table-demo.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { Random } from 'mockjs';
  3. import { resultPageSuccess, baseUrl } from '../_util';
  4. function getRandomPics(count = 10): string[] {
  5. const arr: string[] = [];
  6. for (let i = 0; i < count; i++) {
  7. arr.push(Random.image('800x600', Random.color(), Random.color(), Random.title()));
  8. }
  9. return arr;
  10. }
  11. const demoList = (() => {
  12. const result: any[] = [];
  13. for (let index = 0; index < 200; index++) {
  14. result.push({
  15. id: `${index}`,
  16. beginTime: '@datetime',
  17. endTime: '@datetime',
  18. address: '@city()',
  19. name: '@cname()',
  20. name1: '@cname()',
  21. name2: '@cname()',
  22. name3: '@cname()',
  23. name4: '@cname()',
  24. name5: '@cname()',
  25. name6: '@cname()',
  26. name7: '@cname()',
  27. name8: '@cname()',
  28. avatar: Random.image('400x400', Random.color(), Random.color(), Random.first()),
  29. imgArr: getRandomPics(Math.ceil(Math.random() * 3) + 1),
  30. imgs: getRandomPics(Math.ceil(Math.random() * 3) + 1),
  31. age: Math.ceil(Math.random() * 30) + 1,
  32. score: Math.ceil(Math.random() * 80) + 1,
  33. date: `@date('yyyy-MM-dd')`,
  34. time: `@time('HH:mm')`,
  35. 'no|100000-10000000': 100000,
  36. 'status|1': ['normal', 'enable', 'disable'],
  37. });
  38. }
  39. return result;
  40. })();
  41. export default [
  42. {
  43. url: `${baseUrl}/table/getDemoList`,
  44. timeout: 100,
  45. method: 'get',
  46. response: ({ query }) => {
  47. const { page = 1, pageSize = 20 } = query;
  48. return resultPageSuccess(page, pageSize, demoList);
  49. },
  50. },
  51. ] as MockMethod[];