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.

90 lines
1.8 KiB

  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const systemRouter = {
  5. path: "/system",
  6. name: "system",
  7. redirect: "/system/user",
  8. meta: {
  9. icon: "el-icon-setting",
  10. title: "message.hssysManagement",
  11. showLink: true,
  12. rank: 6
  13. },
  14. children: [
  15. {
  16. path: "/system/user",
  17. name: "user",
  18. meta: {
  19. title: "message.hsBaseinfo",
  20. showLink: true
  21. }
  22. },
  23. {
  24. path: "/system/dict",
  25. name: "dict",
  26. meta: {
  27. title: "message.hsDict",
  28. showLink: true
  29. }
  30. }
  31. ]
  32. };
  33. const permissionRouter = {
  34. path: "/permission",
  35. name: "permission",
  36. redirect: "/permission/page",
  37. meta: {
  38. title: "message.permission",
  39. icon: "el-icon-lollipop",
  40. showLink: true,
  41. rank: 3
  42. },
  43. children: [
  44. {
  45. path: "/permission/page",
  46. name: "permissionPage",
  47. meta: {
  48. title: "message.permissionPage",
  49. showLink: true
  50. }
  51. },
  52. {
  53. path: "/permission/button",
  54. name: "permissionButton",
  55. meta: {
  56. title: "message.permissionButton",
  57. showLink: true,
  58. authority: []
  59. }
  60. }
  61. ]
  62. };
  63. // 添加不同按钮权限到/permission/button页面中
  64. function setDifAuthority(authority, routes) {
  65. routes.children[1].meta.authority = [authority];
  66. return routes;
  67. }
  68. export default [
  69. {
  70. url: "/getAsyncRoutes",
  71. method: "get",
  72. response: ({ query }) => {
  73. if (query.name === "admin") {
  74. return {
  75. code: 0,
  76. info: [systemRouter, setDifAuthority("v-admin", permissionRouter)]
  77. };
  78. } else {
  79. return {
  80. code: 0,
  81. info: [setDifAuthority("v-test", permissionRouter)]
  82. };
  83. }
  84. }
  85. }
  86. ] as MockMethod[];