From 46248c174527d1ce940eb2fa91fd357ceabdb4cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?cls=5F=E5=AE=81=E6=B3=A2=E6=9C=AC=E6=9C=BA?= <908705107@qq.com> Date: Mon, 22 Jun 2026 07:13:05 +0800 Subject: [PATCH] perf: defer admin runtime from bootstrap --- web/apps/web-ele/src/bootstrap.ts | 19 ++--------------- web/apps/web-ele/src/router/guard.ts | 32 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/web/apps/web-ele/src/bootstrap.ts b/web/apps/web-ele/src/bootstrap.ts index 8268d50..2ea448f 100644 --- a/web/apps/web-ele/src/bootstrap.ts +++ b/web/apps/web-ele/src/bootstrap.ts @@ -8,28 +8,13 @@ import '@vben/styles'; import '@vben/styles/ele'; import { useTitle } from '@vueuse/core'; -import ElementPlus from 'element-plus'; - import { $t, setupI18n } from '#/locales'; -import { initComponentAdapter } from './adapter/component'; -import { initSetupVbenForm, useVbenForm } from './adapter/form'; import App from './app.vue'; -import { setupZqTable } from './components/zq-table'; +import { setupElementPlus } from './plugins/element-plus'; import { router } from './router'; async function bootstrap(namespace: string) { - // 初始化组件适配器 - await initComponentAdapter(); - - // 初始化表单组件 - await initSetupVbenForm(); - - // 初始化 ZqTable (注入 form) - setupZqTable({ - useVbenForm, - }); - // // 设置弹窗的默认配置 // setDefaultModalProps({ // fullscreenButton: false, @@ -40,7 +25,7 @@ async function bootstrap(namespace: string) { // }); const app = createApp(App); - app.use(ElementPlus); + setupElementPlus(app); // 注册Element Plus提供的v-loading指令 diff --git a/web/apps/web-ele/src/router/guard.ts b/web/apps/web-ele/src/router/guard.ts index 1bc000a..0925add 100644 --- a/web/apps/web-ele/src/router/guard.ts +++ b/web/apps/web-ele/src/router/guard.ts @@ -7,6 +7,7 @@ import { startProgress, stopProgress } from '@vben/utils'; import { loadBusinessMessages } from '#/locales'; import { accessRoutes, coreRouteNames } from '#/router/routes'; +import { ensureAdminRuntime } from '#/runtime/admin'; import { useAuthStore } from '#/store'; import { useAppContextStore } from '#/store/app-context'; import { normalizeHomePath } from '#/utils/legacy-home'; @@ -24,6 +25,31 @@ function filterLightTabHistory(history: T) { }; } +function isMainHomeRoute(path: string) { + return /\/page-render\/main_home$/.test(path); +} + +function shouldLoadAdminRuntime(path: string) { + if (isMainHomeRoute(path)) return false; + if (path === '/agent-chat/codex') return false; + if (path.startsWith('/auth/')) return false; + if (path.startsWith('/file-preview/')) return false; + return true; +} + +function warmAdminRuntimeAfterPaint() { + const run = () => { + void ensureAdminRuntime(); + }; + + if ('requestIdleCallback' in window) { + window.requestIdleCallback(run, { timeout: 2000 }); + return; + } + + window.setTimeout(run, 800); +} + /** * 通用守卫配置 * @param router @@ -114,6 +140,9 @@ function setupCommonGuard(router: Router) { if (useAccessStore().accessToken) { prefetchAiPlatformPages(to.path); + if (isMainHomeRoute(to.path)) { + warmAdminRuntimeAfterPaint(); + } } }); } @@ -163,6 +192,9 @@ function setupAccessGuard(router: Router) { // 是否已经生成过动态路由 if (accessStore.isAccessChecked) { + if (shouldLoadAdminRuntime(to.path)) { + await ensureAdminRuntime(); + } return true; }