asyncRoutes.ts 3.5 KB

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