fix(mp): 导航/请求健壮性 — reLaunch 去重 + 失败降级

- navigateToLogin 添加去重 + reLaunch 失败降级 redirectTo
- request.ts safeReLaunch 添加目标页检测 + 失败降级
- 退出登录 reLaunch 失败降级 redirectTo
- DoctorTabBar / 首页医生端跳转 reLaunch 失败降级
- 网络恢复时正确清理 toast 状态和定时器
This commit is contained in:
iven
2026-05-25 13:45:12 +08:00
parent 485b9bb926
commit 1a376a255d
5 changed files with 39 additions and 5 deletions

View File

@@ -3,8 +3,26 @@ import Taro from '@tarojs/taro';
const LOGIN_PAGE = '/pages/login/index';
const MAX_PAGE_STACK = 9;
// reLaunch 去重:避免 401 + 并发请求同时触发多个 reLaunch
let reLaunchPromise: Promise<void> | null = null;
export function navigateToLogin() {
Taro.reLaunch({ url: LOGIN_PAGE });
// 已在登录页,跳过
const pages = Taro.getCurrentPages();
const currentPath = pages[pages.length - 1]?.path || '';
if (currentPath.includes('pages/login')) return;
// 去重:上一个 reLaunch 还没完成就跳过
if (reLaunchPromise) return;
reLaunchPromise = Taro.reLaunch({ url: LOGIN_PAGE })
.catch((err) => {
console.warn('[navigate] reLaunch to login failed:', err);
// reLaunch 失败时降级为 redirectTo
Taro.redirectTo({ url: LOGIN_PAGE }).catch(() => {});
})
.then(() => {
setTimeout(() => { reLaunchPromise = null; }, 2000);
});
}
export function safeNavigateTo(url: string): void {