jinhui.wang

菜单屏蔽

......@@ -149,8 +149,7 @@ function setRoute(route, childrens) {
route.forEach((val) => {
val.id == 999999 ? (rootRoute = val) : "";
if (item.parentId == val.id) {
item.component = `${
titleCase(val.name, "low") != ""
item.component = `${titleCase(val.name, "low") != ""
? "/" + titleCase(val.name, "low")
: ""
}${item.component}`;
......@@ -169,10 +168,6 @@ function setRoute(route, childrens) {
return route;
}
function isValidMenuPath(p) {
return p != null && String(p).trim() !== "";
}
function routeItemInfo(data) {
const routes = [
{
......@@ -211,25 +206,19 @@ function routeItemInfo(data) {
];
data.forEach((item) => {
const rawChildren = item.children || [];
const isParent = item.parentId == 0 && rawChildren.length == 0;
if (!isValidMenuPath(item.path)) {
console.warn("[permission] skip menu item without path:", item);
return;
}
const childRoutes = !isParent
? rawChildren
.filter((child) => {
if (!isValidMenuPath(child.path)) {
console.warn("[permission] skip child menu without path:", child);
return false;
}
return true;
})
.map((child) => ({
if (item.nodeType == '1') {
const isParent = item.parentId == 0 && item.children.length == 0;
const route = {
path: item.path,
component: "Layout",
alwaysShow: true,
hidden: false,
meta: { title: item.name, icon: item.icon },
children: !isParent
? item.children.map((child) => ({
path: child.path,
component: `${child.path}`,
hidden: false,
hidden: child.nodeType == '1' ? false : true,
name: child.name,
meta: { title: child.name, icon: child.icon || "" },
}))
......@@ -241,23 +230,10 @@ function routeItemInfo(data) {
name: item.name,
meta: { title: item.name, icon: item.icon || "" },
},
];
if (!isParent && childRoutes.length === 0) {
console.warn(
"[permission] skip menu with no valid child paths:",
item.path
);
return;
}
const route = {
path: item.path,
component: "Layout",
alwaysShow: true,
hidden: false,
meta: { title: item.name, icon: item.icon },
children: childRoutes,
],
};
routes.push(route);
}
});
console.log(routes);
......