asyncRoutes.ts 3.2 KB

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