|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187 |
- 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 deptList = []
- 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'
- }))
- // deptList.push(Mock.mock({
- // code: '',
- // id: 1,
- // name: '@name',
- // fullname: '@cname',
- // 'pid|1': [1, 2, 3, 4, 5],
- // 'sort|+1': 0,
- // type: 1,
- // 'note|1-8': '好',
- // createTime: '@datetime',
- // updateTime: '@datetime'
- // }))
- }
- const deptList = Mock.mock({
- code: 0,
- message: '获取成功',
- type: 'success',
- data: [{
- code: 'XH212313',
- id: 1,
- name: '@name',
- fullname: '@cname',
- pid: 0,
- sort: 0,
- type: 1,
- 'note|1-8': '好',
- createTime: '@datetime',
- updateTime: '@datetime'
- },
- {
- code: 'XH212312',
- id: 2,
- name: '@name',
- fullname: '@cname',
- pid: 1,
- sort: 0,
- type: 2,
- 'note|1-8': '好',
- createTime: '@datetime',
- updateTime: '@datetime'
- },
- {
- code: 'XH212323',
- id: 3,
- name: '@name',
- fullname: '@cname',
- pid: 2,
- sort: 0,
- type: 2,
- 'note|1-8': '好',
- createTime: '@datetime',
- updateTime: '@datetime'
- },
- {
- code: 'XH212319',
- id: 4,
- name: '@name',
- fullname: '@cname',
- pid: 0,
- sort: 1,
- type: 1,
- 'note|1-8': '好',
- createTime: '@datetime',
- updateTime: '@datetime'
- },
- {
- code: 'XH212398',
- id: 5,
- name: '@name',
- fullname: '@cname',
- pid: 0,
- sort: 2,
- type: 2,
- 'note|1-8': '好',
- 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)
- }
- },
- {
- url: '/api-mock/dept/apiIndex',
- timeout: 1000,
- method: 'get',
- response: config => {
- const { page = 1, limit = 10 } = config.query
- const data = {
- list: deptList,
- page: Number(page),
- limit: Number(limit),
- total: 5
- }
- return resultSuccess(data)
- }
- }
- ]
|