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

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 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'

View File

@@ -40,11 +40,9 @@ const toPage = async (path) => {
return;
}
if (path === "/pages/first-try") {
if (canEenter(user.value, device.value, online.value, path)) {
await uni.$checkAudio();
} else {
return;
}
// if (canEenter(user.value, device.value, online.value, path)) {
// await uni.$checkAudio();
// }
}
uni.navigateTo({ url: path });
};

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'

View File

@@ -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'

View File

@@ -15,7 +15,7 @@ const data = ref({});
const goPractise = async (type) => {
if (!canEenter(user.value, device.value, online.value)) return;
await uni.$checkAudio();
// await uni.$checkAudio();
uni.navigateTo({
url: `/pages/practise-${type}`,
});