example.ts 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { MockMethod } from 'vite-plugin-mock'
  2. const baseUrl = '/api/mock/example'
  3. export default [
  4. {
  5. url: `${baseUrl}/loadList`,
  6. method: 'post',
  7. timeout: 500,
  8. response: (res) => {
  9. const { pageNum, pageSize, name } = res.body
  10. const total = name === '无数据' ? 0 : 85
  11. const preNum = (pageNum - 1) * pageSize
  12. let code = 20000
  13. if (name === '错误') {
  14. code = Math.floor(Math.random() * 10 + 1) > 7 ? 0 : 20000
  15. }
  16. let size = pageSize
  17. if (preNum + pageSize > total) {
  18. size = total - preNum
  19. }
  20. const result = {
  21. items: [...new Array(size)].map((_x, n) => name + ':' + (n + preNum)),
  22. total
  23. }
  24. return {
  25. code,
  26. result,
  27. message: 'ok'
  28. }
  29. }
  30. }
  31. ] as MockMethod[]