update:优化比赛流程

This commit is contained in:
2026-07-16 11:38:17 +08:00
parent fa7ad8f538
commit 621397e25d
4 changed files with 35 additions and 14 deletions
+31 -12
View File
@@ -397,6 +397,16 @@ function showRestoreLoading() {
}, RESTORE_LOADING_TIMEOUT);
}
// 终局开始后作废恢复请求,避免恢复遮罩与结算跳转抢占画面。
function cancelPendingBattleRestore() {
restoreGeneration += 1;
if (pendingRestoreTimer) {
clearTimeout(pendingRestoreTimer);
pendingRestoreTimer = null;
}
hideRestoreLoading();
}
// 页面重置、离开或恢复快照时调用,统一清理队列、等待器、音频和进度条。
function invalidateBattleQueue({ stopAudio = false, stopProgress = false } = {}) {
// 提升队列代际并清空待执行消息,确保恢复快照时不会继续跑旧战况。
@@ -416,7 +426,10 @@ function invalidateBattleQueue({ stopAudio = false, stopProgress = false } = {})
function enqueueBattleMessage(message) {
if (Array.isArray(message) || !message?.type) return;
if (battleEnded && message.type !== MESSAGETYPESV2.BattleEnd) return;
if (message.type === MESSAGETYPESV2.BattleEnd) battleEnded = true;
if (message.type === MESSAGETYPESV2.BattleEnd) {
battleEnded = true;
cancelPendingBattleRestore();
}
if (message.type === MESSAGETYPESV2.InvalidShot) {
const receivedAt = Date.now();
@@ -782,7 +795,7 @@ function getBackendRemainingSeconds(battleInfo, total) {
return null;
}
// 计算当前倒计时剩余秒数:后端字段优先,其次按开始时间和当前时间补算。
// 计算当前倒计时剩余秒数:后端字段优先,其次按 ACK 时间和当前时间补算。
function getRemainingSeconds(battleInfo, task, options = {}) {
const total = getShootTimeSeconds(battleInfo);
const backendRemain = getBackendRemainingSeconds(battleInfo, total);
@@ -790,8 +803,9 @@ function getRemainingSeconds(battleInfo, task, options = {}) {
// 新轮首箭由后端 shootTime 定完整时长;没有明确剩余时间时,不扣前端轮次弹窗/语音耗时。
if (options.fullDurationIfNoBackendRemain) return total;
const startTime = normalizeTimestamp(battleInfo?.current?.startTime);
if (!startTime) return total;
const ackTime = normalizeTimestamp(battleInfo?.current?.ackTime);
console.log(11111111111111111111111111,ackTime)
if (!ackTime) return total;
// 后端时间是准的,前端只根据语音耗时和接收延迟做近似补偿。
// 但回前台的 API 快照不一定带“当前后端时间”,恢复场景优先用本机当前时间计算最新剩余秒数。
@@ -800,7 +814,8 @@ function getRemainingSeconds(battleInfo, task, options = {}) {
: task?.serverTime || getServerTime(battleInfo) || Date.now();
const waitAfterReceive = task?.serverTime ? Date.now() - task.receivedAt : 0;
const effectiveNow = anchorTime + waitAfterReceive;
const elapsed = Math.max(0, (effectiveNow - startTime) / 1000);
const elapsed = Math.max(0, (effectiveNow - ackTime) / 1000);
console.log('剩余:', elapsed, waitAfterReceive, Math.max(0, Math.min(total, total - elapsed)))
return Math.max(0, Math.min(total, total - elapsed));
}
@@ -1102,12 +1117,7 @@ function navigateToBattleResultOnce(matchId) {
resultNavigationPending = true;
battleEnded = true;
restoreGeneration += 1;
if (pendingRestoreTimer) {
clearTimeout(pendingRestoreTimer);
pendingRestoreTimer = null;
}
hideRestoreLoading();
cancelPendingBattleRestore();
uni.redirectTo({
url: `/pages/friend-battle-result?battleId=${targetMatchId}`,
@@ -1176,7 +1186,14 @@ async function runInvalidShotTask(task, runId) {
// 回前台恢复入口:拉取服务端快照,处理结束态,然后继续消费增量队列。
async function restoreLatestBattle() {
if (!battleId.value || resultNavigationPending) return;
if (
!battleId.value ||
battleEnded ||
battleEndTaskRunning ||
resultNavigationPending
) {
return;
}
const currentRestoreId = ++restoreGeneration;
showRestoreLoading();
@@ -1245,6 +1262,8 @@ async function restoreLatestBattle() {
}
function scheduleRestoreLatestBattle() {
if (battleEnded || battleEndTaskRunning || resultNavigationPending) return;
if (pendingRestoreTimer) {
clearTimeout(pendingRestoreTimer);
pendingRestoreTimer = null;