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";
|
2025-06-17 12:50:59 +08:00
|
|
|
|
import Avatar from "@/components/Avatar.vue";
|
|
|
|
|
|
import BowPower from "@/components/BowPower.vue";
|
2025-07-05 14:52:41 +08:00
|
|
|
|
import TestDistance from "@/components/TestDistance.vue";
|
2025-07-12 16:01:49 +08:00
|
|
|
|
import BubbleTip from "@/components/BubbleTip.vue";
|
2025-06-17 21:34:41 +08:00
|
|
|
|
import { createPractiseAPI, getHomeData } from "@/apis";
|
2025-07-05 14:52:41 +08:00
|
|
|
|
import { generateCanvasImage } from "@/util";
|
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-06-17 21:34:41 +08:00
|
|
|
|
const { updateUser } = store;
|
2025-07-13 11:38:54 +08:00
|
|
|
|
const start = 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-06-17 12:50:59 +08:00
|
|
|
|
const currentRound = ref(0);
|
2025-05-31 14:57:25 +08:00
|
|
|
|
const practiseResult = ref({});
|
2025-06-17 16:58:24 +08:00
|
|
|
|
const power = ref(0);
|
2025-06-25 18:41:30 +08:00
|
|
|
|
const practiseId = ref("");
|
2025-07-12 16:01:49 +08:00
|
|
|
|
const showGuide = ref(false);
|
2025-05-10 16:57:36 +08:00
|
|
|
|
|
2025-05-29 23:45:44 +08:00
|
|
|
|
const onReady = async () => {
|
2025-06-25 18:41:30 +08:00
|
|
|
|
const result = await createPractiseAPI(total);
|
|
|
|
|
|
if (result) practiseId.value = result.id;
|
2025-06-17 19:35:21 +08:00
|
|
|
|
currentRound.value = 0;
|
2025-06-15 15:53:57 +08:00
|
|
|
|
scores.value = [];
|
2025-06-19 01:55:40 +08:00
|
|
|
|
start.value = true;
|
2025-07-14 16:37:56 +08:00
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
uni.$emit("play-sound", "请开始射击");
|
|
|
|
|
|
}, 300);
|
2025-06-05 21:32:15 +08:00
|
|
|
|
};
|
2025-05-29 23:45:44 +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 15:53:57 +08:00
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
2025-07-11 22:21:34 +08:00
|
|
|
|
if (scores.value.length < total) {
|
|
|
|
|
|
scores.value.push(msg.target);
|
|
|
|
|
|
currentRound.value += 1;
|
|
|
|
|
|
if (currentRound.value === 4) {
|
|
|
|
|
|
currentRound.value = 1;
|
|
|
|
|
|
}
|
2025-07-12 16:01:49 +08:00
|
|
|
|
if (scores.value.length === total / 2) {
|
|
|
|
|
|
showGuide.value = true;
|
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
|
showGuide.value = false;
|
|
|
|
|
|
}, 3000);
|
|
|
|
|
|
}
|
2025-06-17 12:50:59 +08:00
|
|
|
|
}
|
2025-06-05 21:32:15 +08:00
|
|
|
|
power.value = msg.target.battery;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) {
|
2025-06-25 18:41:30 +08:00
|
|
|
|
if (practiseId.value && practiseId.value === msg.practice.id) {
|
|
|
|
|
|
start.value = false;
|
|
|
|
|
|
practiseResult.value = {
|
|
|
|
|
|
...msg.practice,
|
|
|
|
|
|
arrows: JSON.parse(msg.practice.arrows),
|
|
|
|
|
|
};
|
|
|
|
|
|
generateCanvasImage("shareCanvas", 2, user.value, practiseResult.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
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-17 21:34:41 +08:00
|
|
|
|
async function onComplete() {
|
2025-07-05 13:12:58 +08:00
|
|
|
|
if (
|
|
|
|
|
|
practiseResult.value.arrows &&
|
|
|
|
|
|
practiseResult.value.arrows.length === total
|
|
|
|
|
|
) {
|
|
|
|
|
|
uni.navigateBack();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
practiseResult.value = {};
|
|
|
|
|
|
start.value = false;
|
|
|
|
|
|
scores.value = [];
|
|
|
|
|
|
currentRound.value = 0;
|
|
|
|
|
|
}
|
2025-06-05 22:21:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-06-05 21:32:15 +08:00
|
|
|
|
onMounted(() => {
|
2025-07-13 11:21:19 +08:00
|
|
|
|
uni.setKeepScreenOn({
|
|
|
|
|
|
keepScreenOn: true,
|
|
|
|
|
|
});
|
2025-06-05 21:32:15 +08:00
|
|
|
|
uni.$on("socket-inbox", onReceiveMessage);
|
|
|
|
|
|
});
|
2025-05-29 23:45:44 +08:00
|
|
|
|
|
|
|
|
|
|
onUnmounted(() => {
|
2025-07-13 11:21:19 +08:00
|
|
|
|
uni.setKeepScreenOn({
|
|
|
|
|
|
keepScreenOn: false,
|
|
|
|
|
|
});
|
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>
|
2025-07-05 14:52:41 +08:00
|
|
|
|
<TestDistance v-if="!start && !practiseResult.arrows" />
|
|
|
|
|
|
<block v-if="start || practiseResult.arrows">
|
|
|
|
|
|
<ShootProgress
|
|
|
|
|
|
:tips="`${
|
|
|
|
|
|
!start || scores.length === 12
|
|
|
|
|
|
? ''
|
|
|
|
|
|
: `请开始射箭第${
|
|
|
|
|
|
roundsName[Math.ceil((scores.length + 1) / 3)]
|
|
|
|
|
|
}轮`
|
|
|
|
|
|
}`"
|
|
|
|
|
|
:start="start"
|
|
|
|
|
|
:total="120"
|
|
|
|
|
|
/>
|
2025-07-11 00:47:34 +08:00
|
|
|
|
<view class="user-row">
|
2025-07-05 14:52:41 +08:00
|
|
|
|
<Avatar :src="user.avatar" :size="35" />
|
2025-07-13 11:38:54 +08:00
|
|
|
|
<BubbleTip v-if="showGuide" type="normal2">
|
2025-07-12 16:01:49 +08:00
|
|
|
|
<text>还有两场,坚持</text>
|
|
|
|
|
|
<text>就是胜利!💪</text>
|
|
|
|
|
|
</BubbleTip>
|
2025-07-13 11:38:54 +08:00
|
|
|
|
<BowPower :power="power" />
|
2025-07-05 14:52:41 +08:00
|
|
|
|
</view>
|
|
|
|
|
|
<BowTarget
|
|
|
|
|
|
:totalRound="start ? total / 4 : 0"
|
|
|
|
|
|
:currentRound="currentRound"
|
|
|
|
|
|
:scores="scores"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<ScorePanel2 :scores="scores.map((s) => s.ring)" />
|
|
|
|
|
|
<ScoreResult
|
|
|
|
|
|
v-if="practiseResult.arrows"
|
|
|
|
|
|
:rowCount="6"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
:onClose="onComplete"
|
|
|
|
|
|
:result="practiseResult"
|
|
|
|
|
|
:tipSrc="`../static/${
|
|
|
|
|
|
practiseResult.arrows.length < total ? 'un' : ''
|
|
|
|
|
|
}finish-tip.png`"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<canvas class="share-canvas" canvas-id="shareCanvas"></canvas>
|
|
|
|
|
|
</block>
|
2025-06-05 22:21:40 +08:00
|
|
|
|
</view>
|
2025-06-18 21:30:54 +08:00
|
|
|
|
<view :style="{ marginBottom: '20px' }">
|
2025-06-25 00:09:53 +08:00
|
|
|
|
<SButton v-if="!start" :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-07-11 22:21:34 +08:00
|
|
|
|
<style scoped></style>
|