Fixes bug 新增 顶部混合菜单

This commit is contained in:
Ah jung
2021-08-06 17:06:33 +08:00
parent 450234e7ea
commit 3e0b8efe7e
19 changed files with 432 additions and 63 deletions

View File

@@ -3,7 +3,7 @@ const getCss = function (o, key) {
// @ts-ignore
return o.currentStyle
? o.currentStyle[key]
: document.defaultView.getComputedStyle(o, false)[key];
: document.defaultView?.getComputedStyle(o, null)[key];
};
const params = {

View File

@@ -3,7 +3,7 @@ import type { App, Plugin } from 'vue';
import { NIcon, NTag } from 'naive-ui';
import { PageEnum } from '@/enums/pageEnum';
import { isObject } from './is/index';
import { cloneDeep } from 'lodash-es';
/**
* render 图标
* */
@@ -33,29 +33,89 @@ export function renderNew(type = 'warning', text = 'New', color: object = newTag
* 递归组装菜单格式
*/
export function generatorMenu(routerMap: Array<any>) {
return routerMap
.filter((item) => {
return (
(item.meta?.hidden || false) != true &&
!['/:path(.*)*', '/', PageEnum.REDIRECT, PageEnum.BASE_LOGIN].includes(item.path)
);
})
.map((item) => {
const info =
item.meta?.alwaysShow != true && item.children?.length === 1 ? item.children[0] : item;
return filterRouter(routerMap).map((item) => {
const isRoot = isRootRouter(item);
const info = isRoot ? item.children[0] : item;
const currentMenu = {
...info,
...info.meta,
label: info.meta?.title,
key: info.name,
};
// 是否有子菜单,并递归处理
if (info.children && info.children.length > 0) {
// Recursion
currentMenu.children = generatorMenu(info.children);
}
return currentMenu;
});
}
/**
* 混合菜单
* */
export function generatorMenuMix(routerMap: Array<any>, routerName: string, location: string) {
const cloneRouterMap = cloneDeep(routerMap);
const newRouter = filterRouter(cloneRouterMap);
if (location === 'header') {
const firstRouter: any[] = [];
newRouter.forEach((item) => {
const isRoot = isRootRouter(item);
const info = isRoot ? item.children[0] : item;
info.children = undefined;
const currentMenu = {
...info,
...info.meta,
label: info.meta?.title,
key: info.name,
};
// 是否有子菜单,并递归处理
if (info.children && info.children.length > 0) {
// Recursion
currentMenu.children = generatorMenu(info.children);
}
return currentMenu;
firstRouter.push(currentMenu);
});
return firstRouter;
} else {
return getChildrenRouter(newRouter.filter((item) => item.name === routerName));
}
}
/**
* 递归组装子菜单
* */
export function getChildrenRouter(routerMap: Array<any>) {
return routerMap.map((item) => {
const isRoot = isRootRouter(item);
const info = isRoot ? item.children[0] : item;
const currentMenu = {
...info,
...info.meta,
label: info.meta?.title,
key: info.name,
};
// 是否有子菜单,并递归处理
if (info.children && info.children.length > 0) {
// Recursion
currentMenu.children = getChildrenRouter(info.children);
}
return currentMenu;
});
}
/**
* 判断根路由 Router
* */
export function isRootRouter(item) {
return item.meta?.alwaysShow != true && item.children?.length === 1;
}
/**
* 排除Router
* */
export function filterRouter(routerMap: Array<any>) {
return routerMap.filter((item) => {
return (
(item.meta?.hidden || false) != true &&
!['/:path(.*)*', '/', PageEnum.REDIRECT, PageEnum.BASE_LOGIN].includes(item.path)
);
});
}
export const withInstall = <T>(component: T, alias?: string) => {