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
+39 -6
View File
@@ -36,6 +36,7 @@ const playersSorted = ref([]);
const playersScores = ref([]);
const halfTimeTip = ref(false);
const halfRest = ref(false);
const DEFAULT_READY_TIME = 15;
const HALF_REST_SECONDS = 20;
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
const MATCH_STATUS_BY_TEXT = {
@@ -46,6 +47,7 @@ const MATCH_STATUS_BY_TEXT = {
MATCH_STATUS_UNEXPECTEDLY: 4,
};
const halfRestRemain = ref(HALF_REST_SECONDS);
const readyTime = ref(DEFAULT_READY_TIME);
let halfRestTimer = null;
/** 控制设备离线提示弹窗的显示状态 */
const showOfflineModal = ref(false);
@@ -132,6 +134,27 @@ function normalizeBattleInfo(battleInfo) {
return battleInfo;
}
function normalizeTimestamp(value) {
const numberValue = Number(value || 0);
if (!numberValue) return 0;
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);
console.log('11111111111111111111111111111', total, countdownStartTime, Math.max(0, (Date.now() - countdownStartTime) / 1000))
return Math.max(0, total - elapsed);
}
function hasKnownStatus(battleInfo) {
return !(
battleInfo?.status === undefined ||
@@ -168,6 +191,7 @@ function reconnectMatchServer(battleInfo) {
serverAddr: battleInfo.serverAddr,
matchId: battleInfo.matchId || battleId.value,
userId: user.value.id,
mode: battleInfo.mode,
});
}
@@ -235,10 +259,10 @@ function recoverData(battleInfo, { force = false } = {}) {
}
if (battleInfo.status === 0) {
const readyRemain = (Date.now() - (battleInfo.serverTime || Date.now())) / 1000;
if (readyRemain > 0 && readyRemain < 15) {
setTimeout(() => uni.$emit("update-timer", 15 - readyRemain - 0.2), 200);
}
readyTime.value = getReadyTime(battleInfo);
setTimeout(() => {
uni.$emit("update-timer", getReadyRemainingSeconds(battleInfo));
}, 200);
return;
}
@@ -293,7 +317,11 @@ onLoad(async (options) => {
return;
}
const readySnapshot = takeReadySnapshot(battleId.value);
if (readySnapshot?.status === 0) recoverData(readySnapshot);
if (readySnapshot?.status === 0) {
skipNextRestoreOnShow = true;
reconnectMatchServer(readySnapshot);
recoverData(readySnapshot);
}
// uni.enableAlertBeforeUnload({
// message: "离开比赛可能导致比赛失败,是否继续?",
// success: (res) => {
@@ -426,7 +454,12 @@ onShow(async () => {
<Container :title="title" :bgType="1">
<view class="container">
<BattleHeader v-if="!start" :players="players" />
<TestDistance v-if="start === false" :guide="false" :isBattle="true" />
<TestDistance
v-if="start === false"
:guide="false"
:isBattle="true"
:count="readyTime"
/>
<ShootProgress
:show="start"
:start="start && !halfRest"