async-routes.fake.ts 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. import { about, access, home, outside, personalCenter, routeNest, system } from "#/src/router/extra-info";
  2. import { defineFakeRoute } from "vite-plugin-fake-server/client";
  3. import { ADMIN_TOKEN } from "./constants";
  4. import { resultSuccess } from "./utils";
  5. /**
  6. * roles:页面级别权限,这里模拟二种 "admin"、"common"
  7. * admin:管理员角色
  8. * common:普通角色
  9. */
  10. const systemManagementRouter = {
  11. path: "/system",
  12. handle: {
  13. icon: "SettingOutlined",
  14. title: "common.menu.system",
  15. order: system,
  16. roles: ["admin"],
  17. },
  18. children: [
  19. {
  20. path: "/system/user",
  21. handle: {
  22. icon: "UserOutlined",
  23. title: "common.menu.user",
  24. roles: ["admin"],
  25. permissions: [
  26. "permission:button:add",
  27. "permission:button:update",
  28. "permission:button:delete",
  29. ],
  30. },
  31. },
  32. {
  33. path: "/system/role",
  34. handle: {
  35. icon: "TeamOutlined",
  36. title: "common.menu.role",
  37. roles: ["admin"],
  38. permissions: [
  39. "permission:button:add",
  40. "permission:button:update",
  41. "permission:button:delete",
  42. ],
  43. },
  44. },
  45. {
  46. path: "/system/menu",
  47. handle: {
  48. icon: "MenuOutlined",
  49. title: "common.menu.menu",
  50. roles: ["admin"],
  51. permissions: [
  52. "permission:button:add",
  53. "permission:button:update",
  54. "permission:button:delete",
  55. ],
  56. },
  57. },
  58. {
  59. path: "/system/dept",
  60. handle: {
  61. keepAlive: false,
  62. icon: "ApartmentOutlined",
  63. title: "common.menu.dept",
  64. roles: ["admin"],
  65. permissions: [
  66. "permission:button:add",
  67. "permission:button:update",
  68. "permission:button:delete",
  69. ],
  70. },
  71. },
  72. ],
  73. };
  74. const homeRouter = {
  75. path: "/home",
  76. handle: {
  77. icon: "HomeOutlined",
  78. title: "common.menu.home",
  79. order: home,
  80. },
  81. };
  82. const aboutRouter = {
  83. path: "/about",
  84. handle: {
  85. icon: "CopyrightOutlined",
  86. title: "common.menu.about",
  87. order: about,
  88. },
  89. };
  90. const outsideRouter = {
  91. path: "/outside",
  92. handle: {
  93. icon: "OutsidePageIcon",
  94. title: "common.menu.outside",
  95. order: outside,
  96. },
  97. children: [
  98. {
  99. path: "/outside/embedded",
  100. handle: {
  101. icon: "EmbeddedIcon",
  102. title: "common.menu.embedded",
  103. },
  104. children: [
  105. {
  106. path: "/outside/embedded/ant-design",
  107. handle: {
  108. icon: "AntDesignOutlined",
  109. title: "common.menu.antd",
  110. iframeLink: "https://ant.design/",
  111. },
  112. },
  113. {
  114. path: "/outside/embedded/project-docs",
  115. handle: {
  116. icon: "ContainerOutlined",
  117. title: "common.menu.projectDocs",
  118. iframeLink: "https://condorheroblog.github.io/react-antd-admin/docs/",
  119. },
  120. },
  121. ],
  122. },
  123. {
  124. path: "/outside/external-link",
  125. handle: {
  126. icon: "ExternalIcon",
  127. title: "common.menu.externalLink",
  128. },
  129. children: [
  130. {
  131. path: "/outside/external-link/react-docs",
  132. handle: {
  133. icon: "ReactLogoIcon",
  134. title: "common.menu.reactDocs",
  135. externalLink: "https://react.dev/",
  136. },
  137. },
  138. ],
  139. },
  140. ],
  141. };
  142. const personalCenterRouter = {
  143. path: "/personal-center",
  144. handle: {
  145. order: personalCenter,
  146. title: "common.menu.personalCenter",
  147. icon: "UserCircleIcon",
  148. },
  149. children: [
  150. {
  151. path: "/personal-center/my-profile",
  152. handle: {
  153. title: "common.menu.profile",
  154. icon: "ProfileIcon",
  155. },
  156. },
  157. {
  158. path: "/personal-center/settings",
  159. handle: {
  160. title: "common.menu.settings",
  161. icon: "UserSettingsIcon",
  162. },
  163. },
  164. ],
  165. };
  166. const routeNestRouter = {
  167. path: "/route-nest",
  168. handle: {
  169. order: routeNest,
  170. title: "common.menu.nestMenus",
  171. icon: "NodeExpandOutlined",
  172. },
  173. children: [
  174. {
  175. path: "/route-nest/menu1",
  176. handle: {
  177. title: "common.menu.menu1",
  178. icon: "SisternodeOutlined",
  179. },
  180. children: [
  181. {
  182. path: "/route-nest/menu1/menu1-1",
  183. handle: {
  184. title: "common.menu.menu1-1",
  185. icon: ("SubnodeOutlined"),
  186. },
  187. },
  188. {
  189. path: "/route-nest/menu1/menu1-2",
  190. handle: {
  191. title: "common.menu.menu1-2",
  192. icon: ("SubnodeOutlined"),
  193. },
  194. },
  195. ],
  196. },
  197. {
  198. path: "/route-nest/menu2",
  199. handle: {
  200. title: "common.menu.menu2",
  201. icon: "SubnodeOutlined",
  202. },
  203. },
  204. ],
  205. };
  206. export default defineFakeRoute([
  207. {
  208. url: "/get-async-routes",
  209. timeout: 1000,
  210. method: "get",
  211. response: ({ headers }) => {
  212. const userToken = headers.authorization?.split(" ")?.[1];
  213. const isAdmin = userToken === ADMIN_TOKEN;
  214. const accessRouter = {
  215. path: "/access",
  216. handle: {
  217. icon: "SafetyOutlined",
  218. title: "common.menu.access",
  219. order: access,
  220. },
  221. children: [
  222. /**
  223. * @zh 通过接口获取路由时可见
  224. * @en Visible only when getting routes through the interface
  225. */
  226. {
  227. path: "/access/access-mode",
  228. handle: {
  229. icon: "CloudOutlined",
  230. title: "common.menu.accessMode",
  231. },
  232. },
  233. {
  234. path: "/access/page-control",
  235. handle: {
  236. icon: "FileTextOutlined",
  237. title: "common.menu.pageControl",
  238. },
  239. },
  240. {
  241. path: "/access/button-control",
  242. handle: {
  243. icon: "LockOutlined",
  244. title: "common.menu.buttonControl",
  245. permissions: isAdmin
  246. ? [
  247. "permission:button:get",
  248. "permission:button:update",
  249. "permission:button:delete",
  250. "permission:button:add",
  251. ]
  252. : [
  253. "permission:button:get",
  254. ],
  255. },
  256. },
  257. isAdmin
  258. ? {
  259. path: "/access/admin-visible",
  260. handle: {
  261. icon: "EyeOutlined",
  262. title: "common.menu.adminVisible",
  263. },
  264. }
  265. : {
  266. path: "/access/common-visible",
  267. handle: {
  268. icon: "EyeOutlined",
  269. title: "common.menu.commonVisible",
  270. },
  271. },
  272. ],
  273. };
  274. return resultSuccess(
  275. [
  276. homeRouter,
  277. accessRouter,
  278. aboutRouter,
  279. systemManagementRouter,
  280. outsideRouter,
  281. personalCenterRouter,
  282. routeNestRouter,
  283. ],
  284. );
  285. },
  286. },
  287. ]);