fix(router): 修复存储失效时登出逻辑的循环依赖

将存储失效登出逻辑从 storage 模块移至路由守卫,通过标志位解耦,
消除动态 import 及其引发的循环依赖问题。
This commit is contained in:
zhangtao
2026-05-11 17:05:52 +08:00
parent 80d4f18e8b
commit 7e7a5c97cb
2 changed files with 34 additions and 19 deletions
+9
View File
@@ -19,6 +19,7 @@ import { UserAPI } from "@/api/module_system/user";
import { ApiStatus, isHttpError } from "@utils/http";
import { RouteRegistry } from "./dynamicRoutes";
import { MenuProcessor } from "./MenuProcessor";
import { checkStorageInvalidated } from "@utils/storage";
// --- 模块级单例与守卫状态 ---
@@ -119,6 +120,14 @@ async function handleRouteGuard(
NProgress.start();
}
// 检查存储是否已失效(storage/index.ts 检测到异常时标记)
if (checkStorageInvalidated()) {
console.info("[RouteGuard] 检测到存储已失效,执行登出");
await userStore.logout();
next({ name: "Login", replace: true });
return;
}
if (!handleLoginStatus(to, userStore, next)) {
return;
}