four.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import Mock from 'mockjs'
  2. import { MockMethod } from 'vite-plugin-mock'
  3. let saveinfo: {
  4. employee: string
  5. name: string
  6. sex: string
  7. area: string
  8. section: string
  9. birthday: string
  10. profession: string
  11. educational: string
  12. universities: string
  13. aptityde: string
  14. beGoodAt: string
  15. introduction: string
  16. } | null = null
  17. const mockMethodFour: MockMethod[] = [
  18. {
  19. url: '/mock/api/four/userinfo',
  20. method: 'get',
  21. timeout: 1000,
  22. response: () => ({
  23. code: '0',
  24. ...Mock.mock({
  25. data: saveinfo ?? {
  26. employee: '@integer(0)',
  27. name: '@cname',
  28. sex: '@sex',
  29. area: '@integer(1, 3)',
  30. section: '@integer(1, 3)',
  31. birthday: '@datetime',
  32. profession: '@profession',
  33. educational: '@educational',
  34. universities: '@universities',
  35. aptityde: '@jobQualifications',
  36. beGoodAt: '@expertise',
  37. introduction: '唱跳两年半练习生'
  38. }
  39. })
  40. })
  41. },
  42. {
  43. url: '/mock/api/four/query',
  44. method: 'get',
  45. timeout: 1000,
  46. response: () => ({
  47. code: '0',
  48. ...Mock.mock({
  49. 'data|5-10': [
  50. {
  51. id: '@id',
  52. type: '类型@integer(1, 10)',
  53. product: '@goods',
  54. profession: '@profession',
  55. name: '@ctitle',
  56. // intro: '@csentence(5, 10)',
  57. createName: '@cname',
  58. createTime: '@datetime("2024-MM-dd hh:mm:ss")',
  59. modification: '@cname',
  60. modifiTime: '@datetime("2024-MM-dd hh:mm:ss")'
  61. }
  62. ]
  63. })
  64. })
  65. },
  66. {
  67. url: '/mock/api/four/tags',
  68. method: 'get',
  69. timeout: 1000,
  70. response: () => ({
  71. code: '0',
  72. ...Mock.mock({
  73. data: {
  74. 'product|2-3': [{ name: '@product', type: '@colorTypes' }],
  75. 'profession|2-3': [{ name: '@profession', type: '@colorTypes' }],
  76. 'expert|2-3': [{ name: '@expertTags', type: '@colorTypes' }]
  77. }
  78. })
  79. })
  80. },
  81. {
  82. url: '/mock/api/four/save',
  83. method: 'post',
  84. timeout: 1000,
  85. response: ({ body }: { body: any }) => {
  86. console.log(body)
  87. saveinfo = body
  88. return { code: '0' }
  89. }
  90. }
  91. ]
  92. export default mockMethodFour