update:新版本websocket

This commit is contained in:
2026-07-10 13:57:09 +08:00
parent 58a7bb2017
commit b5373bee31
11 changed files with 216 additions and 31 deletions
+26 -9
View File
@@ -32,7 +32,7 @@ const store = useStore();
const { user, online } = storeToRefs(store);
const DEFAULT_SHOOT_TIME = 15;
const READY_SECONDS = 15;
const DEFAULT_READY_TIME = 15;
const READY_TIMER_EMIT_DELAY = 200;
const RESTORE_DELAY = 300;
const RESTORE_EMPTY_ID_RETRY_DELAY = 50;
@@ -81,6 +81,7 @@ const showRoundTip = ref(false);
const isFinalShoot = ref(false);
const matchStatus = ref(undefined);
const shootTimeTotal = ref(DEFAULT_SHOOT_TIME);
const readyTime = ref(DEFAULT_READY_TIME);
const showOfflineModal = ref(false);
const restoreLoading = ref(false);
const xRingStreaks = ref({});
@@ -144,6 +145,20 @@ function normalizeTimestamp(value) {
return numberValue < 1000000000000 ? numberValue * 1000 : numberValue;
}
function getReadyTime(battleInfo) {
const value = Number(battleInfo?.readyTime);
return Number.isFinite(value) && value > 0 ? value : DEFAULT_READY_TIME;
}
function getReadyRemainingSeconds(battleInfo) {
const total = getReadyTime(battleInfo);
const countdownStartTime = normalizeTimestamp(battleInfo?.countdownStartTime);
if (!countdownStartTime) return total;
const elapsed = Math.max(0, (Date.now() - countdownStartTime) / 1000);
return Math.max(0, total - elapsed);
}
function getReadySnapshotKey(matchId) {
return `${MATCH_READY_SNAPSHOT_PREFIX}${String(matchId || "")}`;
}
@@ -830,6 +845,7 @@ function stopProgressAfterMount() {
// 待开局状态:清理比赛态展示,并恢复准备倒计时。
function applyReadyState(battleInfo) {
hideRestoreLoading();
readyTime.value = getReadyTime(battleInfo);
start.value = false;
showRoundTip.value = false;
currentShooterId.value = 0;
@@ -841,13 +857,9 @@ function applyReadyState(battleInfo) {
clearProgressZeroWaiters();
cancelRoundTipDisplay();
const serverTime = normalizeTimestamp(battleInfo?.serverTime || Date.now());
const readyElapsed = (Date.now() - serverTime) / 1000;
if (readyElapsed > 0 && readyElapsed < READY_SECONDS) {
setTimeout(() => {
uni.$emit("update-timer", READY_SECONDS - readyElapsed - 0.2);
}, READY_TIMER_EMIT_DELAY);
}
setTimeout(() => {
uni.$emit("update-timer", getReadyRemainingSeconds(battleInfo));
}, READY_TIMER_EMIT_DELAY);
}
// 快照恢复入口:只把页面拉到服务端最新状态,不重放已经发生过的语音。
@@ -1346,7 +1358,12 @@ onShow(() => {
:blueTeam="blueTeam"
:winner="0"
/>
<TestDistance v-if="start === false" :guide="false" :isBattle="true"/>
<TestDistance
v-if="start === false"
:guide="false"
:isBattle="true"
:count="readyTime"
/>
<!-- 比赛进行中显示左右队伍进度条靶面和底部比分 -->
<view v-if="start" class="players-row">
<TeamAvatars