category.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 categoryList = (() => {
  13. const result: any[] = [];
  14. for (let index = 0; index < 20; index++) {
  15. result.push({
  16. id: `${index}`,
  17. icon: ['ion:layers-outline', 'ion:git-compare-outline', 'ion:tv-outline'][index],
  18. component: 'LAYOUT',
  19. name: '@ctitle(5,15)',
  20. type: '0',
  21. orderNo: index + 1,
  22. createTime: '@datetime',
  23. 'status|1': ['0', '0', '1'],
  24. children: (() => {
  25. const children: any[] = [];
  26. for (let j = 0; j < 4; j++) {
  27. children.push({
  28. id: `${index}-${j}`,
  29. type: '1',
  30. name: '@ctitle(5,15)',
  31. icon: 'ion:document',
  32. orderNo: j + 1,
  33. createTime: '@datetime',
  34. 'status|1': ['0', '1'],
  35. parentMenu: `${index}`,
  36. children: (() => {
  37. const children: any[] = [];
  38. for (let k = 0; k < 4; k++) {
  39. children.push({
  40. id: `${index}-${j}-${k}`,
  41. type: '2',
  42. name: '@ctitle(5,15)' + (j + 1) + '-' + (k + 1),
  43. icon: '',
  44. orderNo: j + 1,
  45. createTime: '@datetime',
  46. 'status|1': ['0', '1'],
  47. parentMenu: `${index}-${j}`,
  48. children: undefined,
  49. });
  50. }
  51. return children;
  52. })(),
  53. });
  54. }
  55. return children;
  56. })(),
  57. });
  58. }
  59. return result;
  60. })();
  61. export default [
  62. {
  63. url: '/zfb-api/zfb/product/category',
  64. timeout: 1000,
  65. method: 'get',
  66. response: ({ query }) => {
  67. const { page = 1, pageSize = 20 } = query;
  68. return resultPageSuccess(page, pageSize, categoryList);
  69. },
  70. },
  71. ] as MockMethod[];