asyncRoutes.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/index",
  8. meta: {
  9. icon: "setting",
  10. title: "menus.hssysManagement",
  11. i18n: true,
  12. rank: 6
  13. },
  14. children: [
  15. {
  16. path: "/system/user/index",
  17. name: "user",
  18. meta: {
  19. title: "menus.hsBaseinfo",
  20. i18n: true
  21. }
  22. },
  23. {
  24. path: "/system/dict/index",
  25. name: "dict",
  26. meta: {
  27. title: "menus.hsDict",
  28. i18n: true,
  29. keepAlive: true
  30. }
  31. }
  32. ]
  33. };
  34. const permissionRouter = {
  35. path: "/permission",
  36. name: "permission",
  37. redirect: "/permission/page/index",
  38. meta: {
  39. title: "menus.permission",
  40. icon: "lollipop",
  41. i18n: true,
  42. rank: 3
  43. },
  44. children: [
  45. {
  46. path: "/permission/page/index",
  47. name: "permissionPage",
  48. meta: {
  49. title: "menus.permissionPage",
  50. i18n: true
  51. }
  52. },
  53. {
  54. path: "/permission/button/index",
  55. name: "permissionButton",
  56. meta: {
  57. title: "menus.permissionButton",
  58. i18n: true,
  59. authority: []
  60. }
  61. }
  62. ]
  63. };
  64. const tabsRouter = {
  65. path: "/tabs",
  66. name: "reTabs",
  67. redirect: "/tabs/index",
  68. meta: {
  69. icon: "IF-team-icontabs",
  70. title: "menus.hstabs",
  71. i18n: true,
  72. rank: 8
  73. },
  74. children: [
  75. {
  76. path: "/tabs/index",
  77. name: "reTabs",
  78. meta: {
  79. title: "menus.hstabs",
  80. i18n: true
  81. }
  82. },
  83. {
  84. path: "/tabs/detail",
  85. name: "tabDetail",
  86. meta: {
  87. title: "",
  88. showLink: false,
  89. i18n: false,
  90. dynamicLevel: 3,
  91. refreshRedirect: "/tabs/index"
  92. }
  93. }
  94. ]
  95. };
  96. // 添加不同按钮权限到/permission/button页面中
  97. function setDifAuthority(authority, routes) {
  98. routes.children[1].meta.authority = [authority];
  99. return routes;
  100. }
  101. export default [
  102. {
  103. url: "/getAsyncRoutes",
  104. method: "get",
  105. response: ({ query }) => {
  106. if (query.name === "admin") {
  107. return {
  108. code: 0,
  109. info: [
  110. tabsRouter,
  111. systemRouter,
  112. setDifAuthority("v-admin", permissionRouter)
  113. ]
  114. };
  115. } else {
  116. return {
  117. code: 0,
  118. info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
  119. };
  120. }
  121. }
  122. }
  123. ] as MockMethod[];