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.

54 lines
1.1 KiB

3 years ago
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. const permissionRouter = {
  4. path: "/permission",
  5. meta: {
  6. title: "menus.permission",
  7. icon: "lollipop",
  8. rank: 7
  9. },
  10. children: [
  11. {
  12. path: "/permission/page/index",
  13. name: "PermissionPage",
  14. meta: {
  15. title: "menus.permissionPage"
  16. }
  17. },
  18. {
  19. path: "/permission/button/index",
  20. name: "PermissionButton",
  21. meta: {
  22. title: "menus.permissionButton",
  23. authority: []
  24. }
  25. }
  26. ]
  27. };
  28. // 添加不同按钮权限到/permission/button页面中
  29. function setDifAuthority(authority, routes) {
  30. routes.children[1].meta.authority = [authority];
  31. return routes;
  32. }
  33. export default [
  34. {
  35. url: "/getAsyncRoutes",
  36. method: "get",
  37. response: ({ query }) => {
  38. if (query.name === "admin") {
  39. return {
  40. code: 0,
  41. info: [setDifAuthority("v-admin", permissionRouter)]
  42. };
  43. } else {
  44. return {
  45. code: 0,
  46. info: [setDifAuthority("v-test", permissionRouter)]
  47. };
  48. }
  49. }
  50. }
  51. ] as MockMethod[];