Defer admin form runtime loading

This commit is contained in:
2026-06-09 19:10:03 +08:00
parent 0cf20cc1ea
commit fbd726ebdf
6 changed files with 46 additions and 7 deletions
@@ -174,6 +174,8 @@ const withDefaultPlaceholder = <T extends Component>(
};
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
let initialized = false;
export type ComponentType =
| 'ApiSelect'
| 'ApiTreeSelect'
@@ -203,7 +205,11 @@ export type ComponentType =
| 'UserSelector'
| BaseFormComponentType;
async function initComponentAdapter() {
function initComponentAdapter() {
if (initialized) {
return;
}
const components: Partial<Record<ComponentType, Component>> = {
// 如果你的组件体积比较大,可以使用异步加载
// Button: () =>
@@ -349,6 +355,7 @@ async function initComponentAdapter() {
// 将组件注册到全局共享状态中
globalShareState.setComponents(components);
initialized = true;
// 定义全局共享状态中的消息提示
globalShareState.defineMessage({
+13 -1
View File
@@ -8,7 +8,16 @@ import type { ComponentType } from './component';
import { setupVbenForm, useVbenForm as useForm, z } from '@vben-core/form-ui';
import { $t } from '@vben/locales';
async function initSetupVbenForm() {
import { initComponentAdapter } from './component';
let initialized = false;
function initSetupVbenForm() {
if (initialized) {
return;
}
initComponentAdapter();
setupVbenForm<ComponentType>({
config: {
modelPropNameMap: {
@@ -31,8 +40,11 @@ async function initSetupVbenForm() {
},
},
});
initialized = true;
}
initSetupVbenForm();
const useVbenForm = useForm<ComponentType>;
export { initSetupVbenForm, useVbenForm, z };
+21
View File
@@ -0,0 +1,21 @@
import { globalShareState } from '@vben-core/shared/global-state';
function initMessageAdapter() {
globalShareState.defineMessage({
copyPreferencesSuccess: (title, content) => {
void import('element-plus/es/components/notification/index').then(
({ ElNotification }) => {
ElNotification({
title,
message: content,
position: 'bottom-right',
duration: 0,
type: 'success',
});
},
);
},
});
}
export { initMessageAdapter };