perf: defer admin runtime from bootstrap
This commit is contained in:
@@ -8,28 +8,13 @@ import '@vben/styles';
|
|||||||
import '@vben/styles/ele';
|
import '@vben/styles/ele';
|
||||||
|
|
||||||
import { useTitle } from '@vueuse/core';
|
import { useTitle } from '@vueuse/core';
|
||||||
import ElementPlus from 'element-plus';
|
|
||||||
|
|
||||||
import { $t, setupI18n } from '#/locales';
|
import { $t, setupI18n } from '#/locales';
|
||||||
|
|
||||||
import { initComponentAdapter } from './adapter/component';
|
|
||||||
import { initSetupVbenForm, useVbenForm } from './adapter/form';
|
|
||||||
import App from './app.vue';
|
import App from './app.vue';
|
||||||
import { setupZqTable } from './components/zq-table';
|
import { setupElementPlus } from './plugins/element-plus';
|
||||||
import { router } from './router';
|
import { router } from './router';
|
||||||
|
|
||||||
async function bootstrap(namespace: string) {
|
async function bootstrap(namespace: string) {
|
||||||
// 初始化组件适配器
|
|
||||||
await initComponentAdapter();
|
|
||||||
|
|
||||||
// 初始化表单组件
|
|
||||||
await initSetupVbenForm();
|
|
||||||
|
|
||||||
// 初始化 ZqTable (注入 form)
|
|
||||||
setupZqTable({
|
|
||||||
useVbenForm,
|
|
||||||
});
|
|
||||||
|
|
||||||
// // 设置弹窗的默认配置
|
// // 设置弹窗的默认配置
|
||||||
// setDefaultModalProps({
|
// setDefaultModalProps({
|
||||||
// fullscreenButton: false,
|
// fullscreenButton: false,
|
||||||
@@ -40,7 +25,7 @@ async function bootstrap(namespace: string) {
|
|||||||
// });
|
// });
|
||||||
const app = createApp(App);
|
const app = createApp(App);
|
||||||
|
|
||||||
app.use(ElementPlus);
|
setupElementPlus(app);
|
||||||
|
|
||||||
// 注册Element Plus提供的v-loading指令
|
// 注册Element Plus提供的v-loading指令
|
||||||
|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import { startProgress, stopProgress } from '@vben/utils';
|
|||||||
|
|
||||||
import { loadBusinessMessages } from '#/locales';
|
import { loadBusinessMessages } from '#/locales';
|
||||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||||
|
import { ensureAdminRuntime } from '#/runtime/admin';
|
||||||
import { useAuthStore } from '#/store';
|
import { useAuthStore } from '#/store';
|
||||||
import { useAppContextStore } from '#/store/app-context';
|
import { useAppContextStore } from '#/store/app-context';
|
||||||
import { normalizeHomePath } from '#/utils/legacy-home';
|
import { normalizeHomePath } from '#/utils/legacy-home';
|
||||||
@@ -24,6 +25,31 @@ function filterLightTabHistory<T extends { tabs?: unknown[] }>(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
|
* @param router
|
||||||
@@ -114,6 +140,9 @@ function setupCommonGuard(router: Router) {
|
|||||||
|
|
||||||
if (useAccessStore().accessToken) {
|
if (useAccessStore().accessToken) {
|
||||||
prefetchAiPlatformPages(to.path);
|
prefetchAiPlatformPages(to.path);
|
||||||
|
if (isMainHomeRoute(to.path)) {
|
||||||
|
warmAdminRuntimeAfterPaint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -163,6 +192,9 @@ function setupAccessGuard(router: Router) {
|
|||||||
|
|
||||||
// 是否已经生成过动态路由
|
// 是否已经生成过动态路由
|
||||||
if (accessStore.isAccessChecked) {
|
if (accessStore.isAccessChecked) {
|
||||||
|
if (shouldLoadAdminRuntime(to.path)) {
|
||||||
|
await ensureAdminRuntime();
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user