asyncRoutes.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. i18n: true,
  11. rank: 11
  12. },
  13. children: [
  14. // {
  15. // path: "/system/dict/index",
  16. // name: "dict",
  17. // meta: {
  18. // title: "menus.hsDict",
  19. // i18n: true,
  20. // keepAlive: true
  21. // }
  22. // },
  23. {
  24. path: "/system/user/index",
  25. name: "user",
  26. meta: {
  27. icon: "flUser",
  28. title: "menus.hsUser",
  29. i18n: true
  30. }
  31. },
  32. {
  33. path: "/system/role/index",
  34. name: "role",
  35. meta: {
  36. icon: "peoples",
  37. title: "menus.hsRole",
  38. i18n: true
  39. }
  40. },
  41. {
  42. path: "/system/dept/index",
  43. name: "dept",
  44. meta: {
  45. icon: "office-building",
  46. title: "menus.hsDept",
  47. i18n: true
  48. }
  49. }
  50. ]
  51. };
  52. const permissionRouter = {
  53. path: "/permission",
  54. redirect: "/permission/page/index",
  55. meta: {
  56. title: "menus.permission",
  57. icon: "lollipop",
  58. i18n: true,
  59. rank: 7
  60. },
  61. children: [
  62. {
  63. path: "/permission/page/index",
  64. name: "permissionPage",
  65. meta: {
  66. title: "menus.permissionPage",
  67. i18n: true
  68. }
  69. },
  70. {
  71. path: "/permission/button/index",
  72. name: "permissionButton",
  73. meta: {
  74. title: "menus.permissionButton",
  75. i18n: true,
  76. authority: []
  77. }
  78. }
  79. ]
  80. };
  81. const frameRouter = {
  82. path: "/iframe",
  83. redirect: "/iframe/pure",
  84. meta: {
  85. icon: "monitor",
  86. title: "menus.hsExternalPage",
  87. i18n: true,
  88. rank: 10
  89. },
  90. children: [
  91. {
  92. path: "/iframe/pure",
  93. name: "reFramePure",
  94. meta: {
  95. i18n: true,
  96. title: "menus.hsPureDocument",
  97. frameSrc: "https://pure-admin-doc.vercel.app"
  98. }
  99. },
  100. {
  101. path: "/external",
  102. name: "https://pure-admin-doc.vercel.app",
  103. meta: {
  104. title: "menus.externalLink",
  105. i18n: true
  106. }
  107. },
  108. {
  109. path: "/iframe/ep",
  110. name: "reFrameEp",
  111. meta: {
  112. i18n: true,
  113. title: "menus.hsEpDocument",
  114. frameSrc: "https://element-plus.gitee.io/zh-CN/"
  115. }
  116. }
  117. ]
  118. };
  119. const tabsRouter = {
  120. path: "/tabs",
  121. redirect: "/tabs/index",
  122. meta: {
  123. icon: "IF-team-icontabs",
  124. title: "menus.hstabs",
  125. i18n: true,
  126. rank: 12
  127. },
  128. children: [
  129. {
  130. path: "/tabs/index",
  131. name: "reTabs",
  132. meta: {
  133. title: "menus.hstabs",
  134. i18n: true
  135. }
  136. },
  137. {
  138. path: "/tabs/detail",
  139. name: "tabDetail",
  140. meta: {
  141. title: "",
  142. showLink: false,
  143. i18n: false,
  144. dynamicLevel: 3,
  145. refreshRedirect: "/tabs/index"
  146. }
  147. }
  148. ]
  149. };
  150. // 添加不同按钮权限到/permission/button页面中
  151. function setDifAuthority(authority, routes) {
  152. routes.children[1].meta.authority = [authority];
  153. return routes;
  154. }
  155. export default [
  156. {
  157. url: "/getAsyncRoutes",
  158. method: "get",
  159. response: ({ query }) => {
  160. if (query.name === "admin") {
  161. return {
  162. code: 0,
  163. info: [
  164. tabsRouter,
  165. frameRouter,
  166. systemRouter,
  167. setDifAuthority("v-admin", permissionRouter)
  168. ]
  169. };
  170. } else {
  171. return {
  172. code: 0,
  173. info: [tabsRouter, setDifAuthority("v-test", permissionRouter)]
  174. };
  175. }
  176. }
  177. }
  178. ] as MockMethod[];