asyncRoutes.ts 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. // 模拟后端动态生成路由
  2. import { defineFakeRoute } from "vite-plugin-fake-server/client";
  3. import { system, permission, frame, tabs } from "@/router/enums";
  4. /**
  5. * roles:页面级别权限,这里模拟二种 "admin"、"common"
  6. * admin:管理员角色
  7. * common:普通角色
  8. */
  9. const systemRouter = {
  10. path: "/system",
  11. meta: {
  12. icon: "setting",
  13. title: "menus.hssysManagement",
  14. rank: system
  15. },
  16. children: [
  17. {
  18. path: "/system/user/index",
  19. name: "SystemUser",
  20. meta: {
  21. icon: "flUser",
  22. title: "menus.hsUser",
  23. roles: ["admin"]
  24. }
  25. },
  26. {
  27. path: "/system/role/index",
  28. name: "SystemRole",
  29. meta: {
  30. icon: "role",
  31. title: "menus.hsRole",
  32. roles: ["admin"]
  33. }
  34. },
  35. {
  36. path: "/system/dept/index",
  37. name: "SystemDept",
  38. meta: {
  39. icon: "dept",
  40. title: "menus.hsDept",
  41. roles: ["admin"]
  42. }
  43. }
  44. ]
  45. };
  46. const permissionRouter = {
  47. path: "/permission",
  48. meta: {
  49. title: "menus.permission",
  50. icon: "lollipop",
  51. rank: permission
  52. },
  53. children: [
  54. {
  55. path: "/permission/page/index",
  56. name: "PermissionPage",
  57. meta: {
  58. title: "menus.permissionPage",
  59. roles: ["admin", "common"]
  60. }
  61. },
  62. {
  63. path: "/permission/button/index",
  64. name: "PermissionButton",
  65. meta: {
  66. title: "menus.permissionButton",
  67. roles: ["admin", "common"],
  68. auths: ["btn_add", "btn_edit", "btn_delete"]
  69. }
  70. }
  71. ]
  72. };
  73. const frameRouter = {
  74. path: "/iframe",
  75. meta: {
  76. icon: "monitor",
  77. title: "menus.hsExternalPage",
  78. rank: frame
  79. },
  80. children: [
  81. {
  82. path: "/iframe/external",
  83. meta: {
  84. title: "menus.hsExternalDoc"
  85. },
  86. children: [
  87. {
  88. path: "/external",
  89. name: "https://yiming_chang.gitee.io/pure-admin-doc",
  90. meta: {
  91. title: "menus.externalLink",
  92. roles: ["admin", "common"]
  93. }
  94. },
  95. {
  96. path: "/pureutilsLink",
  97. name: "https://pure-admin-utils.netlify.app/",
  98. meta: {
  99. title: "menus.pureutilsLink",
  100. roles: ["admin", "common"]
  101. }
  102. }
  103. ]
  104. },
  105. {
  106. path: "/iframe/embedded",
  107. meta: {
  108. title: "menus.hsEmbeddedDoc"
  109. },
  110. children: [
  111. {
  112. path: "/iframe/ep",
  113. name: "FrameEp",
  114. meta: {
  115. title: "menus.hsEpDocument",
  116. frameSrc: "https://element-plus.org/zh-CN/",
  117. keepAlive: true,
  118. roles: ["admin", "common"]
  119. }
  120. },
  121. {
  122. path: "/iframe/tailwindcss",
  123. name: "FrameTailwindcss",
  124. meta: {
  125. title: "menus.hsTailwindcssDocument",
  126. frameSrc: "https://tailwindcss.com/docs/installation",
  127. keepAlive: true,
  128. roles: ["admin", "common"]
  129. }
  130. },
  131. {
  132. path: "/iframe/vue3",
  133. name: "FrameVue",
  134. meta: {
  135. title: "menus.hsVueDocument",
  136. frameSrc: "https://cn.vuejs.org/",
  137. keepAlive: true,
  138. roles: ["admin", "common"]
  139. }
  140. },
  141. {
  142. path: "/iframe/vite",
  143. name: "FrameVite",
  144. meta: {
  145. title: "menus.hsViteDocument",
  146. frameSrc: "https://cn.vitejs.dev/",
  147. keepAlive: true,
  148. roles: ["admin", "common"]
  149. }
  150. },
  151. {
  152. path: "/iframe/pinia",
  153. name: "FramePinia",
  154. meta: {
  155. title: "menus.hsPiniaDocument",
  156. frameSrc: "https://pinia.vuejs.org/zh/index.html",
  157. keepAlive: true,
  158. roles: ["admin", "common"]
  159. }
  160. },
  161. {
  162. path: "/iframe/vue-router",
  163. name: "FrameRouter",
  164. meta: {
  165. title: "menus.hsRouterDocument",
  166. frameSrc: "https://router.vuejs.org/zh/",
  167. keepAlive: true,
  168. roles: ["admin", "common"]
  169. }
  170. }
  171. ]
  172. }
  173. ]
  174. };
  175. const tabsRouter = {
  176. path: "/tabs",
  177. meta: {
  178. icon: "tag",
  179. title: "menus.hstabs",
  180. rank: tabs
  181. },
  182. children: [
  183. {
  184. path: "/tabs/index",
  185. name: "Tabs",
  186. meta: {
  187. title: "menus.hstabs",
  188. roles: ["admin", "common"]
  189. }
  190. },
  191. // query 传参模式
  192. {
  193. path: "/tabs/query-detail",
  194. name: "TabQueryDetail",
  195. meta: {
  196. // 不在menu菜单中显示
  197. showLink: false,
  198. activePath: "/tabs/index",
  199. roles: ["admin", "common"]
  200. }
  201. },
  202. // params 传参模式
  203. {
  204. path: "/tabs/params-detail/:id",
  205. component: "params-detail",
  206. name: "TabParamsDetail",
  207. meta: {
  208. // 不在menu菜单中显示
  209. showLink: false,
  210. activePath: "/tabs/index",
  211. roles: ["admin", "common"]
  212. }
  213. }
  214. ]
  215. };
  216. export default defineFakeRoute([
  217. {
  218. url: "/get-async-routes",
  219. method: "get",
  220. response: () => {
  221. return {
  222. success: true,
  223. data: [systemRouter, permissionRouter, frameRouter, tabsRouter]
  224. };
  225. }
  226. }
  227. ]);