2025-05-08 22:05:53 +08:00
|
|
|
|
<script setup>
|
2025-06-05 21:32:15 +08:00
|
|
|
|
import { ref, onMounted, onUnmounted } from "vue";
|
2025-06-05 22:21:40 +08:00
|
|
|
|
import Container from "@/components/Container.vue";
|
2025-05-10 16:57:36 +08:00
|
|
|
|
import ShootProgress from "@/components/ShootProgress.vue";
|
|
|
|
|
|
import BowTarget from "@/components/BowTarget.vue";
|
|
|
|
|
|
import ScorePanel from "@/components/ScorePanel.vue";
|
|
|
|
|
|
import ScoreResult from "@/components/ScoreResult.vue";
|
2025-05-29 23:56:42 +08:00
|
|
|
|
import SButton from "@/components/SButton.vue";
|
2025-06-17 16:58:24 +08:00
|
|
|
|
import Avatar from "@/components/Avatar.vue";
|
|
|
|
|
|
import BowPower from "@/components/BowPower.vue";
|
2025-06-19 01:55:40 +08:00
|
|
|
|
import StartCountdown from "@/components/StartCountdown.vue";
|
2025-06-17 21:34:41 +08:00
|
|
|
|
import { createPractiseAPI, getHomeData } from "@/apis";
|
2025-05-29 23:56:42 +08:00
|
|
|
|
import { MESSAGETYPES } from "@/constants";
|
2025-06-15 15:53:57 +08:00
|
|
|
|
import useStore from "@/store";
|
|
|
|
|
|
import { storeToRefs } from "pinia";
|
|
|
|
|
|
const store = useStore();
|
|
|
|
|
|
const { user } = storeToRefs(store);
|
2025-06-17 21:34:41 +08:00
|
|
|
|
const { updateUser } = store;
|
2025-06-19 01:55:40 +08:00
|
|
|
|
const startCount = ref(false);
|
2025-05-29 23:56:42 +08:00
|
|
|
|
const start = ref(false);
|
2025-05-10 16:57:36 +08:00
|
|
|
|
const showScore = ref(false);
|
2025-05-29 23:56:42 +08:00
|
|
|
|
const scores = ref([]);
|
|
|
|
|
|
const total = 36;
|
2025-06-17 19:35:21 +08:00
|
|
|
|
const currentRound = ref(0);
|
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:56:42 +08:00
|
|
|
|
const onReady = async () => {
|
2025-06-05 21:32:15 +08:00
|
|
|
|
await createPractiseAPI(total);
|
2025-06-17 19:35:21 +08:00
|
|
|
|
currentRound.value = 0;
|
2025-06-15 20:55:34 +08:00
|
|
|
|
scores.value = [];
|
2025-06-19 01:55:40 +08:00
|
|
|
|
startCount.value = true;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const onStart = () => {
|
|
|
|
|
|
start.value = true;
|
|
|
|
|
|
scores.value = [];
|
|
|
|
|
|
currentRound.value = 0;
|
2025-06-05 21:32:15 +08:00
|
|
|
|
};
|
2025-05-29 23:56:42 +08:00
|
|
|
|
|
2025-06-19 21:03:33 +08:00
|
|
|
|
async function onReceiveMessage(messages = []) {
|
2025-06-05 21:32:15 +08:00
|
|
|
|
messages.forEach((msg) => {
|
2025-06-15 20:55:34 +08:00
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
2025-06-05 21:32:15 +08:00
|
|
|
|
scores.value.push(msg.target);
|
2025-06-15 20:55:34 +08:00
|
|
|
|
power.value = msg.target.battery;
|
2025-06-17 19:35:21 +08:00
|
|
|
|
currentRound.value += 1;
|
2025-06-05 21:32:15 +08:00
|
|
|
|
if (scores.value.length === total) {
|
|
|
|
|
|
showScore.value = true;
|
2025-05-31 14:57:25 +08:00
|
|
|
|
}
|
2025-06-05 21:32:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
2025-06-19 01:55:40 +08:00
|
|
|
|
start.value = false;
|
2025-06-05 21:32:15 +08:00
|
|
|
|
practiseResult.value = {
|
|
|
|
|
|
...msg.practice,
|
|
|
|
|
|
arrows: JSON.parse(msg.practice.arrows),
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-05-29 23:56:42 +08:00
|
|
|
|
});
|
2025-06-05 21:32:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 21:34:41 +08:00
|
|
|
|
async function onComplete() {
|
|
|
|
|
|
const result = await getHomeData();
|
|
|
|
|
|
if (result.user) updateUser(result.user);
|
2025-06-05 22:21:40 +08:00
|
|
|
|
uni.navigateBack();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-05 21:32:15 +08:00
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
uni.$on("socket-inbox", onReceiveMessage);
|
|
|
|
|
|
});
|
2025-05-29 23:56:42 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2025-06-05 21:32:15 +08:00
|
|
|
|
uni.$off("socket-inbox", onReceiveMessage);
|
2025-05-29 23:56:42 +08:00
|
|
|
|
});
|
2025-05-08 22:05:53 +08:00
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<template>
|
2025-06-05 22:21:40 +08:00
|
|
|
|
<Container :bgType="1" title="个人单组练习">
|
|
|
|
|
|
<view>
|
2025-06-15 20:55:34 +08:00
|
|
|
|
<ShootProgress
|
|
|
|
|
|
:start="start"
|
|
|
|
|
|
:tips="`请连续射箭${total}支`"
|
|
|
|
|
|
:total="120"
|
|
|
|
|
|
/>
|
2025-06-17 16:58:24 +08:00
|
|
|
|
<view class="infos">
|
|
|
|
|
|
<Avatar :src="user.avatar" :size="35" />
|
|
|
|
|
|
<BowPower :power="power" />
|
|
|
|
|
|
</view>
|
2025-06-05 22:21:40 +08:00
|
|
|
|
<BowTarget
|
2025-06-17 19:35:21 +08:00
|
|
|
|
:totalRound="start ? total : 0"
|
|
|
|
|
|
:currentRound="currentRound"
|
2025-06-05 22:21:40 +08:00
|
|
|
|
:scores="scores"
|
2025-06-15 20:55:34 +08:00
|
|
|
|
:tips="
|
|
|
|
|
|
!start && scores.length > 0
|
|
|
|
|
|
? `本次射程${scores[scores.length - 1].dst / 100}米,${
|
|
|
|
|
|
scores[scores.length - 1].dst / 100 >= 5 ? '已' : '未'
|
|
|
|
|
|
}达到距离要求`
|
|
|
|
|
|
: ''
|
|
|
|
|
|
"
|
2025-06-05 22:21:40 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<ScorePanel
|
|
|
|
|
|
v-if="start"
|
|
|
|
|
|
:scores="scores.map((s) => s.ring)"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
:rowCount="total / 4"
|
2025-06-16 00:44:28 +08:00
|
|
|
|
:margin="1.5"
|
|
|
|
|
|
:font-size="20"
|
2025-06-05 22:21:40 +08:00
|
|
|
|
/>
|
|
|
|
|
|
<ScoreResult
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
:rowCount="9"
|
|
|
|
|
|
:show="showScore"
|
|
|
|
|
|
:onClose="onComplete"
|
|
|
|
|
|
:result="practiseResult"
|
2025-06-21 12:59:59 +08:00
|
|
|
|
:dataType="3"
|
2025-06-05 22:21:40 +08:00
|
|
|
|
/>
|
2025-06-19 01:55:40 +08:00
|
|
|
|
<StartCountdown :start="startCount" :onFinish="onStart" />
|
2025-06-05 22:21:40 +08:00
|
|
|
|
</view>
|
2025-06-18 21:30:54 +08:00
|
|
|
|
<view :style="{ marginBottom: '20px' }">
|
2025-06-19 01:55:40 +08:00
|
|
|
|
<SButton v-if="!startCount" :onClick="onReady"
|
|
|
|
|
|
>准备好了,直接开始</SButton
|
|
|
|
|
|
>
|
2025-06-15 15:53:57 +08:00
|
|
|
|
</view>
|
2025-06-05 22:21:40 +08:00
|
|
|
|
</Container>
|
2025-05-08 22:05:53 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
2025-06-17 16:58:24 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.infos {
|
|
|
|
|
|
display: flex;
|
|
|
|
|
|
align-items: center;
|
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
|
padding: 0 15px;
|
|
|
|
|
|
padding-top: 15px;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|