mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-16 19:22:27 +08:00
fix Bug or esLink formatting
This commit is contained in:
@@ -1,75 +1,80 @@
|
||||
import { h } from 'vue';
|
||||
import type { App, Plugin } from 'vue';
|
||||
import { NIcon } from 'naive-ui'
|
||||
import { PageEnum } from "@/enums/pageEnum";
|
||||
import { NIcon } from 'naive-ui';
|
||||
import { PageEnum } from '@/enums/pageEnum';
|
||||
|
||||
/**
|
||||
* render 图标
|
||||
* */
|
||||
export function renderIcon(icon) {
|
||||
return () => h(NIcon, null, { default: () => h(icon) })
|
||||
return () => h(NIcon, null, { default: () => h(icon) });
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归组装菜单格式
|
||||
*/
|
||||
export function generatorMenu(routerMap: Array<any>) {
|
||||
return routerMap.filter(item => {
|
||||
return item.meta.hidden != true && !['/:path(.*)*', '/', PageEnum.REDIRECT, PageEnum.BASE_LOGIN].includes(item.path)
|
||||
}).map(item => {
|
||||
const currentMenu = {
|
||||
...item,
|
||||
...item.meta,
|
||||
label: item.meta.title,
|
||||
key: item.name
|
||||
}
|
||||
// 是否有子菜单,并递归处理
|
||||
if (item.children && item.children.length > 0) {
|
||||
// Recursion
|
||||
currentMenu.children = generatorMenu(item.children)
|
||||
}
|
||||
return currentMenu
|
||||
return routerMap
|
||||
.filter((item) => {
|
||||
return (
|
||||
item.meta.hidden != true &&
|
||||
!['/:path(.*)*', '/', PageEnum.REDIRECT, PageEnum.BASE_LOGIN].includes(item.path)
|
||||
);
|
||||
})
|
||||
.map((item) => {
|
||||
const currentMenu = {
|
||||
...item,
|
||||
...item.meta,
|
||||
label: item.meta.title,
|
||||
key: item.name,
|
||||
};
|
||||
// 是否有子菜单,并递归处理
|
||||
if (item.children && item.children.length > 0) {
|
||||
// Recursion
|
||||
currentMenu.children = generatorMenu(item.children);
|
||||
}
|
||||
return currentMenu;
|
||||
});
|
||||
}
|
||||
|
||||
export const withInstall = <T>(component: T, alias?: string) => {
|
||||
const comp = component as any;
|
||||
comp.install = (app: App) => {
|
||||
app.component(comp.name || comp.displayName, component);
|
||||
if (alias) {
|
||||
app.config.globalProperties[alias] = component;
|
||||
}
|
||||
};
|
||||
return component as T & Plugin;
|
||||
const comp = component as any;
|
||||
comp.install = (app: App) => {
|
||||
app.component(comp.name || comp.displayName, component);
|
||||
if (alias) {
|
||||
app.config.globalProperties[alias] = component;
|
||||
}
|
||||
};
|
||||
return component as T & Plugin;
|
||||
};
|
||||
|
||||
/**
|
||||
* 找到对应的节点
|
||||
* */
|
||||
let result = null
|
||||
export function getTreeItem(data: any[], key?: string | number) {
|
||||
data.map(item => {
|
||||
if (item.key === key) {
|
||||
result = item;
|
||||
} else {
|
||||
if (item.children && item.children.length) {
|
||||
getTreeItem(item.children, key);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result
|
||||
let result = null;
|
||||
export function getTreeItem(data: any[], key?: string | number): any {
|
||||
data.map((item) => {
|
||||
if (item.key === key) {
|
||||
result = item;
|
||||
} else {
|
||||
if (item.children && item.children.length) {
|
||||
getTreeItem(item.children, key);
|
||||
}
|
||||
}
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 找到所有节点
|
||||
* */
|
||||
let treeAll = []
|
||||
export function getTreeAll(data: any[]) {
|
||||
data.map(item => {
|
||||
treeAll.push(item.key)
|
||||
if (item.children && item.children.length) {
|
||||
getTreeAll(item.children);
|
||||
}
|
||||
});
|
||||
return treeAll
|
||||
const treeAll: any[] = [];
|
||||
export function getTreeAll(data: any[]): any[] {
|
||||
data.map((item) => {
|
||||
treeAll.push(item.key);
|
||||
if (item.children && item.children.length) {
|
||||
getTreeAll(item.children);
|
||||
}
|
||||
});
|
||||
return treeAll;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user