From 2a2dddfc11c5b97fc4adeadbdd3a5deec6c2b36c Mon Sep 17 00:00:00 2001 From: kron Date: Sat, 31 May 2025 14:57:25 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=83=E4=B9=A0=E7=BB=93=E6=9E=9C=E5=AE=8C?= =?UTF-8?q?=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/BowTarget.vue | 4 +++- src/components/ScoreResult.vue | 27 +++++++++++++++++---------- src/constants.js | 1 + src/pages/first-try.vue | 18 +++++++++++++----- src/pages/practise-one.vue | 14 +++++++++++--- src/pages/practise-two.vue | 17 ++++++++++++----- 6 files changed, 57 insertions(+), 24 deletions(-) diff --git a/src/components/BowTarget.vue b/src/components/BowTarget.vue index 134a2d9..50c0563 100644 --- a/src/components/BowTarget.vue +++ b/src/components/BowTarget.vue @@ -46,7 +46,9 @@ function calcRealY(num) { 大人,请射箭 {{ - currentRound + "/" + totalRound + (currentRound > totalRound ? totalRound : currentRound) + + "/" + + totalRound }} diff --git a/src/components/ScoreResult.vue b/src/components/ScoreResult.vue index 4a9646c..4f36de3 100644 --- a/src/components/ScoreResult.vue +++ b/src/components/ScoreResult.vue @@ -20,9 +20,9 @@ const props = defineProps({ type: Number, default: 0, }, - scores: { - type: Array, - default: () => [], + result: { + type: Object, + default: () => ({}), }, }); const showPanel = ref(true); @@ -39,14 +39,20 @@ setTimeout(() => { diff --git a/src/constants.js b/src/constants.js index 0d57da0..c09a042 100644 --- a/src/constants.js +++ b/src/constants.js @@ -1,3 +1,4 @@ export const MESSAGETYPES = { ShootSyncMeArrowID: parseInt("0x789b6b0d"), + ShootSyncMePracticeID: parseInt("0xD88AE05E"), }; diff --git a/src/pages/first-try.vue b/src/pages/first-try.vue index 5f5d545..5621cdc 100644 --- a/src/pages/first-try.vue +++ b/src/pages/first-try.vue @@ -27,11 +27,14 @@ const stepButtonTexts = [ "", "退出新手试炼", ]; +const start = ref(false); +const practiseResult = ref({}); +const power = ref(0); const onReady = async () => { const result = await createPractiseAPI(total); const token = uni.getStorageSync("token"); - + start.value = true; websocket.createWebSocket(token, (content) => { const messages = JSON.parse(content).data.updates || []; messages.forEach((msg) => { @@ -39,9 +42,14 @@ const onReady = async () => { scores.value.push(msg.target); if (scores.value.length === total) { showScore.value = true; - websocket.closeWebSocket(); } } + if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { + practiseResult.value = { + ...msg.practice, + arrows: JSON.parse(msg.practice.arrows), + }; + } }); }); }; @@ -144,11 +152,11 @@ const onClose = () => { v-if="step === 4" tips="请开始连续射箭" :total="100" - :start="true" + :start="start" /> { :show="showScore" v-if="step === 4" :onClose="onClose" - :scores="scores.map((s) => s.ring)" + :result="practiseResult" /> {{ stepButtonTexts[step] diff --git a/src/pages/practise-one.vue b/src/pages/practise-one.vue index 7f00298..9c5ad92 100644 --- a/src/pages/practise-one.vue +++ b/src/pages/practise-one.vue @@ -14,6 +14,8 @@ const start = ref(false); const showScore = ref(false); const scores = ref([]); const total = 12; +const practiseResult = ref({}); +const power = ref(0); const onReady = async () => { const result = await createPractiseAPI(total); @@ -25,11 +27,17 @@ const onReady = async () => { messages.forEach((msg) => { if (msg.constructor === MESSAGETYPES.ShootSyncMeArrowID) { scores.value.push(msg.target); + power.value = msg.target.battery; if (scores.value.length === total) { showScore.value = true; - websocket.closeWebSocket(); } } + if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { + practiseResult.value = { + ...msg.practice, + arrows: JSON.parse(msg.practice.arrows), + }; + } }); }); }; @@ -58,7 +66,7 @@ onUnmounted(() => { :totalRound="total" :currentRound="scores.length + 1" avatar="../static/avatar.png" - :power="45" + :power="power" :scores="scores" /> @@ -67,7 +75,7 @@ onUnmounted(() => { :rowCount="6" :show="showScore" :onClose="() => (showScore = false)" - :scores="scores.map((s) => s.ring)" + :result="practiseResult" /> 准备好了,直接开始 diff --git a/src/pages/practise-two.vue b/src/pages/practise-two.vue index de83187..92ef8ef 100644 --- a/src/pages/practise-two.vue +++ b/src/pages/practise-two.vue @@ -14,6 +14,8 @@ const start = ref(false); const showScore = ref(false); const scores = ref([]); const total = 36; +const practiseResult = ref({}); +const power = ref(0); const onReady = async () => { const result = await createPractiseAPI(total); @@ -27,9 +29,14 @@ const onReady = async () => { scores.value.push(msg.target); if (scores.value.length === total) { showScore.value = true; - websocket.closeWebSocket(); } } + if (msg.constructor === MESSAGETYPES.ShootSyncMePracticeID) { + practiseResult.value = { + ...msg.practice, + arrows: JSON.parse(msg.practice.arrows), + }; + } }); }); }; @@ -41,14 +48,14 @@ onUnmounted(() => {