import Mock from 'mockjs' import { resultSuccess } from '../_util' import { asyncRoutes } from './router.js' const routes = deepClone([...asyncRoutes]) function deepClone(source) { if (!source && typeof source !== 'object') { throw new Error('error arguments', 'deepClone') } const targetObj = source.constructor === Array ? [] : {} Object.keys(source).forEach(keys => { if (source[keys] && typeof source[keys] === 'object') { targetObj[keys] = deepClone(source[keys]) } else { targetObj[keys] = source[keys] } }) return targetObj } const menuList = [] const userList = [] const count = 100 for (let i = 0; i < count; i++) { menuList.push(Mock.mock({ title: '@name', 'type|1': ['0', '1'], 'method|1': ['put', 'post'], path: '@name', component: '@name', permission: '@name', 'status|1': ['1', '2'], sort: '@natural', 'hide|1': ['0', '1'], createTime: '@datetime' })) userList.push(Mock.mock({ code: '', avatar: '@image', username: '@name', realname: '@cname', roles: '', type: '', status: '', deptName: '', createTime: '@datetime', updateTime: '@datetime' })) } export default [ { url: '/api-mock/index/getMenuList', timeout: 1000, method: 'get', response: () => { return resultSuccess(routes) } }, { url: '/api-mock/menu/index', timeout: 1000, method: 'get', response: config => { const { page = 1, limit = 10 } = config.query const mockList = menuList.filter(item => { return true }) const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1)) return resultSuccess(List) } }, { url: '/api-mock/user/apiIndex', timeout: 1000, method: 'get', response: config => { const { page = 1, limit = 10 } = config.query const mockList = userList.filter(item => { return true }) const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1)) const data = { list: List, page: Number(page), limit: Number(limit), total: count } return resultSuccess(data) } } ]