Files
shoot-miniprograms/src/pages/practise-one.vue

96 lines
2.5 KiB
Vue
Raw Normal View History

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 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-06-15 15:53:57 +08:00
import useStore from "@/store";
import { storeToRefs } from "pinia";
const store = useStore();
const { user } = storeToRefs(store);
2025-05-29 23:45:44 +08:00
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-06-05 21:32:15 +08:00
await createPractiseAPI(total);
2025-05-29 23:45:44 +08:00
start.value = true;
2025-06-15 15:53:57 +08:00
scores.value = [];
2025-06-05 21:32:15 +08:00
};
2025-05-29 23:45:44 +08:00
2025-06-05 21:32:15 +08:00
async function onReceiveMessage(content) {
const messages = JSON.parse(content).data.updates || [];
messages.forEach((msg) => {
2025-06-15 15:53:57 +08:00
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
2025-06-05 21:32:15 +08:00
scores.value.push(msg.target);
power.value = msg.target.battery;
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) {
practiseResult.value = {
...msg.practice,
arrows: JSON.parse(msg.practice.arrows),
};
}
2025-05-29 23:45:44 +08:00
});
2025-06-05 21:32:15 +08:00
}
2025-06-05 22:21:40 +08:00
function onComplete() {
uni.navigateBack();
showScore.value = false;
}
2025-06-05 21:32:15 +08:00
onMounted(() => {
uni.$on("socket-inbox", onReceiveMessage);
});
2025-05-29 23:45:44 +08:00
onUnmounted(() => {
2025-06-05 21:32:15 +08:00
uni.$off("socket-inbox", onReceiveMessage);
2025-05-29 23:45:44 +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>
<ShootProgress
:tips="`${
scores.length === 12
? ''
: `请开始射箭第${roundsName[Math.ceil((scores.length + 1) / 4)]}`
}`"
:start="start"
:total="120"
/>
<BowTarget
:totalRound="total"
2025-06-15 15:53:57 +08:00
:currentRound="start ? scores.length + 1 : 0"
:avatar="user.avatarUrl"
2025-06-05 22:21:40 +08:00
:power="power"
:scores="scores"
/>
<ScorePanel2 v-if="start" :scores="scores.map((s) => s.ring)" />
<ScoreResult
:total="total"
:rowCount="6"
:show="showScore"
:onClose="onComplete"
:result="practiseResult"
/>
</view>
2025-06-15 15:53:57 +08:00
<view :style="{ marginBottom: '10px' }">
<SButton v-if="!start" :onClick="onReady">准备好了直接开始</SButton>
</view>
2025-06-05 22:21:40 +08:00
</Container>
2025-05-08 22:05:53 +08:00
</template>
2025-06-05 22:21:40 +08:00
<style scoped></style>