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

252 lines
6.6 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 { roundsName } from "@/constants";
import { getGameAPI } from "@/apis";
const selected = ref(0);
const redScores = ref([]);
const blueScores = ref([]);
const tabs = ref(["所有轮次"]);
const players = ref([]);
const allRoundsScore = ref({});
2025-08-18 16:09:11 +08:00
const data = ref({
goldenRounds: [],
});
2025-06-24 13:18:03 +08:00
onLoad(async (options) => {
2025-08-15 15:25:41 +08:00
if (options.battleId) {
2025-08-12 18:33:39 +08:00
const result = await getGameAPI(
2025-09-10 15:56:57 +08:00
options.battleId || "BATTLE-1756453741433684760-512"
2025-08-12 18:33:39 +08:00
);
2025-06-24 13:18:03 +08:00
data.value = result;
2025-08-15 16:37:10 +08:00
Object.values(result.bluePlayers).forEach((p, index) => {
players.value.push(p);
if (
Object.values(result.redPlayers) &&
Object.values(result.redPlayers)[index]
) {
players.value.push(Object.values(result.redPlayers)[index]);
}
});
2025-08-18 16:09:11 +08:00
if (result.goldenRounds) {
result.goldenRounds.forEach(() => {
tabs.value.push("决金箭");
});
}
Object.keys(result.roundsData).forEach((key, index) => {
if (
index <
Object.keys(result.roundsData).length - result.goldenRounds.length
) {
tabs.value.push(`${roundsName[key]}`);
}
2025-06-24 13:18:03 +08:00
});
onClickTab(0);
}
});
const onClickTab = (index) => {
selected.value = index;
redScores.value = [];
blueScores.value = [];
2025-08-18 16:09:11 +08:00
const { bluePlayers, redPlayers, roundsData, goldenRounds } = data.value;
let maxArrowLength = 0;
2025-06-24 13:18:03 +08:00
if (index === 0) {
Object.keys(bluePlayers).forEach((p) => {
allRoundsScore.value[p] = [];
Object.values(roundsData).forEach((round) => {
2025-08-18 16:09:11 +08:00
if (!round[p]) return;
2025-06-24 13:18:03 +08:00
allRoundsScore.value[p].push(
round[p].reduce((last, next) => last + next.ring, 0)
);
round[p].forEach((arrow) => {
blueScores.value.push(arrow);
});
});
});
Object.keys(redPlayers).forEach((p) => {
allRoundsScore.value[p] = [];
Object.values(roundsData).forEach((round) => {
2025-08-18 16:09:11 +08:00
if (!round[p]) return;
2025-06-24 13:18:03 +08:00
allRoundsScore.value[p].push(
round[p].reduce((last, next) => last + next.ring, 0)
);
round[p].forEach((arrow) => {
redScores.value.push(arrow);
});
});
});
2025-08-18 16:09:11 +08:00
} else if (index <= goldenRounds.length) {
const dataIndex =
Object.keys(roundsData).length - goldenRounds.length + index;
Object.keys(bluePlayers).forEach((p) => {
if (!roundsData[dataIndex][p]) return;
roundsData[dataIndex][p].forEach((arrow) => {
blueScores.value.push(arrow);
});
});
Object.keys(redPlayers).forEach((p) => {
if (!roundsData[dataIndex][p]) return;
roundsData[dataIndex][p].forEach((arrow) => {
redScores.value.push(arrow);
});
});
2025-06-24 13:18:03 +08:00
} else {
Object.keys(bluePlayers).forEach((p) => {
2025-08-18 16:09:11 +08:00
roundsData[index - goldenRounds.length][p].forEach((arrow) => {
2025-06-24 13:18:03 +08:00
blueScores.value.push(arrow);
});
});
Object.keys(redPlayers).forEach((p) => {
2025-08-18 16:09:11 +08:00
roundsData[index - goldenRounds.length][p].forEach((arrow) => {
2025-06-24 13:18:03 +08:00
redScores.value.push(arrow);
});
});
}
};
</script>
<template>
2025-07-14 13:39:10 +08:00
<Container title="靶纸">
2025-06-24 13:18:03 +08:00
<view class="container">
<view>
<view
v-for="(tab, index) in tabs"
:key="index"
@click="() => onClickTab(index)"
:class="selected === index ? 'selected-tab' : ''"
>
{{ tab }}
</view>
</view>
<view :style="{ margin: '20px 0' }">
2025-07-16 09:33:33 +08:00
<BowTarget :scores="redScores" :blueScores="blueScores" />
2025-06-24 13:18:03 +08:00
</view>
2025-08-12 18:33:39 +08:00
<view class="score-container">
2025-06-24 13:18:03 +08:00
<view
2025-08-12 18:33:39 +08:00
class="score-row"
v-for="(player, index) in players"
2025-06-24 13:18:03 +08:00
:key="index"
2025-08-12 18:33:39 +08:00
:style="{
justifyContent: index % 2 === 0 ? 'flex-end' : 'flex-start',
}"
2025-06-24 13:18:03 +08:00
>
2025-08-12 18:33:39 +08:00
<Avatar
:src="player.avatar"
:borderColor="
data.bluePlayers[player.playerId] ? '#64BAFF' : '#FF6767'
"
:size="36"
/>
<view>
<view
v-if="selected === 0"
v-for="(ring, index) in allRoundsScore[player.playerId]"
:key="index"
class="score-item"
>
{{ ring }}
</view>
<view
v-if="
2025-09-10 15:56:57 +08:00
selected > 0 &&
2025-08-18 16:09:11 +08:00
selected >= data.goldenRounds.length &&
selected <= data.goldenRounds.length
2025-08-12 18:33:39 +08:00
"
2025-08-18 16:09:11 +08:00
v-for="(score, index) in data.roundsData[
Object.keys(data.roundsData).length -
data.goldenRounds.length +
selected
][player.playerId]"
2025-08-12 18:33:39 +08:00
:key="index"
class="score-item"
>
{{ score.ring }}
</view>
<view
2025-08-18 16:09:11 +08:00
v-if="selected > data.goldenRounds.length"
2025-08-12 18:33:39 +08:00
v-for="(score, index) in data.roundsData[
2025-08-18 16:09:11 +08:00
selected - data.goldenRounds.length
2025-08-12 18:33:39 +08:00
][player.playerId]"
:key="index"
class="score-item"
>
{{ score.ring }}
</view>
</view>
2025-06-24 13:18:03 +08:00
</view>
</view>
</view>
</Container>
</template>
<style scoped>
.container {
width: 100%;
flex-direction: column;
justify-content: center;
align-items: center;
}
.container > view:nth-child(1) {
display: flex;
align-items: center;
justify-content: flex-start;
width: calc(100% - 20px);
color: #fff9;
padding: 10px;
overflow-x: auto;
}
.container > view:nth-child(1)::-webkit-scrollbar {
width: 0;
height: 0;
color: transparent;
}
.container > view:nth-child(1) > view {
border: 1px solid #fff9;
border-radius: 20px;
padding: 7px 10px;
margin: 0 5px;
font-size: 14px;
flex: 0 0 auto;
}
.selected-tab {
background-color: #fed847;
border-color: #fed847 !important;
color: #000;
}
.score-row {
display: flex;
2025-08-12 18:33:39 +08:00
align-items: flex-start;
2025-08-18 16:09:11 +08:00
margin-bottom: 5px;
width: calc(50% - 5px);
padding-left: 5px;
2025-08-12 18:33:39 +08:00
}
.score-row > view:last-child {
margin-left: 10px;
display: grid;
grid-template-columns: repeat(3, auto);
gap: 5px;
2025-08-15 15:25:41 +08:00
margin-right: 5px;
2025-08-18 16:09:11 +08:00
min-width: 26%;
2025-06-24 13:18:03 +08:00
}
.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;
2025-08-12 18:33:39 +08:00
font-size: 20px;
width: 10vw;
height: 10vw;
}
.score-container {
2025-08-18 16:09:11 +08:00
display: flex;
flex-wrap: wrap;
width: 100%;
2025-06-24 13:18:03 +08:00
}
</style>