完成新的个人练习流程调试
This commit is contained in:
@@ -13,10 +13,15 @@ import BowPower from "@/components/BowPower.vue";
|
||||
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";
|
||||
const store = useStore();
|
||||
@@ -62,24 +67,35 @@ const createPractise = async (arrows) => {
|
||||
};
|
||||
|
||||
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 (step.value === 2 && msg.target.dst / 100 >= 5) {
|
||||
btnDisabled.value = false;
|
||||
showGuide.value = true;
|
||||
} else if (scores.value.length < total) {
|
||||
scores.value.push(msg.target);
|
||||
}
|
||||
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);
|
||||
} else if (msg.type === MESSAGETYPESV2.TestDistance) {
|
||||
if (msg.shootData.distance / 100 >= 5) {
|
||||
audioManager.play("距离合格");
|
||||
btnDisabled.value = false;
|
||||
showGuide.value = true;
|
||||
} else audioManager.play("距离不足");
|
||||
}
|
||||
// messages.forEach((msg) => {
|
||||
// if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
|
||||
// if (step.value === 2 && msg.target.dst / 100 >= 5) {
|
||||
// btnDisabled.value = false;
|
||||
// showGuide.value = true;
|
||||
// } else if (scores.value.length < total) {
|
||||
// scores.value.push(msg.target);
|
||||
// }
|
||||
// if (scores.value.length === total) {
|
||||
// setTimeout(onOver, 1500);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
const onClickShare = debounce(async () => {
|
||||
@@ -102,6 +118,7 @@ onBeforeUnmount(() => {
|
||||
uni.$off("socket-inbox", onReceiveMessage);
|
||||
uni.$off("share-image", onClickShare);
|
||||
audioManager.stopAll();
|
||||
endPractiseAPI();
|
||||
});
|
||||
|
||||
const nextStep = async () => {
|
||||
@@ -113,13 +130,15 @@ const nextStep = async () => {
|
||||
btnDisabled.value = true;
|
||||
step.value = 2;
|
||||
title.value = "-感知距离";
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
} else if (step.value === 2) {
|
||||
showGuide.value = false;
|
||||
step.value = 3;
|
||||
title.value = "-小试牛刀";
|
||||
} else if (step.value === 3) {
|
||||
title.value = "小试牛刀";
|
||||
await createPractise(total);
|
||||
await startPractiseAPI();
|
||||
scores.value = [];
|
||||
step.value = 4;
|
||||
start.value = true;
|
||||
@@ -133,8 +152,8 @@ const nextStep = async () => {
|
||||
}
|
||||
};
|
||||
|
||||
const onClose = () => {
|
||||
const validArrows = (practiseResult.value.arrows || []).filter(
|
||||
const onClose = async () => {
|
||||
const validArrows = (practiseResult.value.details || []).filter(
|
||||
(a) => a.x !== -30 && a.y !== -30
|
||||
);
|
||||
if (validArrows.length === total) {
|
||||
@@ -148,6 +167,8 @@ const onClose = () => {
|
||||
start.value = false;
|
||||
scores.value = [];
|
||||
step.value = 3;
|
||||
const result = await createPractiseAPI(total, 360);
|
||||
if (result) practiseId.value = result.id;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
@@ -245,13 +266,13 @@ const onClose = () => {
|
||||
:scores="scores.map((s) => s.ring)"
|
||||
/>
|
||||
<ScoreResult
|
||||
v-if="practiseResult.arrows"
|
||||
v-if="practiseResult.details"
|
||||
:rowCount="6"
|
||||
:total="total"
|
||||
:onClose="onClose"
|
||||
:result="practiseResult"
|
||||
:tipSrc="`../static/${
|
||||
practiseResult.arrows.filter(
|
||||
practiseResult.details.filter(
|
||||
(arrow) => arrow.x !== -30 && arrow.y !== -30
|
||||
).length < total
|
||||
? 'un'
|
||||
|
||||
Reference in New Issue
Block a user