jinhui.wang

菜单屏蔽

......@@ -149,11 +149,10 @@ function setRoute(route, childrens) {
route.forEach((val) => {
val.id == 999999 ? (rootRoute = val) : "";
if (item.parentId == val.id) {
item.component = `${
titleCase(val.name, "low") != ""
? "/" + titleCase(val.name, "low")
: ""
}${item.component}`;
item.component = `${titleCase(val.name, "low") != ""
? "/" + titleCase(val.name, "low")
: ""
}${item.component}`;
val.children.push(item);
val.component = "Layout";
// val.meta = item.meta
......@@ -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,53 +206,34 @@ 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 || "" },
}))
: [
{
path: item.path,
component: `${item.path}`,
hidden: false,
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;
: [
{
path: item.path,
component: `${item.path}`,
hidden: false,
name: item.name,
meta: { title: item.name, icon: item.icon || "" },
},
],
};
routes.push(route);
}
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);
......