asyncRoutes.ts 3.2 KB

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