Files
shoot-miniprograms/src/components/Header.vue

279 lines
6.2 KiB
Vue
Raw Normal View History

2025-05-01 21:38:35 +08:00
<script setup>
2025-09-24 21:05:06 +08:00
import { ref, computed, onMounted, onBeforeUnmount } from "vue";
2025-08-13 16:44:25 +08:00
import HeaderProgress from "@/components/HeaderProgress.vue";
2025-09-24 21:05:06 +08:00
import Avatar from "@/components/Avatar.vue";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const currentPage = computed(() => {
const pages = getCurrentPages();
return pages[pages.length - 1].route;
});
2025-06-08 13:55:09 +08:00
2025-06-17 16:42:53 +08:00
const props = defineProps({
2025-05-01 21:38:35 +08:00
title: {
type: String,
default: "",
},
2025-06-17 16:42:53 +08:00
onBack: {
type: Function,
default: null,
},
2025-07-29 10:46:37 +08:00
whiteBackArrow: {
type: Boolean,
default: true,
},
2025-05-01 21:38:35 +08:00
});
2025-06-08 13:55:09 +08:00
2025-06-17 16:42:53 +08:00
const onClick = () => {
2025-09-22 14:55:00 +08:00
if (props.onBack) {
props.onBack();
} else {
const pages = getCurrentPages();
if (pages.length > 1) {
uni.navigateBack();
} else {
uni.redirectTo({
url: "/pages/index",
});
}
}
2025-06-17 16:42:53 +08:00
};
2025-09-24 21:05:06 +08:00
const toUserPage = () => {
uni.navigateTo({
url: "/pages/user",
});
};
const signin = () => {
if (!user.value.id) {
uni.$emit("point-book-signin");
}
};
2025-07-23 11:18:47 +08:00
const loading = ref(false);
const showLoader = ref(false);
2025-07-30 14:20:38 +08:00
const pointBook = ref(null);
2025-08-13 16:44:25 +08:00
const showProgress = ref(false);
2025-09-25 14:22:03 +08:00
const heat = ref(0);
2025-07-23 11:18:47 +08:00
const updateLoading = (value) => {
loading.value = value;
};
2025-09-25 14:22:03 +08:00
const updateHot = (value) => {
heat.value = value;
};
2025-06-15 22:01:06 +08:00
onMounted(() => {
2025-07-23 11:18:47 +08:00
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
2025-07-30 14:20:38 +08:00
if (currentPage.route === "pages/point-book-edit") {
pointBook.value = uni.getStorageSync("point-book");
}
2025-07-23 11:18:47 +08:00
if (
2025-08-14 10:50:44 +08:00
currentPage.route === "pages/team-battle" ||
2025-07-23 11:18:47 +08:00
currentPage.route === "pages/melee-match"
) {
showLoader.value = true;
}
2025-08-13 16:44:25 +08:00
if (currentPage.route === "pages/team-battle") {
showProgress.value = true;
}
2025-09-25 14:22:03 +08:00
uni.$on("update-header-loading", updateLoading);
uni.$on("update-hot", updateHot);
2025-07-23 11:18:47 +08:00
});
2025-08-25 13:47:32 +08:00
onBeforeUnmount(() => {
2025-07-23 11:18:47 +08:00
uni.$off("update-header-loading", updateLoading);
2025-09-25 14:22:03 +08:00
uni.$off("update-hot", updateHot);
2025-06-15 22:01:06 +08:00
});
2025-05-01 21:38:35 +08:00
</script>
<template>
2025-08-07 10:48:05 +08:00
<view class="container">
2025-06-17 16:42:53 +08:00
<view class="back-btn" @click="onClick">
2025-07-29 10:46:37 +08:00
<image v-if="whiteBackArrow" src="../static/back.png" mode="widthFix" />
<image
v-if="!whiteBackArrow"
src="../static/back-black.png"
mode="widthFix"
/>
2025-06-17 16:42:53 +08:00
</view>
2025-07-29 10:46:37 +08:00
<view :style="{ color: whiteBackArrow ? '#fff' : '#000' }">
2025-09-24 21:05:06 +08:00
<view
v-if="currentPage === 'pages/point-book'"
class="user-header"
@click="signin"
>
<block v-if="user.id">
<Avatar
:rankLvl="user.rankLvl"
:src="user.avatar"
:onClick="toUserPage"
:size="40"
borderColor="#333"
/>
<text>{{ user.nickName }}</text>
2025-09-25 14:22:03 +08:00
<image
v-if="heat"
:src="`../static/hot${heat}.png`"
mode="widthFix"
/>
2025-09-24 21:05:06 +08:00
</block>
<block v-else>
<image src="../static/user-icon.png" mode="widthFix" />
<text>新来的弓箭手你好呀~</text>
</block>
</view>
2025-07-11 00:47:34 +08:00
<block
v-if="
'-凹造型-感知距离-小试牛刀'.indexOf(title) === -1 ||
'-凹造型-感知距离-小试牛刀'.indexOf(title) === 10
"
>
2025-06-25 00:09:53 +08:00
<text>{{ title }}</text>
</block>
2025-07-11 00:47:34 +08:00
<block
v-if="
title &&
'-凹造型-感知距离-小试牛刀'.indexOf(title) !== -1 &&
'-凹造型-感知距离-小试牛刀'.indexOf(title) !== 10
"
>
2025-06-25 00:09:53 +08:00
<view class="first-try-steps">
2025-07-11 00:47:34 +08:00
<text :class="title === '-凹造型' ? 'current-step' : ''">凹造型</text>
2025-06-28 12:03:33 +08:00
<text>-</text>
2025-07-11 00:47:34 +08:00
<text :class="title === '-感知距离' ? 'current-step' : ''"
2025-06-25 00:09:53 +08:00
>感知距离</text
>
2025-06-28 12:03:33 +08:00
<text>-</text>
2025-07-11 00:47:34 +08:00
<text :class="title === '-小试牛刀' ? 'current-step' : ''"
2025-06-25 00:09:53 +08:00
>小试牛刀</text
>
</view>
</block>
</view>
2025-07-23 11:18:47 +08:00
<image
:style="{ opacity: showLoader && loading ? 1 : 0 }"
src="../static/btn-loading.png"
mode="widthFix"
class="loading"
/>
2025-07-30 14:20:38 +08:00
<view v-if="pointBook" class="point-book-info">
2025-08-04 16:28:34 +08:00
<text>{{ pointBook.bowType.name }}</text>
2025-07-30 14:20:38 +08:00
<text>{{ pointBook.distance }} </text>
<text
>{{
2025-08-04 16:28:34 +08:00
pointBook.bowtargetType.name.substring(
2025-07-30 14:20:38 +08:00
0,
2025-08-04 16:28:34 +08:00
pointBook.bowtargetType.name.length - 3
2025-07-30 14:20:38 +08:00
)
}}
{{
2025-08-07 10:48:05 +08:00
pointBook.bowtargetType.name.substring(
pointBook.bowtargetType.name.length - 3
)
2025-07-30 14:20:38 +08:00
}}</text
>
</view>
2025-08-13 16:44:25 +08:00
<view v-if="showProgress" class="battle-progress">
<HeaderProgress />
</view>
2025-05-01 21:38:35 +08:00
</view>
</template>
<style scoped>
.container {
display: flex;
justify-content: flex-start;
align-items: center;
width: 72vw;
2025-08-07 10:48:05 +08:00
height: 50px;
2025-06-21 03:34:10 +08:00
/* margin-top: var(--status-bar-height); */
2025-05-01 21:38:35 +08:00
padding-left: 15px;
2025-07-30 14:20:38 +08:00
}
.container > view:nth-child(2) {
2025-06-25 00:09:53 +08:00
font-size: 16px;
2025-07-11 22:21:34 +08:00
font-weight: bold;
2025-05-01 21:38:35 +08:00
}
.back-btn {
display: flex;
align-items: center;
}
.back-btn > image {
2025-07-29 10:46:37 +08:00
width: 22px;
height: 22px;
2025-05-01 21:38:35 +08:00
margin-right: 10px;
}
2025-06-25 00:09:53 +08:00
.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;
2025-05-01 21:38:35 +08:00
color: #fff;
}
2025-07-23 11:18:47 +08:00
.loading {
width: 20px;
height: 20px;
margin-left: 10px;
transition: all 0.3s ease;
background-blend-mode: darken;
animation: rotate 2s linear infinite;
}
2025-07-30 14:20:38 +08:00
.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;
}
2025-08-13 16:44:25 +08:00
.battle-progress {
position: fixed;
width: 60%;
left: 20%;
display: flex;
justify-content: center;
}
2025-09-24 21:05:06 +08:00
.user-header {
display: flex;
align-items: center;
justify-content: flex-start;
}
2025-09-25 14:22:03 +08:00
.user-header > image:first-child {
2025-09-24 21:05:06 +08:00
width: 40px;
height: 40px;
border-radius: 50%;
border: 2rpx solid #333;
}
2025-09-25 14:22:03 +08:00
.user-header > image:last-child {
width: 36rpx;
}
2025-09-24 21:05:06 +08:00
.user-header > text:nth-child(2) {
font-weight: 500;
font-size: 30rpx;
color: #333333;
margin: 0 20rpx;
}
2025-05-01 21:38:35 +08:00
</style>