Defer admin form runtime
This commit is contained in:
@@ -11,25 +11,11 @@ import { useTitle } from '@vueuse/core';
|
|||||||
import { $t, setupI18n } from '#/locales';
|
import { $t, setupI18n } from '#/locales';
|
||||||
import { useAppContextStore } from '#/store/app-context';
|
import { useAppContextStore } from '#/store/app-context';
|
||||||
|
|
||||||
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/init';
|
|
||||||
import { setupElementPlus } from './plugins/element-plus';
|
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,
|
||||||
|
|||||||
@@ -170,6 +170,9 @@ function setupAccessGuard(router: Router) {
|
|||||||
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
|
||||||
const userRoles = userInfo.roles ?? [];
|
const userRoles = userInfo.roles ?? [];
|
||||||
|
|
||||||
|
const { ensureAdminRuntime } = await import('#/runtime/admin');
|
||||||
|
await ensureAdminRuntime();
|
||||||
|
|
||||||
// 生成菜单和路由
|
// 生成菜单和路由
|
||||||
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
const { accessibleMenus, accessibleRoutes } = await generateAccess({
|
||||||
roles: userRoles,
|
roles: userRoles,
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
let initialized = false;
|
||||||
|
let initializing: Promise<void> | null = null;
|
||||||
|
|
||||||
|
async function setupAdminRuntime() {
|
||||||
|
const [{ initComponentAdapter }, formModule, { setupZqTable }] =
|
||||||
|
await Promise.all([
|
||||||
|
import('#/adapter/component'),
|
||||||
|
import('#/adapter/form'),
|
||||||
|
import('#/components/zq-table/init'),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await initComponentAdapter();
|
||||||
|
await formModule.initSetupVbenForm();
|
||||||
|
setupZqTable({
|
||||||
|
useVbenForm: formModule.useVbenForm,
|
||||||
|
});
|
||||||
|
|
||||||
|
initialized = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function ensureAdminRuntime() {
|
||||||
|
if (initialized) return;
|
||||||
|
|
||||||
|
initializing ??= setupAdminRuntime().finally(() => {
|
||||||
|
initializing = null;
|
||||||
|
});
|
||||||
|
|
||||||
|
await initializing;
|
||||||
|
}
|
||||||
|
|
||||||
|
export { ensureAdminRuntime };
|
||||||
Reference in New Issue
Block a user