Files
shoot-miniprograms/src/pages/melee-bow-data.vue

157 lines
3.7 KiB
Vue
Raw Normal View History

2025-06-24 13:18:03 +08:00
<script setup>
import { ref } from "vue";
import { onLoad } from "@dcloudio/uni-app";
import Container from "@/components/Container.vue";
import BowTarget from "@/components/BowTarget.vue";
import Avatar from "@/components/Avatar.vue";
import { getGameAPI } from "@/apis";
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
const scores = ref([]);
const currentUser = ref({});
const data = ref({});
const onSelect = (userId) => {
const user = data.value.players.find((p) => p.playerId === userId);
currentUser.value = user;
if (user && user.arrowHistory) {
scores.value = user.arrowHistory;
}
};
2025-06-28 12:38:38 +08:00
onLoad(async (options) => {
if (options.battleId) {
const result = await getGameAPI(options.battleId);
data.value = result;
if (result.players && result.players[0]) {
onSelect(result.players[0].playerId);
}
}
});
2025-06-24 13:18:03 +08:00
</script>
<template>
2025-07-14 13:39:10 +08:00
<Container title="靶纸">
2025-06-24 13:18:03 +08:00
<view class="container">
2025-06-28 12:38:38 +08:00
<view class="players" v-if="data.players">
2025-06-24 13:18:03 +08:00
<view
v-for="(player, index) in data.players"
:key="index"
2025-06-28 12:38:38 +08:00
:style="{
width: `${Math.max(100 / data.players.length, 18)}vw`,
color: player.playerId === currentUser.playerId ? '#000' : '#fff9',
}"
2025-06-24 13:18:03 +08:00
@click="() => onSelect(player.playerId)"
>
2025-07-16 14:42:00 +08:00
<image
v-if="player.playerId === currentUser.playerId"
src="../static/player-bg2.png"
:style="{
width: `${Math.max(100 / data.players.length, 18)}vw`,
}"
mode="aspectFill"
class="player-bg"
/>
2025-06-28 12:38:38 +08:00
<Avatar
:src="player.avatar"
:size="40"
:rank="showRank ? index + 1 : 0"
2025-06-24 13:18:03 +08:00
/>
2025-06-28 12:38:38 +08:00
<text>{{ player.name }}</text>
2025-06-24 13:18:03 +08:00
</view>
</view>
2025-06-28 12:38:38 +08:00
<view :style="{ marginTop: '10px' }">
2025-07-16 09:33:33 +08:00
<BowTarget :scores="scores" />
2025-06-24 13:18:03 +08:00
</view>
<view class="score-text"
><text :style="{ color: '#fed847' }">{{ scores.length }}</text
>支箭<text :style="{ color: '#fed847' }">{{
scores.reduce((last, next) => last + next.ring, 0)
}}</text
></view
>
<view class="score-row">
<view
v-for="(score, index) in scores"
:key="index"
class="score-item"
:style="{ width: '13vw', height: '13vw' }"
>
{{ score.ring }}
</view>
</view>
</view>
</Container>
</template>
<style scoped>
.container {
width: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
}
2025-06-28 12:38:38 +08:00
.players {
display: flex;
height: 85px;
width: 100%;
overflow-x: auto;
2025-07-16 14:42:00 +08:00
overflow-y: hidden;
2025-06-28 12:38:38 +08:00
background-color: #fff3;
}
2025-07-16 14:42:00 +08:00
.players::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
2025-06-28 12:38:38 +08:00
.players > view {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 12px;
padding-top: 5px;
flex: 0 0 auto;
2025-07-16 14:42:00 +08:00
position: relative;
}
.player-bg {
position: absolute;
width: 100%;
2025-06-28 12:38:38 +08:00
}
.players > view > text {
margin-top: 5px;
width: 80%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
text-align: center;
2025-07-16 14:42:00 +08:00
position: relative;
2025-06-28 12:38:38 +08:00
}
2025-06-24 13:18:03 +08:00
.score-text {
width: 100%;
color: #fff;
text-align: center;
font-size: 16px;
2025-06-28 12:38:38 +08:00
margin-bottom: 20px;
2025-06-24 13:18:03 +08:00
}
.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;
}
</style>