asyncRoutes.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // 模拟后端动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. /**
  4. * roles:页面级别权限,这里模拟二种 "admin"、"common"
  5. * admin:管理员角色
  6. * common:普通角色
  7. */
  8. const systemRouter = {
  9. path: "/system",
  10. meta: {
  11. icon: "setting",
  12. title: "menus.hssysManagement",
  13. rank: 11
  14. },
  15. children: [
  16. {
  17. path: "/system/user/index",
  18. name: "User",
  19. meta: {
  20. icon: "flUser",
  21. title: "menus.hsUser",
  22. roles: ["admin"]
  23. }
  24. },
  25. {
  26. path: "/system/role/index",
  27. name: "Role",
  28. meta: {
  29. icon: "role",
  30. title: "menus.hsRole",
  31. roles: ["admin"]
  32. }
  33. },
  34. {
  35. path: "/system/dept/index",
  36. name: "Dept",
  37. meta: {
  38. icon: "dept",
  39. title: "menus.hsDept",
  40. roles: ["admin"]
  41. }
  42. },
  43. {
  44. path: "/system/dict",
  45. component: "/system/dict/index",
  46. name: "Dict",
  47. meta: {
  48. icon: "dict",
  49. title: "menus.hsDict",
  50. keepAlive: true,
  51. roles: ["admin"]
  52. }
  53. }
  54. ]
  55. };
  56. const permissionRouter = {
  57. path: "/permission",
  58. meta: {
  59. title: "menus.permission",
  60. icon: "lollipop",
  61. rank: 10
  62. },
  63. children: [
  64. {
  65. path: "/permission/page/index",
  66. name: "PermissionPage",
  67. meta: {
  68. title: "menus.permissionPage",
  69. roles: ["admin", "common"]
  70. }
  71. },
  72. {
  73. path: "/permission/button/index",
  74. name: "PermissionButton",
  75. meta: {
  76. title: "menus.permissionButton",
  77. roles: ["admin", "common"],
  78. auths: ["btn_add", "btn_edit", "btn_delete"]
  79. }
  80. }
  81. ]
  82. };
  83. const frameRouter = {
  84. path: "/iframe",
  85. meta: {
  86. icon: "monitor",
  87. title: "menus.hsExternalPage",
  88. rank: 8
  89. },
  90. children: [
  91. {
  92. path: "/iframe/pure",
  93. name: "FramePure",
  94. meta: {
  95. title: "menus.hsPureDocument",
  96. frameSrc: "https://yiming_chang.gitee.io/pure-admin-doc",
  97. roles: ["admin", "common"]
  98. }
  99. },
  100. {
  101. path: "/external",
  102. name: "https://yiming_chang.gitee.io/pure-admin-doc",
  103. meta: {
  104. title: "menus.externalLink",
  105. roles: ["admin", "common"]
  106. }
  107. },
  108. {
  109. path: "/iframe/ep",
  110. name: "FrameEp",
  111. meta: {
  112. title: "menus.hsEpDocument",
  113. frameSrc: "https://element-plus.org/zh-CN/",
  114. roles: ["admin", "common"]
  115. }
  116. }
  117. ]
  118. };
  119. const tabsRouter = {
  120. path: "/tabs",
  121. meta: {
  122. icon: "IF-team-icontabs",
  123. title: "menus.hstabs",
  124. rank: 13
  125. },
  126. children: [
  127. {
  128. path: "/tabs/index",
  129. name: "Tabs",
  130. meta: {
  131. title: "menus.hstabs",
  132. roles: ["admin", "common"]
  133. }
  134. },
  135. // query 传参模式
  136. {
  137. path: "/tabs/query-detail",
  138. name: "TabQueryDetail",
  139. meta: {
  140. // 不在menu菜单中显示
  141. showLink: false,
  142. roles: ["admin", "common"]
  143. }
  144. },
  145. // params 传参模式
  146. {
  147. path: "/tabs/params-detail/:id",
  148. component: "params-detail",
  149. name: "TabParamsDetail",
  150. meta: {
  151. // 不在menu菜单中显示
  152. showLink: false,
  153. roles: ["admin", "common"]
  154. }
  155. }
  156. ]
  157. };
  158. export default [
  159. {
  160. url: "/getAsyncRoutes",
  161. method: "get",
  162. response: () => {
  163. return {
  164. success: true,
  165. data: [systemRouter, permissionRouter, frameRouter, tabsRouter]
  166. };
  167. }
  168. }
  169. ] as MockMethod[];