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

179 lines
4.2 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";
2026-02-07 10:52:56 +08:00
import { getBattleAPI } from "@/apis";
2025-06-24 13:18:03 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
2026-02-07 10:52:56 +08:00
const { user } = storeToRefs(useStore());
const currentUser = ref({
arrows: [],
});
const players = ref([]);
2025-06-28 12:38:38 +08:00
onLoad(async (options) => {
2026-02-07 10:52:56 +08:00
if (!options.id) return;
const result = await getBattleAPI(options.battleId || "59090720979554304");
players.value = result.resultList.map((item, index) => {
const plist = result.teams[0] ? result.teams[0].players : [];
const p = plist.find((p) => p.id === item.userId);
const arrows = new Array(12);
result.rounds.forEach((r, index) => {
if (r.shoots[item.userId]) {
r.shoots[item.userId].forEach((s, index2) => {
arrows[index2 + index * 6] = s;
});
}
});
return {
...item,
rank: index + 1,
name: p.name,
avatar: p.avatar || "",
arrows,
};
});
if (players.value[0]) {
currentUser.value = players.value[0];
2025-06-28 12:38:38 +08:00
}
});
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">
2026-02-07 10:52:56 +08:00
<image
src="../static/battle-header-melee.png"
mode="widthFix"
:style="{ top: '-50rpx' }"
/>
<view class="players">
2025-06-24 13:18:03 +08:00
<view
2026-02-07 10:52:56 +08:00
v-for="(player, index) in players"
2025-06-24 13:18:03 +08:00
:key="index"
2025-06-28 12:38:38 +08:00
:style="{
2026-02-07 10:52:56 +08:00
width: `${Math.max(100 / players.length, 18)}vw`,
color: player.userId === currentUser.userId ? '#000' : '#fff9',
2025-06-28 12:38:38 +08:00
}"
2026-02-07 10:52:56 +08:00
@click="currentUser = player"
2025-06-24 13:18:03 +08:00
>
2025-07-16 14:42:00 +08:00
<image
2026-02-07 10:52:56 +08:00
v-if="player.userId === currentUser.userId"
2025-07-16 14:42:00 +08:00
src="../static/player-bg2.png"
:style="{
2026-02-07 10:52:56 +08:00
width: `${Math.max(100 / players.length, 18)}vw`,
2025-07-16 14:42:00 +08:00
}"
class="player-bg"
/>
2025-07-18 22:17:17 +08:00
<Avatar :src="player.avatar" :rankLvl="player.rankLvl" :size="40" />
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' }">
2026-02-07 10:52:56 +08:00
<BowTarget :scores="currentUser.arrows" />
2025-06-24 13:18:03 +08:00
</view>
<view class="score-text"
2026-02-07 10:52:56 +08:00
><text :style="{ color: '#fed847' }">{{
currentUser.arrows.length
}}</text
2025-06-24 13:18:03 +08:00
>支箭<text :style="{ color: '#fed847' }">{{
2026-02-07 10:52:56 +08:00
currentUser.arrows.reduce((last, next) => last + next.ring, 0)
2025-06-24 13:18:03 +08:00
}}</text
></view
>
2026-02-07 10:52:56 +08:00
<view class="score-row" v-if="currentUser.arrows">
2025-06-24 13:18:03 +08:00
<view
2026-02-07 10:52:56 +08:00
v-for="(score, index) in currentUser.arrows"
2025-06-24 13:18:03 +08:00
: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-07-18 15:04:29 +08:00
position: relative;
}
.container > image:first-child {
position: absolute;
width: 100%;
z-index: 1;
2025-06-24 13:18:03 +08:00
}
2025-06-28 12:38:38 +08:00
.players {
display: flex;
width: 100%;
overflow-x: auto;
2026-02-07 10:52:56 +08:00
margin-top: 50rpx;
2025-06-28 12:38:38 +08:00
}
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 {
2025-07-17 09:35:30 +08:00
background-color: #fff3;
2025-06-28 12:38:38 +08:00
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: 12px;
flex: 0 0 auto;
2025-07-16 14:42:00 +08:00
position: relative;
2025-07-17 09:35:30 +08:00
height: 68px;
margin-bottom: 10px;
2025-07-18 15:04:29 +08:00
padding-top: 10px;
2025-07-16 14:42:00 +08:00
}
.player-bg {
position: absolute;
width: 100%;
2025-07-18 15:04:29 +08:00
height: 85px;
top: 0;
2025-06-28 12:38:38 +08:00
}
.players > view > text {
2025-07-17 09:35:30 +08:00
margin: 5px 0;
2025-06-28 12:38:38 +08:00
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>