Files
JeecgBoot/jeecgboot-vue3/src/utils/monorepo/registerPackages.ts
2025-04-07 23:23:52 +08:00

50 lines
1.3 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { App } from 'vue';
import { warn } from '/@/utils/log';
import { registerDynamicRouter } from '/@/utils/monorepo/dynamicRouter';
// 引入模块
import PACKAGE_JEECG_ONLINE from '@jeecg/online';
import PACKAGE_JEECG_AIFLOW from '@jeecg/aiflow';
export function registerPackages(app: App) {
use(app, PACKAGE_JEECG_ONLINE);
use(app, PACKAGE_JEECG_AIFLOW);
}
// noinspection JSUnusedGlobalSymbols
const installOptions = {
baseImport,
};
/** 注册模块 */
function use(app: App, pkg) {
app.use(pkg, installOptions);
registerDynamicRouter(pkg.getViews);
}
// 模块里可使用的import
const importGlobs = [import.meta.glob('../../utils/**/*.{ts,js,tsx}'), import.meta.glob('../../hooks/**/*.{ts,js,tsx}')];
/**
* 基础项目导包
* 目前支持导入如下
* /@/utils/**
* /@/hooks/**
*
* @param path 文件路径ts无需输入后缀名。如/@/utils/common/compUtils
*/
async function baseImport(path: string) {
if (path) {
// 将 /@/ 替换成 ../../
path = path.replace(/^\/@\//, '../../');
for (const glob of importGlobs) {
for (const key of Object.keys(glob)) {
if (path === key || `${path}.ts` === key || `${path}.tsx` === key) {
return glob[key]();
}
}
}
warn(`引入失败:${path} 不存在`);
}
return null;
}