wireguard-dashboard-admin/mock/asyncRoutes.ts

63 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-10-16 16:16:58 +08:00
// 根据角色动态生成路由
import { MockMethod } from "vite-plugin-mock";
const permissionRouter = {
path: "/permission",
name: "permission",
2022-01-05 14:17:06 +08:00
redirect: "/permission/page/index",
2021-10-16 16:16:58 +08:00
meta: {
2022-01-05 14:17:06 +08:00
title: "menus.permission",
icon: "Lollipop",
2021-11-16 22:17:57 +08:00
i18n: true,
2021-10-16 16:16:58 +08:00
showLink: true,
rank: 3
},
children: [
{
2022-01-05 14:17:06 +08:00
path: "/permission/page/index",
2021-10-16 16:16:58 +08:00
name: "permissionPage",
meta: {
2022-01-05 14:17:06 +08:00
title: "menus.permissionPage",
2021-11-16 22:17:57 +08:00
i18n: true,
2021-10-16 16:16:58 +08:00
showLink: true
}
},
{
2022-01-05 14:17:06 +08:00
path: "/permission/button/index",
2021-10-16 16:16:58 +08:00
name: "permissionButton",
meta: {
2022-01-05 14:17:06 +08:00
title: "menus.permissionButton",
2021-11-16 22:17:57 +08:00
i18n: true,
2021-10-16 16:16:58 +08:00
showLink: 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,
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[];