選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

index.js 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 deptList = []
  22. const count = 100
  23. for (let i = 0; i < count; i++) {
  24. menuList.push(Mock.mock({
  25. title: '@name',
  26. 'type|1': ['0', '1'],
  27. 'method|1': ['put', 'post'],
  28. path: '@name',
  29. component: '@name',
  30. permission: '@name',
  31. 'status|1': ['1', '2'],
  32. sort: '@natural',
  33. 'hide|1': ['0', '1'],
  34. createTime: '@datetime'
  35. }))
  36. userList.push(Mock.mock({
  37. code: '',
  38. avatar: '@image',
  39. username: '@name',
  40. realname: '@cname',
  41. roles: '',
  42. type: '',
  43. status: '',
  44. deptName: '',
  45. createTime: '@datetime',
  46. updateTime: '@datetime'
  47. }))
  48. // deptList.push(Mock.mock({
  49. // code: '',
  50. // id: 1,
  51. // name: '@name',
  52. // fullname: '@cname',
  53. // 'pid|1': [1, 2, 3, 4, 5],
  54. // 'sort|+1': 0,
  55. // type: 1,
  56. // 'note|1-8': '好',
  57. // createTime: '@datetime',
  58. // updateTime: '@datetime'
  59. // }))
  60. }
  61. const deptList = Mock.mock({
  62. code: 0,
  63. message: '获取成功',
  64. type: 'success',
  65. data: [{
  66. code: 'XH212313',
  67. id: 1,
  68. name: '@name',
  69. fullname: '@cname',
  70. pid: 0,
  71. sort: 0,
  72. type: 1,
  73. 'note|1-8': '好',
  74. createTime: '@datetime',
  75. updateTime: '@datetime'
  76. },
  77. {
  78. code: 'XH212312',
  79. id: 2,
  80. name: '@name',
  81. fullname: '@cname',
  82. pid: 1,
  83. sort: 0,
  84. type: 2,
  85. 'note|1-8': '好',
  86. createTime: '@datetime',
  87. updateTime: '@datetime'
  88. },
  89. {
  90. code: 'XH212323',
  91. id: 3,
  92. name: '@name',
  93. fullname: '@cname',
  94. pid: 2,
  95. sort: 0,
  96. type: 2,
  97. 'note|1-8': '好',
  98. createTime: '@datetime',
  99. updateTime: '@datetime'
  100. },
  101. {
  102. code: 'XH212319',
  103. id: 4,
  104. name: '@name',
  105. fullname: '@cname',
  106. pid: 0,
  107. sort: 1,
  108. type: 1,
  109. 'note|1-8': '好',
  110. createTime: '@datetime',
  111. updateTime: '@datetime'
  112. },
  113. {
  114. code: 'XH212398',
  115. id: 5,
  116. name: '@name',
  117. fullname: '@cname',
  118. pid: 0,
  119. sort: 2,
  120. type: 2,
  121. 'note|1-8': '好',
  122. createTime: '@datetime',
  123. updateTime: '@datetime'
  124. }]
  125. })
  126. export default [
  127. {
  128. url: '/api-mock/index/getMenuList',
  129. timeout: 1000,
  130. method: 'get',
  131. response: () => {
  132. return resultSuccess(routes)
  133. }
  134. },
  135. {
  136. url: '/api-mock/menu/index',
  137. timeout: 1000,
  138. method: 'get',
  139. response: config => {
  140. const { page = 1, limit = 10 } = config.query
  141. const mockList = menuList.filter(item => {
  142. return true
  143. })
  144. const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  145. return resultSuccess(List)
  146. }
  147. },
  148. {
  149. url: '/api-mock/user/apiIndex',
  150. timeout: 1000,
  151. method: 'get',
  152. response: config => {
  153. const { page = 1, limit = 10 } = config.query
  154. const mockList = userList.filter(item => {
  155. return true
  156. })
  157. const List = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
  158. const data = {
  159. list: List,
  160. page: Number(page),
  161. limit: Number(limit),
  162. total: count
  163. }
  164. return resultSuccess(data)
  165. }
  166. },
  167. {
  168. url: '/api-mock/dept/apiIndex',
  169. timeout: 1000,
  170. method: 'get',
  171. response: config => {
  172. const { page = 1, limit = 10 } = config.query
  173. const data = {
  174. list: deptList,
  175. page: Number(page),
  176. limit: Number(limit),
  177. total: 5
  178. }
  179. return resultSuccess(data)
  180. }
  181. }
  182. ]