update:新增匹配跳转幂等
This commit is contained in:
+19
-7
@@ -227,15 +227,27 @@ function normalizeRoute(route) {
|
|||||||
return String(route || "").replace(/^\//, "");
|
return String(route || "").replace(/^\//, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCurrentBattlePage(matchId) {
|
function getRouteFromUrl(url) {
|
||||||
const page = getCurrentPageInfo();
|
return normalizeRoute(String(url || "").split("?")[0]);
|
||||||
const route = normalizeRoute(page?.route);
|
|
||||||
if (route !== "pages/team-battle/index" && route !== "pages/melee-battle") {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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 || {};
|
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) {
|
function scheduleReadyRouteFallback(message) {
|
||||||
@@ -246,7 +258,7 @@ function scheduleReadyRouteFallback(message) {
|
|||||||
|
|
||||||
lastReadyRouteKey = routeKey;
|
lastReadyRouteKey = routeKey;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (isCurrentBattlePage(matchId)) return;
|
if (isCurrentBattlePage(url, matchId)) return;
|
||||||
|
|
||||||
const currentRoute = normalizeRoute(getCurrentPageInfo()?.route);
|
const currentRoute = normalizeRoute(getCurrentPageInfo()?.route);
|
||||||
// battle-room 和 match-page 本身会消费 AboutToStart;这里不绕过页面内状态,避免好友房误触退房逻辑。
|
// battle-room 和 match-page 本身会消费 AboutToStart;这里不绕过页面内状态,避免好友房误触退房逻辑。
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ function getMatchId(battleInfo) {
|
|||||||
return battleInfo?.matchId || battleInfo?.id || "";
|
return battleInfo?.matchId || battleInfo?.id || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function getBattlePageUrl(battleInfo) {
|
function getBattlePageUrl(battleInfo, matchId) {
|
||||||
return Number(battleInfo?.mode) <= 3
|
const page =
|
||||||
? "/pages/team-battle/index?fromReturn=1"
|
Number(battleInfo?.mode) <= 3
|
||||||
: "/pages/melee-battle?fromReturn=1";
|
? "/pages/team-battle/index"
|
||||||
|
: "/pages/melee-battle";
|
||||||
|
return `${page}?fromReturn=1&battleId=${encodeURIComponent(String(matchId))}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function takeMatchReturnSnapshot() {
|
export function takeMatchReturnSnapshot() {
|
||||||
@@ -27,6 +29,6 @@ export async function returnToBattle(battleInfo, navigate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uni.setStorageSync(MATCH_RETURN_SNAPSHOT_KEY, battleInfo);
|
uni.setStorageSync(MATCH_RETURN_SNAPSHOT_KEY, battleInfo);
|
||||||
await navigate(getBattlePageUrl(battleInfo));
|
await navigate(getBattlePageUrl(battleInfo, matchId));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user