index.ts 947 B

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