index.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { config } from '@/config/axios/config'
  2. import { MockMethod } from 'vite-plugin-mock'
  3. const { result_code } = config
  4. const timeout = 1000
  5. const List: {
  6. username: string
  7. password: string
  8. role: string
  9. roleId: string
  10. }[] = [
  11. {
  12. username: 'admin',
  13. password: 'admin',
  14. role: 'admin',
  15. roleId: '1'
  16. },
  17. {
  18. username: 'test',
  19. password: 'test',
  20. role: 'test',
  21. roleId: '2'
  22. }
  23. ]
  24. export default [
  25. // 登录接口
  26. {
  27. url: '/user/login',
  28. method: 'post',
  29. timeout,
  30. response: ({ body }) => {
  31. const data = body
  32. let hasUser = false
  33. for (const user of List) {
  34. if (user.username === data.username && user.password === data.password) {
  35. hasUser = true
  36. return {
  37. code: result_code,
  38. data: user
  39. }
  40. }
  41. }
  42. if (!hasUser) {
  43. return {
  44. code: '500',
  45. message: '账号或密码错误'
  46. }
  47. }
  48. }
  49. },
  50. // 退出接口
  51. {
  52. url: '/user/loginOut',
  53. method: 'get',
  54. timeout,
  55. response: () => {
  56. return {
  57. code: result_code,
  58. data: null
  59. }
  60. }
  61. }
  62. ] as MockMethod[]