Skip to content

Commit 3d57937

Browse files
committed
修复因@jeecg/online库按需加载,导致高级查询组件不好使
1 parent 4468ec2 commit 3d57937

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

jeecgboot-vue3/src/utils/monorepo/registerPackages.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { App } from 'vue';
22
import { warn } from '/@/utils/log';
33
import { registerDynamicRouter } from '/@/utils/monorepo/dynamicRouter';
4-
import { add } from '/@/components/Form/src/componentMap';
4+
import { createAsyncComponent } from "@/utils/factory/createAsyncComponent";
55

66
// 懒加载模块配置(按需加载,访问相关路由时才加载对应包)
77
const lazyPackages = [
@@ -19,6 +19,33 @@ const installOptions = {
1919
export function registerPackages(app: App) {
2020
// 仅保存 app 实例,不立即加载模块
2121
appInstance = app;
22+
app.component(
23+
'superQuery',
24+
createAsyncComponent(() => {
25+
return import('@jeecg/online').then(mod => {
26+
const str = mod.default.install.toString();
27+
const importPaths = extractDynamicImportPaths(str);
28+
return import(importPaths.find(path => path.includes('SuperQuery')) ?? importPaths[1])
29+
});
30+
})
31+
);
32+
app.component(
33+
'JOnlineSearchSelect',
34+
createAsyncComponent(() => {
35+
return import('@jeecg/online').then(mod => {
36+
const str = mod.default.install.toString();
37+
const importPaths = extractDynamicImportPaths(str);
38+
debugger
39+
return import(importPaths.find(path => path.includes('JOnlineSearchSelect')) ?? importPaths[0])
40+
});
41+
})
42+
);
43+
}
44+
45+
function extractDynamicImportPaths(code: string): string[] {
46+
// 匹配 import("...") / import('...'),保留括号内路径(包含 query 参数)
47+
const matches = code.matchAll(/import\(\s*(['"])(.*?)\1\s*\)/g);
48+
return Array.from(matches, (m) => m[2]).filter(Boolean);
2249
}
2350

2451
/** 已加载的包缓存 */

0 commit comments

Comments
 (0)