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.

62 lines
1.3 KiB

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