2021-10-16 16:16:58 +08:00
|
|
|
// 根据角色动态生成路由
|
|
|
|
import { MockMethod } from "vite-plugin-mock";
|
|
|
|
|
|
|
|
const permissionRouter = {
|
|
|
|
path: "/permission",
|
|
|
|
meta: {
|
2022-01-05 14:17:06 +08:00
|
|
|
title: "menus.permission",
|
2022-01-21 11:32:58 +08:00
|
|
|
icon: "lollipop",
|
2022-03-14 14:49:02 +08:00
|
|
|
rank: 7
|
2021-10-16 16:16:58 +08:00
|
|
|
},
|
|
|
|
children: [
|
|
|
|
{
|
2022-01-05 14:17:06 +08:00
|
|
|
path: "/permission/page/index",
|
2022-08-22 21:34:55 +08:00
|
|
|
name: "PermissionPage",
|
2021-10-16 16:16:58 +08:00
|
|
|
meta: {
|
2022-05-11 16:43:56 +08:00
|
|
|
title: "menus.permissionPage"
|
2021-10-16 16:16:58 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
2022-01-05 14:17:06 +08:00
|
|
|
path: "/permission/button/index",
|
2022-08-22 21:34:55 +08:00
|
|
|
name: "PermissionButton",
|
2021-10-16 16:16:58 +08:00
|
|
|
meta: {
|
2022-01-05 14:17:06 +08:00
|
|
|
title: "menus.permissionButton",
|
2021-10-16 16:16:58 +08:00
|
|
|
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,
|
2021-10-16 21:17:18 +08:00
|
|
|
info: [setDifAuthority("v-admin", permissionRouter)]
|
2021-10-16 16:16:58 +08:00
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return {
|
|
|
|
code: 0,
|
|
|
|
info: [setDifAuthority("v-test", permissionRouter)]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
] as MockMethod[];
|