perf(admin): 实现切页即时导航与列表 loading 壳

非阻塞 session 刷新、侧边栏 chunk 预取、KeepAlive 对齐,以及按 tab 延迟加载重型列表页。
This commit is contained in:
2026-06-18 16:45:01 +08:00
parent f2f6927a75
commit c5a5e66bbd
21 changed files with 321 additions and 117 deletions

View File

@@ -1,7 +1,7 @@
import { createRouter, createWebHistory } from 'vue-router';
import { useAuthStore } from '../stores/auth';
import { useSmokeTestsAllowed } from '../composables/useSmokeTestsAllowed';
import { ensureStaffSession, isSessionFresh } from '../utils/session-hydrate';
import { hydrateStaffSession } from '../utils/session-hydrate';
import { reconcileStaffSessionFromToken } from '../stores/auth';
import { AdminPerm } from '../constants/permissions';
import { adminCanAccess, firstAdminFallback } from '../utils/admin-access';
@@ -192,13 +192,9 @@ router.beforeEach(async (to) => {
const hasToken = !!auth.token.value;
if (hasToken) {
if (isSessionFresh()) {
// Session 在 TTL 内且完整:只做同步 reconcile跳过网络请求
reconcileStaffSessionFromToken();
} else {
// Session 过期或不完整:才 await 远程刷新
await ensureStaffSession();
}
reconcileStaffSessionFromToken();
// 后台刷新 session不阻塞路由切换401 由 api 拦截器处理
void hydrateStaffSession();
}
const hasUser = !!auth.user.value?.userType;
@@ -247,9 +243,8 @@ router.beforeEach(async (to) => {
}
if (to.meta.smokeTestsOnly) {
const { ensureLoaded, allowed } = useSmokeTestsAllowed();
await ensureLoaded();
if (!allowed.value) return '/';
const { allowed } = useSmokeTestsAllowed();
if (allowed.value === false) return '/';
}
return true;