list.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { MockMethod } from 'vite-plugin-mock';
  2. import { mock, Random } from 'mockjs';
  3. import { resultPageSuccess } from '../_util';
  4. Random.extend({
  5. phone: function () {
  6. const phonePrefixs = ['132', '135', '189']; // 自己写前缀哈
  7. return this.pick(phonePrefixs) + mock(/\d{8}/); //Number()
  8. },
  9. });
  10. // console.log(Random.phone());
  11. // 生成 1 - 10 个 随机手机号码
  12. const demoList = (() => {
  13. const result: any[] = [];
  14. for (let index = 0; index < 200; index++) {
  15. // const { phone } = mock({
  16. // phone: '@phone',
  17. // });
  18. result.push({
  19. id: `${index}`,
  20. name: '@ctitle(3,10)',
  21. desc: '@cparagraph(3, 5)',
  22. link: `https://zfb.4dkankan.com/smobile.html?m=@string( 'lower/number',5,10)`,
  23. 'productType|1': [0, 1, 2, 3],
  24. steamRoom: {
  25. id: 1,
  26. name: '李嘉琪的直播间',
  27. },
  28. 'amount|1': '@integer(20,50)',
  29. 'total|1': '@integer(20,50)',
  30. 'marketingUnit|1': '@float(20,50,3,4)',
  31. 'unit|1': '@float(20,50,3,6)',
  32. isLaunched: '@boolean(1, 9, true)',
  33. createTime: '@datetime',
  34. });
  35. }
  36. return result;
  37. })();
  38. export default [
  39. {
  40. url: '/zfb-api/zfb/product/list',
  41. timeout: 1000,
  42. method: 'get',
  43. response: ({ query }) => {
  44. const { page = 1, pageSize = 20 } = query;
  45. return resultPageSuccess(page, pageSize, demoList);
  46. },
  47. },
  48. ] as MockMethod[];