import { MockMethod } from 'vite-plugin-mock'; import { mock, Random } from 'mockjs'; import { resultPageSuccess } from '../_util'; Random.extend({ phone: function () { const phonePrefixs = ['132', '135', '189']; // 自己写前缀哈 return this.pick(phonePrefixs) + mock(/\d{8}/); //Number() }, }); // console.log(Random.phone()); // 生成 1 - 10 个 随机手机号码 const categoryList = (() => { const result: any[] = []; for (let index = 0; index < 20; index++) { result.push({ id: `${index}`, icon: ['ion:layers-outline', 'ion:git-compare-outline', 'ion:tv-outline'][index], component: 'LAYOUT', name: '@ctitle(5,15)', type: '0', orderNo: index + 1, createTime: '@datetime', 'status|1': ['0', '0', '1'], children: (() => { const children: any[] = []; for (let j = 0; j < 4; j++) { children.push({ id: `${index}-${j}`, type: '1', name: '@ctitle(5,15)', icon: 'ion:document', orderNo: j + 1, createTime: '@datetime', 'status|1': ['0', '1'], parentMenu: `${index}`, children: (() => { const children: any[] = []; for (let k = 0; k < 4; k++) { children.push({ id: `${index}-${j}-${k}`, type: '2', name: '@ctitle(5,15)' + (j + 1) + '-' + (k + 1), icon: '', orderNo: j + 1, createTime: '@datetime', 'status|1': ['0', '1'], parentMenu: `${index}-${j}`, children: undefined, }); } return children; })(), }); } return children; })(), }); } return result; })(); export default [ { url: '/zfb-api/zfb/product/category', timeout: 1000, method: 'get', response: ({ query }) => { const { page = 1, pageSize = 20 } = query; return resultPageSuccess(page, pageSize, categoryList); }, }, ] as MockMethod[];