index.mock.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. import { SUCCESS_CODE } from '@/constants'
  2. const timeout = 1000
  3. const List: {
  4. account: string
  5. pwd: string
  6. role: string
  7. roleId: string
  8. permissions: string | string[]
  9. }[] = [
  10. {
  11. account: 'admin',
  12. pwd: 'admin',
  13. role: 'admin',
  14. roleId: '1',
  15. permissions: ['*.*.*']
  16. },
  17. {
  18. account: 'test',
  19. pwd: 'test',
  20. role: 'test',
  21. roleId: '2',
  22. permissions: ['example:dialog:create', 'example:dialog:delete']
  23. }
  24. ]
  25. export default [
  26. // 列表接口
  27. {
  28. url: '/mock/user/list',
  29. method: 'get',
  30. response: ({ query }) => {
  31. const { account, pageIndex, pageSize } = query
  32. const mockList = List.filter((item) => {
  33. if (account && item.account.indexOf(account) < 0) return false
  34. return true
  35. })
  36. const pageList = mockList.filter(
  37. (_, index) => index < pageSize * pageIndex && index >= pageSize * (pageIndex - 1)
  38. )
  39. return {
  40. code: SUCCESS_CODE,
  41. data: {
  42. total: mockList.length,
  43. list: pageList
  44. }
  45. }
  46. }
  47. },
  48. // 登录接口
  49. {
  50. url: '/adminapi/login',
  51. method: 'post',
  52. timeout,
  53. response: ({ body }) => {
  54. const data = body
  55. let hasUser = false
  56. for (const user of List) {
  57. if (user.account === data.account && user.pwd === data.pwd) {
  58. hasUser = true
  59. return {
  60. status: SUCCESS_CODE,
  61. data: user
  62. }
  63. }
  64. }
  65. if (!hasUser) {
  66. return {
  67. code: 500,
  68. message: '账号或密码错误'
  69. }
  70. }
  71. }
  72. },
  73. // 退出接口
  74. {
  75. url: '/adminapi/logout',
  76. method: 'post',
  77. timeout,
  78. response: () => {
  79. return {
  80. status: SUCCESS_CODE,
  81. data: null
  82. }
  83. }
  84. }
  85. ]