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

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

@@ -196,18 +196,23 @@ export const getMyDevicesAPI = () => {
return request("GET", "/user/device/getBindings"); return request("GET", "/user/device/getBindings");
}; };
export const createPractiseAPI = (arrows, mode) => { export const createPractiseAPI = (arrows, time) => {
return request("POST", "/user/practice/create", { return request("POST", "/user/practice/create", {
arrows, shootNumber: arrows,
mode, shootTime: time,
}); });
}; };
export const startPractiseAPI = () => {
return request("POST", "/user/practice/begin");
};
export const endPractiseAPI = () => {
return request("POST", "/user/practice/stop");
};
export const getPractiseAPI = async (id) => { export const getPractiseAPI = async (id) => {
const result = await request("GET", `/user/practice/get?id=${id}`); return request("GET", `/user/practice/get?id=${id}`);
const data = { ...(result.UserPracticeRound || {}) };
if (data.arrows) data.arrows = JSON.parse(data.arrows);
return data;
}; };
export const createRoomAPI = (gameType, teamSize) => { export const createRoomAPI = (gameType, teamSize) => {

View File

@@ -50,14 +50,14 @@ onMounted(() => {
if (props.result.lvl > user.value.lvl) { if (props.result.lvl > user.value.lvl) {
showUpgrade.value = true; showUpgrade.value = true;
} }
totalRing.value = (props.result.arrows || []).reduce( totalRing.value = (props.result.details || []).reduce(
(last, next) => last + next.ring, (last, next) => last + next.ring,
0 0
); );
}); });
const validArrows = computed(() => { const validArrows = computed(() => {
return (props.result.arrows || []).filter( return (props.result.details || []).filter(
(arrow) => arrow.x !== -30 && arrow.y !== -30 (arrow) => arrow.x !== -30 && arrow.y !== -30
).length; ).length;
}); });
@@ -96,8 +96,8 @@ const getRing = (arrow) => {
</view> </view>
<view :style="{ gridTemplateColumns: `repeat(${rowCount}, 1fr)` }"> <view :style="{ gridTemplateColumns: `repeat(${rowCount}, 1fr)` }">
<view v-for="(_, index) in new Array(total).fill(0)" :key="index"> <view v-for="(_, index) in new Array(total).fill(0)" :key="index">
{{ getRing(result.arrows[index]) {{ getRing(result.details[index])
}}<text v-if="getRing(result.arrows[index]) !== '-'"></text> }}<text v-if="getRing(result.details[index]) !== '-'"></text>
</view> </view>
</view> </view>
<view> <view>
@@ -133,7 +133,7 @@ const getRing = (arrow) => {
}}</text }}</text
>环的成绩所有箭支上靶后的平均点间距为<text >环的成绩所有箭支上靶后的平均点间距为<text
:style="{ color: '#fed847' }" :style="{ color: '#fed847' }"
>{{ Number(result.average_distance.toFixed(2)) }}</text >{{ Number((result.average_distance || 0).toFixed(2)) }}</text
>{{ >{{
result.spreadEvaluation === "Dispersed" result.spreadEvaluation === "Dispersed"
? "还需要持续改进哦~" ? "还需要持续改进哦~"
@@ -161,7 +161,7 @@ const getRing = (arrow) => {
</ScreenHint> </ScreenHint>
<BowData <BowData
:total="result.completed_arrows" :total="result.completed_arrows"
:arrows="result.arrows" :arrows="result.details"
:show="showBowData" :show="showBowData"
:onClose="() => (showBowData = false)" :onClose="() => (showBowData = false)"
/> />

View File

@@ -128,14 +128,17 @@ async function onReceiveMessage(msg) {
} else if (msg.type === MESSAGETYPESV2.BattleEnd) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) {
audioManager.play("比赛结束"); audioManager.play("比赛结束");
} else if (msg.type === MESSAGETYPESV2.ShootResult) { } else if (msg.type === MESSAGETYPESV2.ShootResult) {
if (msg.shootData.playerId !== user.value.id) return; let arrow = {};
if (msg.shootData) { if (msg.details && Array.isArray(msg.details)) {
let key = []; arrow = msg.details[msg.details.length - 1];
key.push(msg.shootData.ring ? `${msg.shootData.ring}` : "未上靶"); } else {
if (!msg.shootData.ring) if (msg.shootData.playerId !== user.value.id) return;
key.push(`${getDirectionText(msg.shootData.angle)}调整`); if (msg.shootData) arrow = msg.shootData;
audioManager.play(key, false);
} }
let key = [];
key.push(arrow.ring ? `${arrow.ring}` : "未上靶");
if (!arrow.ring) key.push(`${getDirectionText(arrow.angle)}调整`);
audioManager.play(key, false);
} else if (msg.type === MESSAGETYPESV2.HalfRest) { } else if (msg.type === MESSAGETYPESV2.HalfRest) {
halfTime.value = true; halfTime.value = true;
audioManager.play("中场休息"); audioManager.play("中场休息");

View File

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

View File

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

View File

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

View File

@@ -12,10 +12,15 @@ import TestDistance from "@/components/TestDistance.vue";
import BubbleTip from "@/components/BubbleTip.vue"; import BubbleTip from "@/components/BubbleTip.vue";
import audioManager from "@/audioManager"; import audioManager from "@/audioManager";
import { createPractiseAPI, getPractiseAPI } from "@/apis"; import {
createPractiseAPI,
startPractiseAPI,
endPractiseAPI,
getPractiseAPI,
} from "@/apis";
import { sharePractiseData } from "@/canvas"; import { sharePractiseData } from "@/canvas";
import { wxShare, debounce } from "@/util"; import { wxShare, debounce } from "@/util";
import { MESSAGETYPES } from "@/constants"; import { MESSAGETYPESV2 } from "@/constants";
import useStore from "@/store"; import useStore from "@/store";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
@@ -30,41 +35,43 @@ const practiseId = ref("");
const showGuide = ref(false); const showGuide = ref(false);
const onReady = async () => { const onReady = async () => {
const result = await createPractiseAPI(total, 3); await startPractiseAPI();
if (result) practiseId.value = result.id;
scores.value = []; scores.value = [];
start.value = true; start.value = true;
setTimeout(() => { audioManager.play("练习开始");
audioManager.play("练习开始");
}, 300);
}; };
const onOver = async () => { const onOver = async () => {
start.value = false;
practiseResult.value = await getPractiseAPI(practiseId.value); practiseResult.value = await getPractiseAPI(practiseId.value);
start.value = false;
}; };
async function onReceiveMessage(messages = []) { async function onReceiveMessage(msg) {
messages.forEach((msg) => { if (msg.type === MESSAGETYPESV2.ShootResult) {
if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) { scores.value = msg.details;
if (scores.value.length < total) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) {
scores.value.push(msg.target); setTimeout(onOver, 1500);
if (practiseId && scores.value.length === total / 2) { }
showGuide.value = true; // messages.forEach((msg) => {
setTimeout(() => { // if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) {
showGuide.value = false; // if (scores.value.length < total) {
}, 3000); // scores.value.push(msg.target);
} // if (practiseId && scores.value.length === total / 2) {
if (scores.value.length === total) { // showGuide.value = true;
setTimeout(onOver, 1500); // setTimeout(() => {
} // showGuide.value = false;
} // }, 3000);
} // }
}); // if (scores.value.length === total) {
// setTimeout(onOver, 1500);
// }
// }
// }
// });
} }
async function onComplete() { async function onComplete() {
const validArrows = (practiseResult.value.arrows || []).filter( const validArrows = (practiseResult.value.details || []).filter(
(a) => a.x !== -30 && a.y !== -30 (a) => a.x !== -30 && a.y !== -30
); );
if (validArrows.length === total) { if (validArrows.length === total) {
@@ -74,7 +81,8 @@ async function onComplete() {
practiseResult.value = {}; practiseResult.value = {};
start.value = false; start.value = false;
scores.value = []; 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"); await wxShare("shareCanvas");
}); });
onMounted(() => { onMounted(async () => {
uni.setKeepScreenOn({ uni.setKeepScreenOn({
keepScreenOn: true, keepScreenOn: true,
}); });
uni.$on("socket-inbox", onReceiveMessage); uni.$on("socket-inbox", onReceiveMessage);
uni.$on("share-image", onClickShare); uni.$on("share-image", onClickShare);
const result = await createPractiseAPI(total, 360);
if (result) practiseId.value = result.id;
}); });
onBeforeUnmount(() => { onBeforeUnmount(() => {
@@ -98,14 +108,19 @@ onBeforeUnmount(() => {
uni.$off("socket-inbox", onReceiveMessage); uni.$off("socket-inbox", onReceiveMessage);
uni.$off("share-image", onClickShare); uni.$off("share-image", onClickShare);
audioManager.stopAll(); audioManager.stopAll();
endPractiseAPI();
}); });
</script> </script>
<template> <template>
<Container :bgType="1" title="日常耐力挑战" :showBottom="!start && !scores.length"> <Container
:bgType="1"
title="日常耐力挑战"
:showBottom="!start && !scores.length"
>
<view> <view>
<TestDistance v-if="!practiseId" /> <TestDistance v-if="!start && !practiseResult.id" />
<block v-if="practiseId"> <block v-else>
<ShootProgress <ShootProgress
:tips="`请连续射${total}支箭`" :tips="`请连续射${total}支箭`"
:start="start" :start="start"
@@ -134,13 +149,13 @@ onBeforeUnmount(() => {
:font-size="20" :font-size="20"
/> />
<ScoreResult <ScoreResult
v-if="practiseResult.arrows" v-if="practiseResult.details"
:total="total" :total="total"
:rowCount="9" :rowCount="9"
:onClose="onComplete" :onClose="onComplete"
:result="practiseResult" :result="practiseResult"
:tipSrc="`../static/${ :tipSrc="`../static/${
practiseResult.arrows.filter( practiseResult.details.filter(
(arrow) => arrow.x !== -30 && arrow.y !== -30 (arrow) => arrow.x !== -30 && arrow.y !== -30
).length < total ).length < total
? '2un' ? '2un'

View File

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