权限列表
const menuList = [
{
title: "首页",
key: "/home",
icon: "home",
isPublic: true,
},
{
title: "商品",
key: "/products",
icon: "appstore",
children: [
{
title: "品类管理",
key: "/category",
icon: "bars",
},
{
title: "商品管理",
key: "/product",
icon: "tool",
},
],
},
{
title: "用户管理",
key: "/user",
icon: "user",
},
{
title: "角色管理",
key: "/role",
icon: "safety",
},
{
title: "图形图表",
key: "/charts",
icon: "area-chart",
children: [
{
title: "柱形图",
key: "/charts/bar",
icon: "bar-chart",
},
{
title: "折线图",
key: "/charts/line",
icon: "line-chart",
},
{
title: "饼图",
key: "/charts/pie",
icon: "pie-chart",
},
],
},
{
title: "订单管理",
key: "/order",
icon: "windows",
},
];
export default menuList;
递归遍历权限例表
const getMenunodes = (menuList) => {
return menuList.map((item) => {
if (!item.children) {
return (
<Menu.Item key={item.key}>
<Link to={item.key}>
<Icon type={item.icon} />
<span>{item.title}</span>
</Link>
</Menu.Item>
);
} else {
return (
<SubMenu
key={item.key}
title={
<span>
<Icon type={item.type} />
<span>{item.title}</span>
</span>
}
>
{getMenunodes(item.children)}
</SubMenu>
);
}
});
};
左边菜单栏,高亮显示
const { pathname } = useLocation();
console.log(pathname);
return (
<div>
<Menu
defaultSelectedKeys={[pathname]}
defaultOpenKeys={["sub1"]}
mode="inline"
theme="dark"
>
{getMenunodes(menuList)}
</Menu>
</div>
);
}