index.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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/list',
  28. method: 'get',
  29. response: ({ query }) => {
  30. const { username, pageIndex, pageSize } = query
  31. const mockList = List.filter((item) => {
  32. if (username && item.username.indexOf(username) < 0) return false
  33. return true
  34. })
  35. const pageList = mockList.filter(
  36. (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
  37. )
  38. return {
  39. code: result_code,
  40. data: {
  41. total: mockList.length,
  42. list: pageList
  43. }
  44. }
  45. }
  46. },
  47. // 登录接口
  48. {
  49. url: '/user/login',
  50. method: 'post',
  51. timeout,
  52. response: ({ body }) => {
  53. const data = body
  54. let hasUser = false
  55. for (const user of List) {
  56. if (user.username === data.username && user.password === data.password) {
  57. hasUser = true
  58. return {
  59. code: result_code,
  60. data: user
  61. }
  62. }
  63. }
  64. if (!hasUser) {
  65. return {
  66. code: '500',
  67. message: '账号或密码错误'
  68. }
  69. }
  70. }
  71. },
  72. // 退出接口
  73. {
  74. url: '/user/loginOut',
  75. method: 'get',
  76. timeout,
  77. response: () => {
  78. return {
  79. code: result_code,
  80. data: null
  81. }
  82. }
  83. }
  84. ] as MockMethod[]