支持npm 安装的@great-dream插件动态菜单
This commit is contained in:
@@ -21,13 +21,14 @@ const menuApi = useMenuApi();
|
|||||||
|
|
||||||
const layouModules: any = import.meta.glob('../layout/routerView/*.{vue,tsx}');
|
const layouModules: any = import.meta.glob('../layout/routerView/*.{vue,tsx}');
|
||||||
const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}');
|
const viewsModules: any = import.meta.glob('../views/**/*.{vue,tsx}');
|
||||||
|
const greatDream: any = import.meta.glob('@great-dream/**/*.{vue,tsx}');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取目录下的 .vue、.tsx 全部文件
|
* 获取目录下的 .vue、.tsx 全部文件
|
||||||
* @method import.meta.glob
|
* @method import.meta.glob
|
||||||
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
* @link 参考:https://cn.vitejs.dev/guide/features.html#json
|
||||||
*/
|
*/
|
||||||
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...layouModules }, { ...viewsModules });
|
const dynamicViewsModules: Record<string, Function> = Object.assign({}, { ...layouModules }, { ...viewsModules }, { ...greatDream });
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 后端控制路由:初始化方法,防止刷新时路由丢失
|
* 后端控制路由:初始化方法,防止刷新时路由丢失
|
||||||
@@ -198,7 +199,9 @@ export function dynamicImport(dynamicViewsModules: Record<string, Function>, com
|
|||||||
const keys = Object.keys(dynamicViewsModules);
|
const keys = Object.keys(dynamicViewsModules);
|
||||||
const matchKeys = keys.filter((key) => {
|
const matchKeys = keys.filter((key) => {
|
||||||
const k = key.replace(/..\/views|../, '');
|
const k = key.replace(/..\/views|../, '');
|
||||||
return k.startsWith(`${component}`) || k.startsWith(`/${component}`);
|
const k1 = k.replace("ode_modules/@great-dream/", '')
|
||||||
|
const newComponent = component.replace("plugins/", "")
|
||||||
|
return k1.startsWith(`${newComponent}`) || k1.startsWith(`/${newComponent}`);
|
||||||
});
|
});
|
||||||
if (matchKeys?.length === 1) {
|
if (matchKeys?.length === 1) {
|
||||||
const matchKey = matchKeys[0];
|
const matchKey = matchKeys[0];
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { defineAsyncComponent, AsyncComponentLoader } from 'vue';
|
|||||||
export let pluginsAll: any = [];
|
export let pluginsAll: any = [];
|
||||||
// 扫描插件目录并注册插件
|
// 扫描插件目录并注册插件
|
||||||
export const scanAndInstallPlugins = (app: any) => {
|
export const scanAndInstallPlugins = (app: any) => {
|
||||||
const components = import.meta.glob('./**/*.vue');
|
const components = import.meta.glob('./**/*.ts');
|
||||||
const pluginNames = new Set();
|
const pluginNames = new Set();
|
||||||
// 遍历对象并注册异步组件
|
// 遍历对象并注册异步组件
|
||||||
for (const [key, value] of Object.entries(components)) {
|
for (const [key, value] of Object.entries(components)) {
|
||||||
@@ -11,6 +11,15 @@ export const scanAndInstallPlugins = (app: any) => {
|
|||||||
const pluginsName = key.match(/\/([^\/]*)\//)?.[1];
|
const pluginsName = key.match(/\/([^\/]*)\//)?.[1];
|
||||||
pluginNames.add(pluginsName);
|
pluginNames.add(pluginsName);
|
||||||
}
|
}
|
||||||
|
const dreamComponents = import.meta.glob('/node_modules/@great-dream/**/*.ts');
|
||||||
|
// 遍历对象并注册异步组件
|
||||||
|
for (let [key, value] of Object.entries(dreamComponents)) {
|
||||||
|
key = key.replace('node_modules/@great-dream/', '');
|
||||||
|
const name = key.slice(key.lastIndexOf('/') + 1, key.lastIndexOf('.'));
|
||||||
|
app.component(name, defineAsyncComponent(value as AsyncComponentLoader));
|
||||||
|
const pluginsName = key.match(/\/([^\/]*)\//)?.[1];
|
||||||
|
pluginNames.add(pluginsName);
|
||||||
|
}
|
||||||
pluginsAll = Array.from(pluginNames);
|
pluginsAll = Array.from(pluginNames);
|
||||||
console.log('已发现插件:', pluginsAll);
|
console.log('已发现插件:', pluginsAll);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const pathResolve = (dir: string) => {
|
|||||||
|
|
||||||
const alias: Record<string, string> = {
|
const alias: Record<string, string> = {
|
||||||
'/@': pathResolve('./src/'),
|
'/@': pathResolve('./src/'),
|
||||||
|
'@great-dream': pathResolve('./node_modules/@great-dream/'),
|
||||||
'@views': pathResolve('./src/views'),
|
'@views': pathResolve('./src/views'),
|
||||||
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js',
|
||||||
'@dvaformflow':pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/')
|
'@dvaformflow':pathResolve('./src/viwes/plugins/dvaadmin_form_flow/src/')
|
||||||
|
|||||||
Reference in New Issue
Block a user