login.ts 975 B

12345678910111213141516171819202122232425262728293031323334353637
  1. // 根据角色动态生成路由
  2. import { MockMethod } from "vite-plugin-mock";
  3. export default [
  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: "2023/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: "2023/10/30 00:00:00"
  30. }
  31. };
  32. }
  33. }
  34. }
  35. ] as MockMethod[];