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.

36 lines
995 B

  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. username: "admin",
  13. // 一个用户可能有多个角色
  14. roles: ["admin"],
  15. accessToken: "eyJhbGciOiJIUzUxMiJ9.admin",
  16. refreshToken: "eyJhbGciOiJIUzUxMiJ9.adminRefresh",
  17. expires: "2030/10/30 00:00:00"
  18. }
  19. };
  20. } else {
  21. return {
  22. success: true,
  23. data: {
  24. username: "common",
  25. // 一个用户可能有多个角色
  26. roles: ["common"],
  27. accessToken: "eyJhbGciOiJIUzUxMiJ9.common",
  28. refreshToken: "eyJhbGciOiJIUzUxMiJ9.commonRefresh",
  29. expires: "2030/10/30 00:00:00"
  30. }
  31. };
  32. }
  33. }
  34. }
  35. ]);