asyncRoutes.ts 3.5 KB

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