完成新的个人练习流程调试

This commit is contained in:
kron
2026-02-07 18:30:16 +08:00
parent d35ff9335f
commit d9a2e53faf
8 changed files with 170 additions and 114 deletions

View File

@@ -13,10 +13,15 @@ import TestDistance from "@/components/TestDistance.vue";
import BubbleTip from "@/components/BubbleTip.vue";
import audioManager from "@/audioManager";
import { createPractiseAPI, getPractiseAPI } from "@/apis";
import {
createPractiseAPI,
startPractiseAPI,
endPractiseAPI,
getPractiseAPI,
} from "@/apis";
import { sharePractiseData } from "@/canvas";
import { wxShare, debounce } from "@/util";
import { MESSAGETYPES, roundsName } from "@/constants";
import { MESSAGETYPESV2, MESSAGETYPES, roundsName } from "@/constants";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -33,8 +38,7 @@ const showGuide = ref(false);
const tips = ref("");
const onReady = async () => {
const result = await createPractiseAPI(total, 2);
if (result) practiseId.value = result.id;
await startPractiseAPI();
currentRound.value = 0;
scores.value = [];
start.value = true;
@@ -42,35 +46,40 @@ const onReady = async () => {
};
const onOver = async () => {
start.value = false;
practiseResult.value = await getPractiseAPI(practiseId.value);
start.value = false;
};
async function onReceiveMessage(messages = []) {
messages.forEach((msg) => {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
if (scores.value.length < total) {
scores.value.push(msg.target);
currentRound.value += 1;
if (currentRound.value === 4) {
currentRound.value = 1;
}
if (practiseId && scores.value.length === total / 2) {
showGuide.value = true;
setTimeout(() => {
showGuide.value = false;
}, 3000);
}
if (scores.value.length === total) {
setTimeout(onOver, 1500);
}
}
}
});
async function onReceiveMessage(msg) {
if (msg.type === MESSAGETYPESV2.ShootResult) {
scores.value = msg.details;
} else if (msg.type === MESSAGETYPESV2.BattleEnd) {
setTimeout(onOver, 1500);
}
// messages.forEach((msg) => {
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
// if (scores.value.length < total) {
// scores.value.push(msg.target);
// currentRound.value += 1;
// if (currentRound.value === 4) {
// currentRound.value = 1;
// }
// if (practiseId && scores.value.length === total / 2) {
// showGuide.value = true;
// setTimeout(() => {
// showGuide.value = false;
// }, 3000);
// }
// if (scores.value.length === total) {
// setTimeout(onOver, 1500);
// }
// }
// }
// });
}
async function onComplete() {
const validArrows = (practiseResult.value.arrows || []).filter(
const validArrows = (practiseResult.value.details || []).filter(
(a) => a.x !== -30 && a.y !== -30
);
if (validArrows.length === total) {
@@ -81,6 +90,8 @@ async function onComplete() {
start.value = false;
scores.value = [];
currentRound.value = 0;
const result = await createPractiseAPI(total, 360);
if (result) practiseId.value = result.id;
}
}
@@ -89,13 +100,15 @@ const onClickShare = debounce(async () => {
await wxShare("shareCanvas");
});
onMounted(() => {
audioManager.play("第一轮");
onMounted(async () => {
// audioManager.play("第一轮");
uni.setKeepScreenOn({
keepScreenOn: true,
});
uni.$on("socket-inbox", onReceiveMessage);
uni.$on("share-image", onClickShare);
const result = await createPractiseAPI(total, 120);
if (result) practiseId.value = result.id;
});
onBeforeUnmount(() => {
@@ -105,6 +118,7 @@ onBeforeUnmount(() => {
uni.$off("socket-inbox", onReceiveMessage);
uni.$off("share-image", onClickShare);
audioManager.stopAll();
endPractiseAPI();
});
</script>
@@ -115,8 +129,8 @@ onBeforeUnmount(() => {
:showBottom="!start && !scores.length"
>
<view>
<TestDistance v-if="!practiseId" />
<block v-if="practiseId">
<TestDistance v-if="!start && !practiseResult.id" />
<block v-else>
<ShootProgress
:tips="`${
!start || scores.length === 12
@@ -143,13 +157,13 @@ onBeforeUnmount(() => {
/>
<ScorePanel2 :scores="scores.map((s) => s.ring)" />
<ScoreResult
v-if="practiseResult.arrows"
v-if="practiseResult.details"
:rowCount="6"
:total="total"
:onClose="onComplete"
:result="practiseResult"
:tipSrc="`../static/${
practiseResult.arrows.filter(
practiseResult.details.filter(
(arrow) => arrow.x !== -30 && arrow.y !== -30
).length < total
? 'un'