perf(admin): 优化管理端页面切换性能与包体积 (同步自 main)

- 阶段 A: 增加 KeepAlive 缓存高频列表页,改用 onActivated 进行后台静默刷新,优化 tab 切换与 HomeEntry 闪屏

- 阶段 B: beforeEach 守卫在 TTL 内走同步快速路径,api 请求拦截器缓存 token 避免重复解析 JWT

- 阶段 C: 引入 unplugin 插件启用 Element Plus 组件按需加载,清理 App.vue 中 960+ 行冗余暗色主题 CSS

- i18n 拆包: 将三语文案包提取为独立懒加载 chunks,主包体积从 209KB 减少至 99KB (降低 53%)
This commit is contained in:
2026-06-18 15:31:39 +08:00
parent ea695012cc
commit e1d33dde9a
26 changed files with 549 additions and 603 deletions

View File

@@ -1,7 +1,8 @@
import { createRouter, createWebHistory } from 'vue-router';
import { useAuthStore } from '../stores/auth';
import { useSmokeTestsAllowed } from '../composables/useSmokeTestsAllowed';
import { ensureStaffSession } from '../utils/session-hydrate';
import { ensureStaffSession, isSessionFresh } from '../utils/session-hydrate';
import { reconcileStaffSessionFromToken } from '../stores/auth';
import { AdminPerm } from '../constants/permissions';
import { adminCanAccess, firstAdminFallback } from '../utils/admin-access';
@@ -191,7 +192,13 @@ router.beforeEach(async (to) => {
const hasToken = !!auth.token.value;
if (hasToken) {
await ensureStaffSession();
if (isSessionFresh()) {
// Session 在 TTL 内且完整:只做同步 reconcile跳过网络请求
reconcileStaffSessionFromToken();
} else {
// Session 过期或不完整:才 await 远程刷新
await ensureStaffSession();
}
}
const hasUser = !!auth.user.value?.userType;