From c094fc7bef74a99baeb90bc110528459fc6f32dd Mon Sep 17 00:00:00 2001 From: chenlimao Date: Tue, 19 May 2026 11:39:34 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E9=87=8D=E8=BF=9B=E6=AF=94?= =?UTF-8?q?=E8=B5=9B=E9=80=BB=E8=BE=91=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/HeaderProgress.vue | 8 +++++++- src/pages/team-battle.vue | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/components/HeaderProgress.vue b/src/components/HeaderProgress.vue index da96697..b4bd643 100644 --- a/src/components/HeaderProgress.vue +++ b/src/components/HeaderProgress.vue @@ -19,12 +19,17 @@ const ended = ref(false); const halfTime = ref(false); const currentShot = ref(0); const totalShot = ref(0); +/** 标记组件是否已完成挂载,防止 immediate watcher 在挂载前用旧 store 值触发意外播音 */ +const isMounted = ref(false); watch( () => tips.value, (newVal) => { + // 挂载完成前不播音(避免 immediate store watcher 用旧值触发多余播报) + if (!isMounted.value) return; + // 空字符串或含"重回"的 tips 均不播音 + if (!newVal || newVal.includes("重回")) return; let key = []; - if (newVal.includes("重回")) return; if (currentRoundEnded.value) { // 播放当前轮次语音 key.push(`第${["一", "二", "三", "四", "五"][currentRound.value]}轮`); @@ -113,6 +118,7 @@ watch(() => store.game.tips, (newVal) => { }, { immediate: true }); onMounted(() => { + isMounted.value = true; uni.$on("update-tips", onUpdateTips); uni.$on("socket-inbox", onReceiveMessage); uni.$on("play-sound", playSound); diff --git a/src/pages/team-battle.vue b/src/pages/team-battle.vue index cb984ec..96e2e18 100644 --- a/src/pages/team-battle.vue +++ b/src/pages/team-battle.vue @@ -132,8 +132,18 @@ const recoverData = (battleInfo, {force = false, arrowOnly = false} = {}) => { // ShootProgress2(v-if="start")尚未挂载,update-remain 事件会被丢弃。 // 同时 HeaderProgress 对含"重回"的 tips 拦截音频,倒计时无法依赖 // onAudioEnded 驱动,需在 nextTick 后直接启动。 + + // playerId=0 表示后端处于过渡状态(上一位射手已完成、下一位尚未分配) + // 此时 startTime/targetTeam 均不可靠,停止进度条并等待 WS ToSomeoneShoot 驱动 + if (!battleInfo.current.playerId) { + nextTick(() => { + uni.$emit("update-tips", nextTips); + uni.$emit("update-remain", {stop: true}); + }); + return; + } + const elapsed = (Date.now() - battleInfo.current.startTime) / 1000; - console.log(`当前轮已进行${elapsed}秒`); if (elapsed > 0 && elapsed < shootTimeTotal.value) { updateRemainSecond.value = shootTimeTotal.value - elapsed - 0.2; }