asyncRoutes.ts 3.4 KB

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