You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.2KB

  1. import Mock from 'mockjs'
  2. import { resultSuccess } from '../_util'
  3. import { asyncRoutes } from './router.js'
  4. const routes = deepClone([...asyncRoutes])
  5. function deepClone(source) {
  6. if (!source && typeof source !== 'object') {
  7. throw new Error('error arguments', 'deepClone')
  8. }
  9. const targetObj = source.constructor === Array ? [] : {}
  10. Object.keys(source).forEach(keys => {
  11. if (source[keys] && typeof source[keys] === 'object') {
  12. targetObj[keys] = deepClone(source[keys])
  13. } else {
  14. targetObj[keys] = source[keys]
  15. }
  16. })
  17. return targetObj
  18. }
  19. const menuList = []
  20. const userList = []
  21. const count = 100
  22. for (let i = 0; i < count; i++) {
  23. menuList.push(Mock.mock({
  24. title: '@name',
  25. 'type|1': ['0', '1'],
  26. 'method|1': ['put', 'post'],
  27. path: '@name',
  28. component: '@name',
  29. permission: '@name',
  30. 'status|1': ['1', '2'],
  31. sort: '@natural',
  32. 'hide|1': ['0', '1'],
  33. createTime: '@datetime'
  34. }))
  35. userList.push(Mock.mock({
  36. code: '',
  37. avatar: '@image',
  38. username: '@name',
  39. realname: '@cname',
  40. roles: '',
  41. type: '',
  42. status: '',
  43. deptName: '',
  44. createTime: '@datetime',
  45. updateTime: '@datetime'
  46. }))
  47. }
  48. export default [
  49. {
  50. url: '/api-mock/index/getMenuList',
  51. timeout: 1000,
  52. method: 'get',
  53. response: () => {
  54. return resultSuccess(routes)
  55. }
  56. },
  57. {
  58. url: '/api-mock/menu/index',
  59. timeout: 1000,
  60. method: 'get',
  61. response: config => {
  62. const { page = 1, limit = 10 } = config.query
  63. const mockList = menuList.filter(item => {
  64. return true
  65. })
  66. const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  67. return resultSuccess(List)
  68. }
  69. },
  70. {
  71. url: '/api-mock/user/apiIndex',
  72. timeout: 1000,
  73. method: 'get',
  74. response: config => {
  75. const { page = 1, limit = 10 } = config.query
  76. const mockList = userList.filter(item => {
  77. return true
  78. })
  79. const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  80. const data = {
  81. list: List,
  82. page: Number(page),
  83. limit: Number(limit),
  84. total: count
  85. }
  86. return resultSuccess(data)
  87. }
  88. }
  89. ]