From d9a2e53faf332eb81da3906f176e7902a5e0d517 Mon Sep 17 00:00:00 2001 From: kron Date: Sat, 7 Feb 2026 18:30:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=96=B0=E7=9A=84=E4=B8=AA?= =?UTF-8?q?=E4=BA=BA=E7=BB=83=E4=B9=A0=E6=B5=81=E7=A8=8B=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis.js | 19 +++++--- src/components/ScoreResult.vue | 12 ++--- src/components/ShootProgress.vue | 17 ++++--- src/pages/first-try.vue | 65 ++++++++++++++++--------- src/pages/index.vue | 8 ++-- src/pages/practise-one.vue | 80 ++++++++++++++++++------------- src/pages/practise-two.vue | 81 +++++++++++++++++++------------- src/pages/practise.vue | 2 +- 8 files changed, 170 insertions(+), 114 deletions(-) diff --git a/src/apis.js b/src/apis.js index 28e6228..4c4850a 100644 --- a/src/apis.js +++ b/src/apis.js @@ -196,18 +196,23 @@ export const getMyDevicesAPI = () => { return request("GET", "/user/device/getBindings"); }; -export const createPractiseAPI = (arrows, mode) => { +export const createPractiseAPI = (arrows, time) => { return request("POST", "/user/practice/create", { - arrows, - mode, + shootNumber: arrows, + 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) => { - const result = await request("GET", `/user/practice/get?id=${id}`); - const data = { ...(result.UserPracticeRound || {}) }; - if (data.arrows) data.arrows = JSON.parse(data.arrows); - return data; + return request("GET", `/user/practice/get?id=${id}`); }; export const createRoomAPI = (gameType, teamSize) => { diff --git a/src/components/ScoreResult.vue b/src/components/ScoreResult.vue index 73eec70..27d8de4 100644 --- a/src/components/ScoreResult.vue +++ b/src/components/ScoreResult.vue @@ -50,14 +50,14 @@ onMounted(() => { if (props.result.lvl > user.value.lvl) { showUpgrade.value = true; } - totalRing.value = (props.result.arrows || []).reduce( + totalRing.value = (props.result.details || []).reduce( (last, next) => last + next.ring, 0 ); }); const validArrows = computed(() => { - return (props.result.arrows || []).filter( + return (props.result.details || []).filter( (arrow) => arrow.x !== -30 && arrow.y !== -30 ).length; }); @@ -96,8 +96,8 @@ const getRing = (arrow) => { - {{ getRing(result.arrows[index]) - }} + {{ getRing(result.details[index]) + }} @@ -133,7 +133,7 @@ const getRing = (arrow) => { }}环的成绩,所有箭支上靶后的平均点间距为{{ Number(result.average_distance.toFixed(2)) }}{{ Number((result.average_distance || 0).toFixed(2)) }},{{ result.spreadEvaluation === "Dispersed" ? "还需要持续改进哦~" @@ -161,7 +161,7 @@ const getRing = (arrow) => { diff --git a/src/components/ShootProgress.vue b/src/components/ShootProgress.vue index 9173021..1ee5f59 100644 --- a/src/components/ShootProgress.vue +++ b/src/components/ShootProgress.vue @@ -128,14 +128,17 @@ async function onReceiveMessage(msg) { } else if (msg.type === MESSAGETYPESV2.BattleEnd) { audioManager.play("比赛结束"); } else if (msg.type === MESSAGETYPESV2.ShootResult) { - if (msg.shootData.playerId !== user.value.id) return; - if (msg.shootData) { - let key = []; - key.push(msg.shootData.ring ? `${msg.shootData.ring}环` : "未上靶"); - if (!msg.shootData.ring) - key.push(`向${getDirectionText(msg.shootData.angle)}调整`); - audioManager.play(key, false); + let arrow = {}; + if (msg.details && Array.isArray(msg.details)) { + arrow = msg.details[msg.details.length - 1]; + } else { + if (msg.shootData.playerId !== user.value.id) return; + if (msg.shootData) arrow = msg.shootData; } + 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) { halfTime.value = true; audioManager.play("中场休息"); diff --git a/src/pages/first-try.vue b/src/pages/first-try.vue index 9bad64a..6f76794 100644 --- a/src/pages/first-try.vue +++ b/src/pages/first-try.vue @@ -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; } }; @@ -245,13 +266,13 @@ const onClose = () => { :scores="scores.map((s) => s.ring)" /> { - 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(); }); @@ -115,8 +129,8 @@ onBeforeUnmount(() => { :showBottom="!start && !scores.length" > - - + + s.ring)" /> { - 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(); });