完成新的个人练习流程调试
This commit is contained in:
@@ -12,10 +12,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 } from "@/constants";
|
||||
import { MESSAGETYPESV2 } from "@/constants";
|
||||
|
||||
import useStore from "@/store";
|
||||
import { storeToRefs } from "pinia";
|
||||
@@ -30,41 +35,43 @@ const practiseId = ref("");
|
||||
const showGuide = ref(false);
|
||||
|
||||
const onReady = async () => {
|
||||
const result = await createPractiseAPI(total, 3);
|
||||
if (result) practiseId.value = result.id;
|
||||
await startPractiseAPI();
|
||||
scores.value = [];
|
||||
start.value = true;
|
||||
setTimeout(() => {
|
||||
audioManager.play("练习开始");
|
||||
}, 300);
|
||||
audioManager.play("练习开始");
|
||||
};
|
||||
|
||||
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);
|
||||
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);
|
||||
// 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) {
|
||||
@@ -74,7 +81,8 @@ async function onComplete() {
|
||||
practiseResult.value = {};
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
currentRound.value = 0;
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,12 +91,14 @@ const onClickShare = debounce(async () => {
|
||||
await wxShare("shareCanvas");
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
onMounted(async () => {
|
||||
uni.setKeepScreenOn({
|
||||
keepScreenOn: true,
|
||||
});
|
||||
uni.$on("socket-inbox", onReceiveMessage);
|
||||
uni.$on("share-image", onClickShare);
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
@@ -98,14 +108,19 @@ onBeforeUnmount(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
uni.$off("share-image", onClickShare);
|
||||
audioManager.stopAll();
|
||||
endPractiseAPI();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Container :bgType="1" title="日常耐力挑战" :showBottom="!start && !scores.length">
|
||||
<Container
|
||||
:bgType="1"
|
||||
title="日常耐力挑战"
|
||||
:showBottom="!start && !scores.length"
|
||||
>
|
||||
<view>
|
||||
<TestDistance v-if="!practiseId" />
|
||||
<block v-if="practiseId">
|
||||
<TestDistance v-if="!start && !practiseResult.id" />
|
||||
<block v-else>
|
||||
<ShootProgress
|
||||
:tips="`请连续射${total}支箭`"
|
||||
:start="start"
|
||||
@@ -134,13 +149,13 @@ onBeforeUnmount(() => {
|
||||
:font-size="20"
|
||||
/>
|
||||
<ScoreResult
|
||||
v-if="practiseResult.arrows"
|
||||
v-if="practiseResult.details"
|
||||
:total="total"
|
||||
:rowCount="9"
|
||||
:onClose="onComplete"
|
||||
:result="practiseResult"
|
||||
:tipSrc="`../static/${
|
||||
practiseResult.arrows.filter(
|
||||
practiseResult.details.filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length < total
|
||||
? '2un'
|
||||
|
||||
Reference in New Issue
Block a user