fix:修复语音,射箭数字,第一轮提前报靶问题

This commit is contained in:
2026-05-22 17:57:20 +08:00
parent ef2a71f793
commit fe8b38bc6f
4 changed files with 91 additions and 13 deletions

View File

@@ -24,12 +24,14 @@ const onUpdateTips = (newVal) => {
// 监听 Pinia store 中 totalShot 变化,用于比赛恢复时同步箭数(替代 uni.$emit 避免时序问题)
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决重入时 totalShot 值不变 watch 不触发的问题)
watch(() => store.game.totalShot, (newVal) => {
if (newVal > 0) {
totalShot.value = newVal;
currentShot.value = store.game.currentShot;
}
}, { immediate: true });
watch(
() => [store.game.currentShot, store.game.totalShot],
([newCurrentShot, newTotalShot]) => {
currentShot.value = newCurrentShot || 0;
totalShot.value = newTotalShot || 0;
},
{ immediate: true }
);
// 监听 Pinia store 中 tips 变化,用于比赛恢复时同步提示文案(替代 uni.$emit 避免时序问题)
// 使用 immediate: true 确保组件创建时立即读取 store 当前值(解决 onShow 早于 onMounted 导致 uni.$emit 事件丢失的问题)

View File

@@ -9,7 +9,7 @@ const props = defineProps({
},
total: {
type: Number,
default: 15,
default: 12,
},
currentRound: {
type: String,
@@ -18,9 +18,9 @@ const props = defineProps({
});
const barColor = ref("");
const remain = ref(15);
const remain = ref(12);
const timer = ref(null);
const loading = ref(false);
const loading = ref(true);
const transitionStyle = ref("all 1s linear");
const currentTeam = ref(null);
const MIN_TICK_MS = 1;

View File

@@ -1,6 +1,6 @@
<script setup>
import { ref, onMounted, onBeforeUnmount, nextTick, watch } from "vue";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { onHide, onLoad, onShow } from "@dcloudio/uni-app";
import Container from "./components/Container.vue";
import BattleHeader from "./components/BattleHeader.vue";
import BowTarget from "./components/BowTarget.vue";
@@ -15,7 +15,10 @@ import SModal from "./components/SModal.vue";
import { laserCloseAPI, getBattleAPI } from "@/apis";
import { MESSAGETYPESV2 } from "@/constants";
import { getDirectionText } from "@/util";
import audioManager from "@/audioManager";
import audioManager, {
AUDIO_INTERRUPTION_BEGIN_EVENT,
AUDIO_INTERRUPTION_END_EVENT,
} from "@/audioManager";
import useStore from "@/store";
import { storeToRefs } from "pinia";
@@ -402,6 +405,20 @@ function onAudioEnded(key) {
});
}
function handleBattleCovered() {
if (pendingRestoreTimer) {
clearTimeout(pendingRestoreTimer);
pendingRestoreTimer = null;
}
hideRestoreLoading();
pendingRoundAudio = false;
invalidateBattleQueue({ stopAudio: true, stopProgress: true });
}
function handleBattleRecovered() {
scheduleRestoreLatestBattle();
}
// 队伍信息优先用接口返回值;接口缺失时使用本地缓存,避免重进页面时头像为空。
function loadTeamPlayers(teamInfo, storageKey) {
if (Array.isArray(teamInfo?.players)) return [...teamInfo.players];
@@ -995,6 +1012,8 @@ onMounted(async () => {
});
uni.$on("socket-inbox", onReceiveMessage);
uni.$on("audioEnded", onAudioEnded);
uni.$on(AUDIO_INTERRUPTION_BEGIN_EVENT, handleBattleCovered);
uni.$on(AUDIO_INTERRUPTION_END_EVENT, handleBattleRecovered);
uni.$on(PROGRESS_ZERO_EVENT, onProgressZero);
uni.$on(COUNTDOWN_READY_EVENT, hideRestoreLoading);
await laserCloseAPI();
@@ -1015,9 +1034,17 @@ onBeforeUnmount(() => {
}
hideRestoreLoading();
invalidateBattleQueue({ stopAudio: true, stopProgress: true });
console.log('onBeforeUnmount', '页面卸载前')
audioManager.stopAll();
uni.$off(AUDIO_INTERRUPTION_BEGIN_EVENT, handleBattleCovered);
uni.$off(AUDIO_INTERRUPTION_END_EVENT, handleBattleRecovered);
});
onHide(()=>{
console.log('onHide', '页面大退')
handleBattleCovered();
})
// 每次回到前台都重新拉最新比赛快照,确保画面与后端一致。
onShow(() => {
console.log('onshow')