asyncRoutes.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. // 模拟后端动态生成路由
  2. import { defineFakeRoute } from "vite-plugin-fake-server/client";
  3. import { system, monitor, permission, frame, tabs } from "@/router/enums";
  4. /**
  5. * roles:页面级别权限,这里模拟二种 "admin"、"common"
  6. * admin:管理员角色
  7. * common:普通角色
  8. */
  9. const systemManagementRouter = {
  10. path: "/system",
  11. meta: {
  12. icon: "ri:settings-3-line",
  13. title: "menus.pureSysManagement",
  14. rank: system
  15. },
  16. children: [
  17. {
  18. path: "/system/user/index",
  19. name: "SystemUser",
  20. meta: {
  21. icon: "ri:admin-line",
  22. title: "menus.pureUser",
  23. roles: ["admin"]
  24. }
  25. },
  26. {
  27. path: "/system/role/index",
  28. name: "SystemRole",
  29. meta: {
  30. icon: "ri:admin-fill",
  31. title: "menus.pureRole",
  32. roles: ["admin"]
  33. }
  34. },
  35. {
  36. path: "/system/menu/index",
  37. name: "SystemMenu",
  38. meta: {
  39. icon: "ep:menu",
  40. title: "menus.pureSystemMenu",
  41. roles: ["admin"]
  42. }
  43. },
  44. {
  45. path: "/system/dept/index",
  46. name: "SystemDept",
  47. meta: {
  48. icon: "ri:git-branch-line",
  49. title: "menus.pureDept",
  50. roles: ["admin"]
  51. }
  52. }
  53. ]
  54. };
  55. const systemMonitorRouter = {
  56. path: "/monitor",
  57. meta: {
  58. icon: "ep:monitor",
  59. title: "menus.pureSysMonitor",
  60. rank: monitor
  61. },
  62. children: [
  63. {
  64. path: "/monitor/online-user",
  65. component: "monitor/online/index",
  66. name: "OnlineUser",
  67. meta: {
  68. icon: "ri:user-voice-line",
  69. title: "menus.pureOnlineUser",
  70. roles: ["admin"]
  71. }
  72. },
  73. {
  74. path: "/monitor/login-logs",
  75. component: "monitor/logs/login/index",
  76. name: "LoginLog",
  77. meta: {
  78. icon: "ri:window-line",
  79. title: "menus.pureLoginLog",
  80. roles: ["admin"]
  81. }
  82. },
  83. {
  84. path: "/monitor/operation-logs",
  85. component: "monitor/logs/operation/index",
  86. name: "OperationLog",
  87. meta: {
  88. icon: "ri:history-fill",
  89. title: "menus.pureOperationLog",
  90. roles: ["admin"]
  91. }
  92. },
  93. {
  94. path: "/monitor/system-logs",
  95. component: "monitor/logs/system/index",
  96. name: "SystemLog",
  97. meta: {
  98. icon: "ri:file-search-line",
  99. title: "menus.pureSystemLog",
  100. roles: ["admin"]
  101. }
  102. }
  103. ]
  104. };
  105. const permissionRouter = {
  106. path: "/permission",
  107. meta: {
  108. title: "menus.purePermission",
  109. icon: "ep:lollipop",
  110. rank: permission
  111. },
  112. children: [
  113. {
  114. path: "/permission/page/index",
  115. name: "PermissionPage",
  116. meta: {
  117. title: "menus.purePermissionPage",
  118. roles: ["admin", "common"]
  119. }
  120. },
  121. {
  122. path: "/permission/button/index",
  123. name: "PermissionButton",
  124. meta: {
  125. title: "menus.purePermissionButton",
  126. roles: ["admin", "common"],
  127. auths: [
  128. "permission:btn:add",
  129. "permission:btn:edit",
  130. "permission:btn:delete"
  131. ]
  132. }
  133. }
  134. ]
  135. };
  136. const frameRouter = {
  137. path: "/iframe",
  138. meta: {
  139. icon: "ri:links-fill",
  140. title: "menus.pureExternalPage",
  141. rank: frame
  142. },
  143. children: [
  144. {
  145. path: "/iframe/external",
  146. meta: {
  147. title: "menus.pureExternalDoc"
  148. },
  149. children: [
  150. {
  151. path: "/external",
  152. name: "https://yiming_chang.gitee.io/pure-admin-doc",
  153. meta: {
  154. title: "menus.pureExternalLink",
  155. roles: ["admin", "common"]
  156. }
  157. },
  158. {
  159. path: "/pureUtilsLink",
  160. name: "https://pure-admin-utils.netlify.app/",
  161. meta: {
  162. title: "menus.pureUtilsLink",
  163. roles: ["admin", "common"]
  164. }
  165. }
  166. ]
  167. },
  168. {
  169. path: "/iframe/embedded",
  170. meta: {
  171. title: "menus.pureEmbeddedDoc"
  172. },
  173. children: [
  174. {
  175. path: "/iframe/colorhunt",
  176. name: "FrameColorHunt",
  177. meta: {
  178. title: "menus.pureColorHuntDoc",
  179. frameSrc: "https://colorhunt.co/",
  180. keepAlive: true,
  181. roles: ["admin", "common"]
  182. }
  183. },
  184. {
  185. path: "/iframe/uigradients",
  186. name: "FrameUiGradients",
  187. meta: {
  188. title: "menus.pureUiGradients",
  189. frameSrc: "https://uigradients.com/",
  190. keepAlive: true,
  191. roles: ["admin", "common"]
  192. }
  193. },
  194. {
  195. path: "/iframe/ep",
  196. name: "FrameEp",
  197. meta: {
  198. title: "menus.pureEpDoc",
  199. frameSrc: "https://element-plus.org/zh-CN/",
  200. keepAlive: true,
  201. roles: ["admin", "common"]
  202. }
  203. },
  204. {
  205. path: "/iframe/tailwindcss",
  206. name: "FrameTailwindcss",
  207. meta: {
  208. title: "menus.pureTailwindcssDoc",
  209. frameSrc: "https://tailwindcss.com/docs/installation",
  210. keepAlive: true,
  211. roles: ["admin", "common"]
  212. }
  213. },
  214. {
  215. path: "/iframe/vue3",
  216. name: "FrameVue",
  217. meta: {
  218. title: "menus.pureVueDoc",
  219. frameSrc: "https://cn.vuejs.org/",
  220. keepAlive: true,
  221. roles: ["admin", "common"]
  222. }
  223. },
  224. {
  225. path: "/iframe/vite",
  226. name: "FrameVite",
  227. meta: {
  228. title: "menus.pureViteDoc",
  229. frameSrc: "https://cn.vitejs.dev/",
  230. keepAlive: true,
  231. roles: ["admin", "common"]
  232. }
  233. },
  234. {
  235. path: "/iframe/pinia",
  236. name: "FramePinia",
  237. meta: {
  238. title: "menus.purePiniaDoc",
  239. frameSrc: "https://pinia.vuejs.org/zh/index.html",
  240. keepAlive: true,
  241. roles: ["admin", "common"]
  242. }
  243. },
  244. {
  245. path: "/iframe/vue-router",
  246. name: "FrameRouter",
  247. meta: {
  248. title: "menus.pureRouterDoc",
  249. frameSrc: "https://router.vuejs.org/zh/",
  250. keepAlive: true,
  251. roles: ["admin", "common"]
  252. }
  253. }
  254. ]
  255. }
  256. ]
  257. };
  258. const tabsRouter = {
  259. path: "/tabs",
  260. meta: {
  261. icon: "ri:bookmark-2-line",
  262. title: "menus.pureTabs",
  263. rank: tabs
  264. },
  265. children: [
  266. {
  267. path: "/tabs/index",
  268. name: "Tabs",
  269. meta: {
  270. title: "menus.pureTabs",
  271. roles: ["admin", "common"]
  272. }
  273. },
  274. // query 传参模式
  275. {
  276. path: "/tabs/query-detail",
  277. name: "TabQueryDetail",
  278. meta: {
  279. // 不在menu菜单中显示
  280. showLink: false,
  281. activePath: "/tabs/index",
  282. roles: ["admin", "common"]
  283. }
  284. },
  285. // params 传参模式
  286. {
  287. path: "/tabs/params-detail/:id",
  288. component: "params-detail",
  289. name: "TabParamsDetail",
  290. meta: {
  291. // 不在menu菜单中显示
  292. showLink: false,
  293. activePath: "/tabs/index",
  294. roles: ["admin", "common"]
  295. }
  296. }
  297. ]
  298. };
  299. export default defineFakeRoute([
  300. {
  301. url: "/get-async-routes",
  302. method: "get",
  303. response: () => {
  304. return {
  305. success: true,
  306. data: [
  307. systemManagementRouter,
  308. systemMonitorRouter,
  309. permissionRouter,
  310. frameRouter,
  311. tabsRouter
  312. ]
  313. };
  314. }
  315. }
  316. ]);