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
+13
View File
@@ -12,6 +12,7 @@ const gameType = ref(0);
const teamSize = ref(0);
const onComplete = ref(null);
const showLimitModal = ref(false);
const MATCH_READY_SNAPSHOT_PREFIX = "match-ready-snapshot:";
/** 匹配超时计时器,用于检测 WS 消息丢失或真正超时 */
const matchTimeoutTimer = ref(null);
@@ -27,6 +28,17 @@ const clearMatchTimeout = () => {
}
};
const cacheReadyBattle = (battle) => {
const matchId = String(battle?.matchId || "");
if (!matchId) return;
uni.setStorageSync(`${MATCH_READY_SNAPSHOT_PREFIX}${matchId}`, {
...battle,
status: battle.status == null ? 0 : Number(battle.status),
savedAt: Date.now(),
});
};
/**
* 超时处理:查询后端是否已分配对局
* - 有对局 → WS 消息丢失场景,自动跳入
@@ -36,6 +48,7 @@ const handleMatchTimeout = async () => {
try {
const battle = await getBattleAPI();
if (battle && battle.matchId) {
cacheReadyBattle(battle);
uni.showToast({ title: "匹配成功,正在进入...", icon: "none" });
if (battle.mode <= 3) {
uni.redirectTo({ url: `/pages/team-battle/index?battleId=${battle.matchId}` });