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

210 lines
4.8 KiB
Vue
Raw Normal View History

2025-06-08 12:52:49 +08:00
<script setup>
2025-06-09 01:17:18 +08:00
import { ref, watch } from "vue";
2025-06-08 12:52:49 +08:00
import BowTarget from "@/components/BowTarget.vue";
import Avatar from "@/components/Avatar.vue";
2025-06-09 01:17:18 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const scores = ref([]);
2025-06-20 01:47:57 +08:00
const currentUser = ref({});
2025-06-08 12:52:49 +08:00
const props = defineProps({
show: {
type: Boolean,
default: false,
},
onClose: {
type: Function,
default: () => {},
},
2025-06-09 01:17:18 +08:00
data: {
type: Object,
default: () => ({}),
},
2025-06-08 12:52:49 +08:00
});
2025-06-09 01:17:18 +08:00
watch(
() => props.data,
(value) => {
const mine = value.players.find((p) => p.playerId === user.value.id);
2025-06-20 01:47:57 +08:00
currentUser.value = mine;
2025-06-14 22:45:07 +08:00
if (mine && mine.arrowHistory) {
2025-06-09 01:17:18 +08:00
scores.value = mine.arrowHistory;
}
},
{ deep: true, immediate: true }
);
2025-06-20 01:47:57 +08:00
const onSelect = (userId) => {
const user = props.data.players.find((p) => p.playerId === userId);
currentUser.value = user;
if (user && user.arrowHistory) {
scores.value = user.arrowHistory;
}
};
2025-06-08 12:52:49 +08:00
</script>
<template>
<view class="container" :style="{ display: show ? 'flex' : 'none' }">
<view>
<text>5人大乱斗</text>
<view @click="onClose">
<image src="../static/close-white.png" mode="widthFix" />
</view>
</view>
<view class="rank-rows">
2025-06-20 01:47:57 +08:00
<view
v-for="(player, index) in data.players"
:key="index"
@click="() => onSelect(player.playerId)"
>
2025-06-08 12:52:49 +08:00
<image v-if="index === 0" src="../static/champ1.png" mode="widthFix" />
<image v-if="index === 1" src="../static/champ2.png" mode="widthFix" />
<image v-if="index === 2" src="../static/champ3.png" mode="widthFix" />
2025-06-09 01:17:18 +08:00
<view v-if="index > 2" class="rank-view">{{ index + 1 }}</view>
2025-06-14 22:45:07 +08:00
<Avatar :src="player.avatar" :size="24" />
2025-06-09 01:17:18 +08:00
<text
>积分
{{
player.totalScore > 0 ? "+" + player.totalScore : player.totalScore
}}</text
>
<text>{{ player.totalRings }}</text>
<text v-for="(arrow, index2) in player.arrowHistory" :key="index2">
2025-06-17 21:34:41 +08:00
{{ arrow.ring }}
2025-06-08 12:52:49 +08:00
</text>
</view>
</view>
2025-06-09 01:17:18 +08:00
<view :style="{ width: '95%' }">
2025-06-20 01:47:57 +08:00
<BowTarget
:scores="scores"
2025-06-24 13:18:03 +08:00
:avatar="currentUser ? currentUser.avatar : ''"
2025-06-20 01:47:57 +08:00
/>
2025-06-08 12:52:49 +08:00
</view>
<view class="score-text"
2025-06-24 13:18:03 +08:00
><text :style="{ color: '#fed847' }">{{ scores.length }}</text
>支箭<text :style="{ color: '#fed847' }">{{
scores.reduce((last, next) => last + next.ring, 0)
}}</text
2025-06-08 12:52:49 +08:00
></view
>
<view class="score-row">
<view
2025-06-09 01:17:18 +08:00
v-for="(score, index) in scores"
2025-06-08 12:52:49 +08:00
:key="index"
class="score-item"
:style="{ width: '13vw', height: '13vw' }"
>
2025-06-18 02:02:09 +08:00
{{ score.ring }}
2025-06-08 12:52:49 +08:00
</view>
</view>
</view>
</template>
<style scoped>
.container {
width: 100vw;
height: 100vh;
position: fixed;
top: 0;
left: 0;
2025-06-09 12:24:01 +08:00
background-color: #232323;
2025-06-08 12:52:49 +08:00
flex-direction: column;
justify-content: center;
align-items: center;
z-index: 10;
}
.container > view:first-child {
width: 100%;
display: flex;
align-items: center;
justify-content: center;
padding: 20px 0;
color: #fff;
position: relative;
font-size: 20px;
}
.container > view:first-child > view:last-child {
position: absolute;
left: 5px;
top: 25px;
}
.container > view:first-child > view:last-child > image {
width: 40px;
}
.score-text {
width: 100%;
color: #fff;
text-align: center;
font-size: 16px;
margin-bottom: 6px;
}
.score-row {
margin: 10px;
display: flex;
align-items: center;
justify-content: center;
flex-wrap: wrap;
}
.score-item {
background-image: url("../static/score-bg.png");
background-size: cover;
background-repeat: no-repeat;
background-position: center;
color: #fed847;
display: flex;
justify-content: center;
align-items: center;
font-size: 24px;
margin: 3px;
}
.rank-rows {
display: flex;
flex-direction: column;
width: 100%;
border-top: 1px solid #fff3;
}
.rank-rows > view {
width: clac(100% - 20px);
color: #fff9;
border-bottom: 1px solid #fff3;
padding: 7px 10px;
display: flex;
align-items: center;
font-size: 14px;
overflow-x: auto;
}
.rank-rows > view::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
.rank-rows > view > image:first-child,
.rank-rows > view > view:first-child {
width: 20px;
height: 20px;
line-height: 20px;
text-align: center;
font-size: 12px;
margin-right: 10px;
flex: 0 0 auto;
}
.rank-rows > view > view:first-child {
background-color: #6d6d6d;
border-radius: 50%;
}
.rank-rows > view > text {
margin-left: 10px;
flex: 0 0 auto;
2025-06-09 01:17:18 +08:00
display: block;
width: 25px;
}
.rank-rows > view > text:nth-child(3) {
width: 80px;
2025-06-08 12:52:49 +08:00
}
.rank-rows > view > text:nth-child(4) {
color: #fed847;
padding-right: 10px;
border-right: 1px solid #fff3;
2025-06-09 01:17:18 +08:00
width: 32px;
2025-06-08 12:52:49 +08:00
}
</style>