2025-05-08 22:05:53 +08:00
|
|
|
|
<script setup>
|
2025-05-30 13:58:43 +08:00
|
|
|
|
import { ref, onUnmounted } from "vue";
|
2025-05-08 22:05:53 +08:00
|
|
|
|
import AppBackground from "@/components/AppBackground.vue";
|
|
|
|
|
|
import Header from "@/components/Header.vue";
|
2025-05-10 16:57:36 +08:00
|
|
|
|
import ShootProgress from "@/components/ShootProgress.vue";
|
|
|
|
|
|
import BowTarget from "@/components/BowTarget.vue";
|
|
|
|
|
|
import ScorePanel2 from "@/components/ScorePanel2.vue";
|
2025-05-16 15:56:54 +08:00
|
|
|
|
import ScoreResult from "@/components/ScoreResult.vue";
|
2025-05-29 23:45:44 +08:00
|
|
|
|
import SButton from "@/components/SButton.vue";
|
|
|
|
|
|
import { createPractiseAPI } from "@/apis";
|
2025-06-04 16:26:07 +08:00
|
|
|
|
import { MESSAGETYPES, roundsName } from "@/constants";
|
2025-05-29 23:45:44 +08:00
|
|
|
|
import websocket from "@/websocket";
|
|
|
|
|
|
const start = ref(false);
|
2025-05-10 16:57:36 +08:00
|
|
|
|
const showScore = ref(false);
|
2025-05-29 23:45:44 +08:00
|
|
|
|
const scores = ref([]);
|
2025-05-29 23:56:42 +08:00
|
|
|
|
const total = 12;
|
2025-05-31 14:57:25 +08:00
|
|
|
|
const practiseResult = ref({});
|
|
|
|
|
|
const power = ref(0);
|
2025-05-10 16:57:36 +08:00
|
|
|
|
|
2025-05-29 23:45:44 +08:00
|
|
|
|
const onReady = async () => {
|
2025-05-29 23:56:42 +08:00
|
|
|
|
const result = await createPractiseAPI(total);
|
2025-05-29 23:45:44 +08:00
|
|
|
|
start.value = true;
|
|
|
|
|
|
const token = uni.getStorageSync("token");
|
|
|
|
|
|
|
2025-05-30 13:58:43 +08:00
|
|
|
|
websocket.createWebSocket(token, (content) => {
|
|
|
|
|
|
const messages = JSON.parse(content).data.updates || [];
|
2025-05-29 23:45:44 +08:00
|
|
|
|
messages.forEach((msg) => {
|
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
|
|
|
|
|
scores.value.push(msg.target);
|
2025-05-31 14:57:25 +08:00
|
|
|
|
power.value = msg.target.battery;
|
2025-05-29 23:56:42 +08:00
|
|
|
|
if (scores.value.length === total) {
|
2025-05-29 23:45:44 +08:00
|
|
|
|
showScore.value = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-05-31 14:57:25 +08:00
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
|
|
|
|
|
practiseResult.value = {
|
|
|
|
|
|
...msg.practice,
|
|
|
|
|
|
arrows: JSON.parse(msg.practice.arrows),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-05-29 23:45:44 +08:00
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
|
websocket.closeWebSocket();
|
|
|
|
|
|
});
|
2025-05-08 22:05:53 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-05-10 16:57:36 +08:00
|
|
|
|
<view class="container">
|
2025-05-29 23:45:44 +08:00
|
|
|
|
<AppBackground :type="1" />
|
2025-05-08 22:05:53 +08:00
|
|
|
|
<Header title="个人单组练习" />
|
2025-05-30 17:34:59 +08:00
|
|
|
|
<ShootProgress
|
2025-05-31 17:59:36 +08:00
|
|
|
|
:tips="`${
|
|
|
|
|
|
scores.length === 12
|
|
|
|
|
|
? ''
|
|
|
|
|
|
: `请开始射箭第${roundsName[Math.ceil((scores.length + 1) / 4)]}轮`
|
|
|
|
|
|
}`"
|
2025-05-30 17:34:59 +08:00
|
|
|
|
:start="start"
|
|
|
|
|
|
:total="120"
|
|
|
|
|
|
/>
|
2025-05-10 16:57:36 +08:00
|
|
|
|
<BowTarget
|
2025-05-29 23:56:42 +08:00
|
|
|
|
:totalRound="total"
|
2025-05-29 23:45:44 +08:00
|
|
|
|
:currentRound="scores.length + 1"
|
2025-05-10 16:57:36 +08:00
|
|
|
|
avatar="../static/avatar.png"
|
2025-05-31 14:57:25 +08:00
|
|
|
|
:power="power"
|
2025-05-29 23:45:44 +08:00
|
|
|
|
:scores="scores"
|
2025-05-10 16:57:36 +08:00
|
|
|
|
/>
|
2025-05-29 23:45:44 +08:00
|
|
|
|
<ScorePanel2 v-if="start" :scores="scores.map((s) => s.ring)" />
|
2025-05-16 15:56:54 +08:00
|
|
|
|
<ScoreResult
|
2025-05-29 23:56:42 +08:00
|
|
|
|
:total="total"
|
2025-05-16 15:56:54 +08:00
|
|
|
|
:rowCount="6"
|
|
|
|
|
|
:show="showScore"
|
|
|
|
|
|
:onClose="() => (showScore = false)"
|
2025-05-31 14:57:25 +08:00
|
|
|
|
:result="practiseResult"
|
2025-05-16 15:56:54 +08:00
|
|
|
|
/>
|
2025-05-29 23:45:44 +08:00
|
|
|
|
<SButton v-if="!start" :onClick="onReady">准备好了,直接开始</SButton>
|
2025-05-08 22:05:53 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
2025-05-10 16:57:36 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.container {
|
|
|
|
|
|
position: relative;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|