You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.2 KiB
59 lines
1.2 KiB
// 根据角色动态生成路由
|
|
import { MockMethod } from "vite-plugin-mock";
|
|
|
|
const permissionRouter = {
|
|
path: "/permission",
|
|
name: "permission",
|
|
redirect: "/permission/page/index",
|
|
meta: {
|
|
title: "menus.permission",
|
|
icon: "lollipop",
|
|
i18n: true,
|
|
rank: 3
|
|
},
|
|
children: [
|
|
{
|
|
path: "/permission/page/index",
|
|
name: "permissionPage",
|
|
meta: {
|
|
title: "menus.permissionPage",
|
|
i18n: true
|
|
}
|
|
},
|
|
{
|
|
path: "/permission/button/index",
|
|
name: "permissionButton",
|
|
meta: {
|
|
title: "menus.permissionButton",
|
|
i18n: true,
|
|
authority: []
|
|
}
|
|
}
|
|
]
|
|
};
|
|
|
|
// 添加不同按钮权限到/permission/button页面中
|
|
function setDifAuthority(authority, routes) {
|
|
routes.children[1].meta.authority = [authority];
|
|
return routes;
|
|
}
|
|
|
|
export default [
|
|
{
|
|
url: "/getAsyncRoutes",
|
|
method: "get",
|
|
response: ({ query }) => {
|
|
if (query.name === "admin") {
|
|
return {
|
|
code: 0,
|
|
info: [setDifAuthority("v-admin", permissionRouter)]
|
|
};
|
|
} else {
|
|
return {
|
|
code: 0,
|
|
info: [setDifAuthority("v-test", permissionRouter)]
|
|
};
|
|
}
|
|
}
|
|
}
|
|
] as MockMethod[];
|