You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
1.1 KiB

  1. // 根据角色动态生成路由
  2. import { defineFakeRoute } from "vite-plugin-fake-server/client";
  3. export default defineFakeRoute([
  4. {
  5. url: "/login",
  6. method: "post",
  7. response: ({ body }) => {
  8. if (body.username === "admin") {
  9. return {
  10. success: true,
  11. data: {
  12. avatar: "https://avatars.githubusercontent.com/u/44761321",
  13. username: "admin",
  14. nickname: "小铭",
  15. // 一个用户可能有多个角色
  16. roles: ["admin"],
  17. accessToken: "eyJhbGciOiJIUzUxMiJ9.admin",
  18. refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
  19. expires: "2030/10/30 00:00:00"
  20. }
  21. };
  22. } else {
  23. return {
  24. success: true,
  25. data: {
  26. avatar: "https://avatars.githubusercontent.com/u/52823142",
  27. username: "common",
  28. nickname: "小林",
  29. roles: ["common"],
  30. accessToken: "eyJhbGciOiJIUzUxMiJ9.common",
  31. refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
  32. expires: "2030/10/30 00:00:00"
  33. }
  34. };
  35. }
  36. }
  37. }
  38. ]);