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

252 lines
5.1 KiB
Vue
Raw Normal View History

2025-05-01 21:38:35 +08:00
<script setup>
import { ref, computed, watch } from "vue";
2025-05-27 12:38:39 +08:00
import Avatar from "@/components/Avatar.vue";
2025-06-17 13:47:33 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
2025-06-27 10:50:09 +08:00
const { user, config, rankData } = storeToRefs(store);
2025-05-01 21:38:35 +08:00
const props = defineProps({
showRank: {
type: Boolean,
default: false,
},
2025-06-24 13:18:03 +08:00
onSignin: {
type: Function,
default: () => {},
},
2025-05-01 21:38:35 +08:00
});
2025-06-17 21:34:41 +08:00
const nextLvlPoints = ref("");
2025-05-01 21:38:35 +08:00
const containerWidth = computed(() => (props.showRank ? "72vw" : "100vw"));
const toUserPage = () => {
// 获取当前页面路径
const pages = getCurrentPages();
const currentPage = pages[pages.length - 1];
2025-05-26 16:28:13 +08:00
2025-05-01 21:38:35 +08:00
// 如果当前不是用户页面才进行跳转
2025-05-26 16:28:13 +08:00
if (currentPage.route !== "pages/user") {
2025-05-01 21:38:35 +08:00
uni.navigateTo({
url: "/pages/user",
});
}
};
watch(
() => [config.value, user.value],
([n_config, n_user]) => {
const rankInfos = n_config.randInfos || [];
if (n_user.id && rankInfos.length) {
rankInfos.some((r, index) => {
if (r.upgrade_scores > n_user.scores) {
nextLvlPoints.value = r.upgrade_scores;
return true;
}
return false;
});
2025-06-17 21:34:41 +08:00
}
},
{
immediate: true,
}
);
2025-05-01 21:38:35 +08:00
</script>
<template>
<view class="container" :style="{ width: containerWidth }">
2025-06-24 13:18:03 +08:00
<block v-if="user.id"
><Avatar
:frame="true"
:src="user.avatar"
:onClick="toUserPage"
:size="42"
/>
<view class="user-details">
<view class="user-name">
<text>{{ user.nickName }}</text>
<image
class="user-name-image"
src="../static/vip1.png"
mode="widthFix"
2025-06-18 13:50:33 +08:00
/>
2025-06-24 13:18:03 +08:00
</view>
<view class="user-stats">
<text class="level-tag level-tag-first">{{ user.lvlName }}</text>
<text class="level-tag level-tag-second">L{{ user.lvl }}</text>
<view class="rank-tag">
<view
class="rank-tag-progress"
:style="{
width: `${(Math.max(user.scores, 0) / nextLvlPoints) * 100}%`,
}"
/>
<text class="rank-tag-text">
{{ Math.max(user.scores, 0) }}/{{ nextLvlPoints }}
</text>
</view>
2025-05-01 21:38:35 +08:00
</view>
</view>
2025-06-24 13:18:03 +08:00
<view v-if="showRank === true" class="rank-info">
<image
class="rank-info-image"
src="../static/global-rank.png"
mode="widthFix"
/>
2025-06-27 10:50:09 +08:00
<block v-if="user.ranking > 0 && rankData.rank.length">
<text>本赛季全国</text>
<text class="rank-number"
><text :style="{ color: '#ffd700' }"
>{{ user.ranking }}/{{ rankData.rank.length }}</text
></text
>
</block>
<block v-else>
<text>本赛季</text>
<text>暂未上榜</text>
</block>
2025-06-24 13:18:03 +08:00
</view>
</block>
<block v-else>
<view class="signin">
<image src="../static/user-icon.png" mode="widthFix" />
<view @click="() => (showModal = true)">
<text>新来的弓箭手你好呀~</text>
<view @click="onSignin">
<text>微信登录</text>
<image src="../static/enter-arrow-blue.png" mode="widthFix" />
</view>
</view>
</view>
</block>
2025-05-01 21:38:35 +08:00
</view>
</template>
<style scoped>
.container {
display: flex;
align-items: center;
width: 72vw;
padding-left: 15px;
color: #fff;
}
.user-details {
display: flex;
flex-direction: column;
2025-06-16 11:26:57 +08:00
padding-left: 10px;
2025-05-01 21:38:35 +08:00
}
.user-name {
display: flex;
align-items: center;
margin-bottom: 5px;
}
2025-06-15 22:01:06 +08:00
.user-name > text:first-child {
2025-06-16 11:26:57 +08:00
font-size: 13px;
2025-06-25 00:09:53 +08:00
max-width: 180rpx;
2025-06-15 22:01:06 +08:00
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
2025-06-08 12:52:49 +08:00
.user-name-image {
2025-05-01 21:38:35 +08:00
margin-left: 5px;
2025-05-08 22:05:53 +08:00
width: 20px;
2025-05-01 21:38:35 +08:00
}
.user-stats {
display: flex;
gap: 5px;
}
.level-tag {
text-align: center;
line-height: 16px;
}
2025-06-08 12:52:49 +08:00
.level-tag-first {
2025-06-16 11:26:57 +08:00
width: 40px;
2025-05-01 21:38:35 +08:00
background: #5f51ff;
}
2025-06-08 12:52:49 +08:00
.level-tag-second {
2025-05-01 21:38:35 +08:00
width: 30px;
background: #09c504;
}
.level-tag,
.rank-tag {
border-radius: 12px;
2025-06-16 11:26:57 +08:00
font-size: 9px;
2025-05-01 21:38:35 +08:00
}
.rank-tag {
position: relative;
background-color: #00000038;
2025-06-25 00:09:53 +08:00
width: 100rpx;
2025-05-01 21:38:35 +08:00
}
2025-06-08 12:52:49 +08:00
.rank-tag-progress {
2025-05-01 21:38:35 +08:00
background: #ffa711;
height: 100%;
border-radius: 12px;
}
2025-06-08 12:52:49 +08:00
.rank-tag-text {
2025-05-01 21:38:35 +08:00
position: absolute;
top: 0;
left: 5px;
line-height: 16px;
}
.rank-info {
2025-06-24 13:18:03 +08:00
width: 68px;
2025-05-01 21:38:35 +08:00
text-align: left;
2025-06-08 12:52:49 +08:00
font-size: 12px;
2025-05-01 21:38:35 +08:00
position: relative;
color: #b3b3b3;
padding-left: 8px;
2025-06-25 00:09:53 +08:00
margin-left: 15rpx;
2025-06-16 11:26:57 +08:00
display: flex;
flex-direction: column;
2025-05-01 21:38:35 +08:00
}
2025-06-08 12:52:49 +08:00
.rank-info-image {
2025-05-01 21:38:35 +08:00
position: absolute;
2025-06-08 12:52:49 +08:00
top: -6px;
left: -9px;
2025-05-01 21:38:35 +08:00
width: 90px;
}
2025-06-24 13:18:03 +08:00
.rank-info > text {
text-align: center;
}
2025-05-01 21:38:35 +08:00
.rank-number {
display: block;
}
2025-06-24 13:18:03 +08:00
.signin {
display: flex;
align-items: center;
}
.signin > image {
width: 40px;
height: 40px;
}
.signin > view {
display: flex;
flex-direction: column;
justify-content: center;
align-items: flex-start;
margin-left: 12px;
font-size: 14px;
}
.signin > view > view:last-child {
display: flex;
align-items: center;
}
.signin > view > view:last-child > text {
color: #39a8ff;
margin-top: 2px;
}
.signin > view > view:last-child > image {
width: 15px;
margin-top: 2px;
}
2025-05-01 21:38:35 +08:00
</style>