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. meta: {
  7. icon: "setting",
  8. title: "menus.hssysManagement",
  9. rank: 11
  10. },
  11. children: [
  12. {
  13. path: "/system/user/index",
  14. name: "User",
  15. meta: {
  16. icon: "flUser",
  17. title: "menus.hsUser"
  18. }
  19. },
  20. {
  21. path: "/system/role/index",
  22. name: "Role",
  23. meta: {
  24. icon: "role",
  25. title: "menus.hsRole"
  26. }
  27. },
  28. {
  29. path: "/system/dept/index",
  30. name: "Dept",
  31. meta: {
  32. icon: "dept",
  33. title: "menus.hsDept"
  34. }
  35. },
  36. {
  37. path: "/system/dict",
  38. component: "/system/dict/index",
  39. name: "Dict",
  40. meta: {
  41. icon: "dict",
  42. title: "menus.hsDict",
  43. keepAlive: true
  44. }
  45. }
  46. ]
  47. };
  48. const permissionRouter = {
  49. path: "/permission",
  50. meta: {
  51. title: "menus.permission",
  52. icon: "lollipop",
  53. rank: 7
  54. },
  55. children: [
  56. {
  57. path: "/permission/page/index",
  58. name: "PermissionPage",
  59. meta: {
  60. title: "menus.permissionPage"
  61. }
  62. },
  63. {
  64. path: "/permission/button/index",
  65. name: "PermissionButton",
  66. meta: {
  67. title: "menus.permissionButton",
  68. authority: []
  69. }
  70. }
  71. ]
  72. };
  73. const frameRouter = {
  74. path: "/iframe",
  75. meta: {
  76. icon: "monitor",
  77. title: "menus.hsExternalPage",
  78. rank: 10
  79. },
  80. children: [
  81. {
  82. path: "/iframe/pure",
  83. name: "FramePure",
  84. meta: {
  85. title: "menus.hsPureDocument",
  86. frameSrc: "http://yiming_chang.gitee.io/pure-admin-doc"
  87. }
  88. },
  89. {
  90. path: "/external",
  91. name: "http://yiming_chang.gitee.io/pure-admin-doc",
  92. meta: {
  93. title: "menus.externalLink"
  94. }
  95. },
  96. {
  97. path: "/iframe/ep",
  98. name: "FrameEp",
  99. meta: {
  100. title: "menus.hsEpDocument",
  101. frameSrc: "https://element-plus.org/zh-CN/"
  102. }
  103. }
  104. ]
  105. };
  106. const tabsRouter = {
  107. path: "/tabs",
  108. meta: {
  109. icon: "IF-team-icontabs",
  110. title: "menus.hstabs",
  111. rank: 13
  112. },
  113. children: [
  114. {
  115. path: "/tabs/index",
  116. name: "Tabs",
  117. meta: {
  118. title: "menus.hstabs"
  119. }
  120. },
  121. {
  122. path: "/tabs/query-detail",
  123. name: "TabQueryDetail",
  124. meta: {
  125. // 不在menu菜单中显示
  126. showLink: false
  127. }
  128. },
  129. {
  130. path: "/tabs/params-detail/:id",
  131. component: "params-detail",
  132. name: "TabParamsDetail",
  133. meta: {
  134. showLink: false
  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[];