update:新增匹配跳转幂等

This commit is contained in:
2026-07-20 16:46:04 +08:00
parent b15c37cb4a
commit 886faa0007
2 changed files with 25 additions and 11 deletions
+19 -7
View File
@@ -227,15 +227,27 @@ function normalizeRoute(route) {
return String(route || "").replace(/^\//, "");
}
function isCurrentBattlePage(matchId) {
const page = getCurrentPageInfo();
const route = normalizeRoute(page?.route);
if (route !== "pages/team-battle/index" && route !== "pages/melee-battle") {
return false;
function getRouteFromUrl(url) {
return normalizeRoute(String(url || "").split("?")[0]);
}
function isCurrentBattlePage(url, matchId) {
const page = getCurrentPageInfo();
const route = normalizeRoute(page?.route);
const targetRoute = getRouteFromUrl(url);
if (!targetRoute || route !== targetRoute) return false;
const options = page?.options || page?.$page?.options || {};
return !matchId || normalizeId(options.battleId) === normalizeId(matchId);
const expectedMatchId = normalizeId(matchId);
if (!expectedMatchId) return true;
const routeMatchId = normalizeId(options.battleId);
if (routeMatchId) return routeMatchId === expectedMatchId;
return Boolean(
options.fromReturn &&
normalizeId(currentContext?.matchId) === expectedMatchId
);
}
function scheduleReadyRouteFallback(message) {
@@ -246,7 +258,7 @@ function scheduleReadyRouteFallback(message) {
lastReadyRouteKey = routeKey;
setTimeout(() => {
if (isCurrentBattlePage(matchId)) return;
if (isCurrentBattlePage(url, matchId)) return;
const currentRoute = normalizeRoute(getCurrentPageInfo()?.route);
// battle-room 和 match-page 本身会消费 AboutToStart;这里不绕过页面内状态,避免好友房误触退房逻辑。
+7 -5
View File
@@ -4,10 +4,12 @@ function getMatchId(battleInfo) {
return battleInfo?.matchId || battleInfo?.id || "";
}
function getBattlePageUrl(battleInfo) {
return Number(battleInfo?.mode) <= 3
? "/pages/team-battle/index?fromReturn=1"
: "/pages/melee-battle?fromReturn=1";
function getBattlePageUrl(battleInfo, matchId) {
const page =
Number(battleInfo?.mode) <= 3
? "/pages/team-battle/index"
: "/pages/melee-battle";
return `${page}?fromReturn=1&battleId=${encodeURIComponent(String(matchId))}`;
}
export function takeMatchReturnSnapshot() {
@@ -27,6 +29,6 @@ export async function returnToBattle(battleInfo, navigate) {
}
uni.setStorageSync(MATCH_RETURN_SNAPSHOT_KEY, battleInfo);
await navigate(getBattlePageUrl(battleInfo));
await navigate(getBattlePageUrl(battleInfo, matchId));
return true;
}