table-demo.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { Random } from 'mockjs';
  3. import { resultPageSuccess } 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. radio1: `选项${index + 1}`,
  29. radio2: `选项${index + 1}`,
  30. radio3: `选项${index + 1}`,
  31. avatar: Random.image('400x400', Random.color(), Random.color(), Random.first()),
  32. imgArr: getRandomPics(Math.ceil(Math.random() * 3) + 1),
  33. imgs: getRandomPics(Math.ceil(Math.random() * 3) + 1),
  34. date: `@date('yyyy-MM-dd')`,
  35. time: `@time('HH:mm')`,
  36. 'no|100000-10000000': 100000,
  37. 'status|1': ['normal', 'enable', 'disable'],
  38. });
  39. }
  40. return result;
  41. })();
  42. export default [
  43. {
  44. url: '/basic-api/table/getDemoList',
  45. timeout: 100,
  46. method: 'get',
  47. response: ({ query }) => {
  48. const { page = 1, pageSize = 20 } = query;
  49. return resultPageSuccess(page, pageSize, demoList);
  50. },
  51. },
  52. ] as MockMethod[];