Files
shoot-miniprograms/src/components/Header.vue
2025-08-05 15:58:43 +08:00

181 lines
4.1 KiB
Vue

<script setup>
import { ref, onMounted, onUnmounted } from "vue";
const isIos = ref(true);
const props = defineProps({
title: {
type: String,
default: "",
},
onBack: {
type: Function,
default: null,
},
whiteBackArrow: {
type: Boolean,
default: true,
},
});
const onClick = () => {
if (props.onBack) props.onBack();
else uni.navigateBack();
};
const loading = ref(false);
const showLoader = ref(false);
const pointBook = ref(null);
const updateLoading = (value) => {
loading.value = value;
};
onMounted(() => {
const deviceInfo = uni.getDeviceInfo();
isIos.value = deviceInfo.osName === "ios";
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
if (currentPage.route === "pages/point-book-edit") {
pointBook.value = uni.getStorageSync("point-book");
}
if (
currentPage.route === "pages/battle-room" ||
currentPage.route === "pages/team-match" ||
currentPage.route === "pages/melee-match"
) {
showLoader.value = true;
}
uni.$on("update-header-loading", updateLoading);
});
onUnmounted(() => {
uni.$off("update-header-loading", updateLoading);
});
</script>
<template>
<view class="container" :style="{ paddingTop: isIos ? '90rpx' : '60rpx' }">
<view class="back-btn" @click="onClick">
<image v-if="whiteBackArrow" src="../static/back.png" mode="widthFix" />
<image
v-if="!whiteBackArrow"
src="../static/back-black.png"
mode="widthFix"
/>
</view>
<view :style="{ color: whiteBackArrow ? '#fff' : '#000' }">
<block
v-if="
'-凹造型-感知距离-小试牛刀'.indexOf(title) === -1 ||
'-凹造型-感知距离-小试牛刀'.indexOf(title) === 10
"
>
<text>{{ title }}</text>
</block>
<block
v-if="
title &&
'-凹造型-感知距离-小试牛刀'.indexOf(title) !== -1 &&
'-凹造型-感知距离-小试牛刀'.indexOf(title) !== 10
"
>
<view class="first-try-steps">
<text :class="title === '-凹造型' ? 'current-step' : ''">凹造型</text>
<text>-</text>
<text :class="title === '-感知距离' ? 'current-step' : ''"
>感知距离</text
>
<text>-</text>
<text :class="title === '-小试牛刀' ? 'current-step' : ''"
>小试牛刀</text
>
</view>
</block>
</view>
<image
:style="{ opacity: showLoader && loading ? 1 : 0 }"
src="../static/btn-loading.png"
mode="widthFix"
class="loading"
/>
<view v-if="pointBook" class="point-book-info">
<text>{{ pointBook.bowType.name }}</text>
<text>{{ pointBook.distance }} </text>
<text
>{{
pointBook.bowtargetType.name.substring(
0,
pointBook.bowtargetType.name.length - 3
)
}}
{{
pointBook.bowtargetType.name.substring(pointBook.bowtargetType.name.length - 3)
}}</text
>
</view>
</view>
</template>
<style scoped>
.container {
display: flex;
justify-content: flex-start;
align-items: center;
width: 72vw;
height: 100rpx;
/* margin-top: var(--status-bar-height); */
padding-left: 15px;
}
.container > view:nth-child(2) {
font-size: 16px;
font-weight: bold;
}
.back-btn {
display: flex;
align-items: center;
}
.back-btn > image {
width: 22px;
height: 22px;
margin-right: 10px;
}
.first-try-steps {
display: flex;
align-items: center;
color: #fff6;
font-size: 14px;
}
.first-try-steps > text {
transition: all 0.3s ease;
}
.first-try-steps > text:nth-child(2),
.first-try-steps > text:nth-child(4) {
margin: 0 5px;
}
.current-step {
font-size: 16px;
color: #fff;
}
.loading {
width: 20px;
height: 20px;
margin-left: 10px;
transition: all 0.3s ease;
background-blend-mode: darken;
animation: rotate 2s linear infinite;
}
.point-book-info {
color: #333;
position: fixed;
width: 60%;
left: 20%;
display: flex;
justify-content: center;
}
.point-book-info > text {
border-radius: 6px;
background-color: #fff;
font-size: 10px;
padding: 5px 10px;
margin: 3px;
}
</style>