asyncRoutes.ts 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. // http://mockjs.com/examples.html#Object
  4. const systemRouter = {
  5. path: "/system",
  6. redirect: "/system/user/index",
  7. meta: {
  8. icon: "setting",
  9. title: "menus.hssysManagement",
  10. rank: 11
  11. },
  12. children: [
  13. {
  14. path: "/system/user/index",
  15. name: "User",
  16. meta: {
  17. icon: "flUser",
  18. title: "menus.hsUser"
  19. }
  20. },
  21. {
  22. path: "/system/role/index",
  23. name: "Role",
  24. meta: {
  25. icon: "role",
  26. title: "menus.hsRole"
  27. }
  28. },
  29. {
  30. path: "/system/dept/index",
  31. name: "Dept",
  32. meta: {
  33. icon: "dept",
  34. title: "menus.hsDept"
  35. }
  36. },
  37. {
  38. path: "/system/dict",
  39. component: "/system/dict/index",
  40. name: "Dict",
  41. meta: {
  42. icon: "dict",
  43. title: "menus.hsDict",
  44. keepAlive: true
  45. }
  46. }
  47. ]
  48. };
  49. const permissionRouter = {
  50. path: "/permission",
  51. redirect: "/permission/page/index",
  52. meta: {
  53. title: "menus.permission",
  54. icon: "lollipop",
  55. rank: 7
  56. },
  57. children: [
  58. {
  59. path: "/permission/page/index",
  60. name: "PermissionPage",
  61. meta: {
  62. title: "menus.permissionPage"
  63. }
  64. },
  65. {
  66. path: "/permission/button/index",
  67. name: "PermissionButton",
  68. meta: {
  69. title: "menus.permissionButton",
  70. authority: []
  71. }
  72. }
  73. ]
  74. };
  75. const frameRouter = {
  76. path: "/iframe",
  77. redirect: "/iframe/pure",
  78. meta: {
  79. icon: "monitor",
  80. title: "menus.hsExternalPage",
  81. rank: 10
  82. },
  83. children: [
  84. {
  85. path: "/iframe/pure",
  86. name: "FramePure",
  87. meta: {
  88. title: "menus.hsPureDocument",
  89. frameSrc: "https://pure-admin-doc.vercel.app"
  90. }
  91. },
  92. {
  93. path: "/external",
  94. name: "https://pure-admin-doc.vercel.app",
  95. meta: {
  96. title: "menus.externalLink"
  97. }
  98. },
  99. {
  100. path: "/iframe/ep",
  101. name: "FrameEp",
  102. meta: {
  103. title: "menus.hsEpDocument",
  104. frameSrc: "https://element-plus.org/zh-CN/"
  105. }
  106. }
  107. ]
  108. };
  109. const tabsRouter = {
  110. path: "/tabs",
  111. redirect: "/tabs/index",
  112. meta: {
  113. icon: "IF-team-icontabs",
  114. title: "menus.hstabs",
  115. rank: 13
  116. },
  117. children: [
  118. {
  119. path: "/tabs/index",
  120. name: "Tabs",
  121. meta: {
  122. title: "menus.hstabs"
  123. }
  124. },
  125. {
  126. path: "/tabs/detail",
  127. name: "TabDetail",
  128. meta: {
  129. title: "",
  130. showLink: false,
  131. dynamicLevel: 3,
  132. refreshRedirect: "/tabs/index"
  133. }
  134. }
  135. ]
  136. };
  137. // 添加不同按钮权限到/permission/button页面中
  138. function setDifAuthority(authority, routes) {
  139. routes.children[1].meta.authority = [authority];
  140. return routes;
  141. }
  142. export default [
  143. {
  144. url: "/getAsyncRoutes",
  145. method: "get",
  146. response: ({ query }) => {
  147. if (query.name === "admin") {
  148. return {
  149. code: 0,
  150. info: [
  151. tabsRouter,
  152. frameRouter,
  153. systemRouter,
  154. setDifAuthority("v-admin", permissionRouter)
  155. ]
  156. };
  157. } else {
  158. return {
  159. code: 0,
  160. info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
  161. };
  162. }
  163. }
  164. }
  165. ] as MockMethod[];