index.mock.ts 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. import { toAnyString } from '@/utils'
  2. import Mock from 'mockjs'
  3. import { SUCCESS_CODE } from '@/constants'
  4. const departmentList: any = []
  5. const citys = ['厦门总公司', '北京分公司', '上海分公司', '福州分公司', '深圳分公司', '杭州分公司']
  6. for (let i = 0; i < 5; i++) {
  7. departmentList.push({
  8. // 部门名称
  9. departmentName: citys[i],
  10. id: toAnyString(),
  11. createTime: '@datetime',
  12. // 状态
  13. status: Mock.Random.integer(0, 1),
  14. // 备注
  15. remark: '@cword(10, 15)',
  16. children: [
  17. {
  18. // 部门名称
  19. departmentName: '研发部',
  20. id: toAnyString(),
  21. createTime: '@datetime',
  22. // 状态
  23. status: Mock.Random.integer(0, 1),
  24. // 备注
  25. remark: '@cword(10, 15)'
  26. },
  27. {
  28. // 部门名称
  29. departmentName: '产品部',
  30. id: toAnyString(),
  31. createTime: '@datetime',
  32. // 状态
  33. status: Mock.Random.integer(0, 1),
  34. // 备注
  35. remark: '@cword(10, 15)'
  36. },
  37. {
  38. // 部门名称
  39. departmentName: '运营部',
  40. id: toAnyString(),
  41. createTime: '@datetime',
  42. // 状态
  43. status: Mock.Random.integer(0, 1),
  44. // 备注
  45. remark: '@cword(10, 15)'
  46. },
  47. {
  48. // 部门名称
  49. departmentName: '市场部',
  50. id: toAnyString(),
  51. createTime: '@datetime',
  52. // 状态
  53. status: Mock.Random.integer(0, 1),
  54. // 备注
  55. remark: '@cword(10, 15)'
  56. },
  57. {
  58. // 部门名称
  59. departmentName: '销售部',
  60. id: toAnyString(),
  61. createTime: '@datetime',
  62. // 状态
  63. status: Mock.Random.integer(0, 1),
  64. // 备注
  65. remark: '@cword(10, 15)'
  66. },
  67. {
  68. // 部门名称
  69. departmentName: '客服部',
  70. id: toAnyString(),
  71. createTime: '@datetime',
  72. // 状态
  73. status: Mock.Random.integer(0, 1),
  74. // 备注
  75. remark: '@cword(10, 15)'
  76. }
  77. ]
  78. })
  79. }
  80. export default [
  81. // 列表接口
  82. {
  83. url: '/mock/department/list',
  84. method: 'get',
  85. response: () => {
  86. return {
  87. code: SUCCESS_CODE,
  88. data: {
  89. list: departmentList
  90. }
  91. }
  92. }
  93. },
  94. {
  95. url: '/mock/department/table/list',
  96. method: 'get',
  97. response: () => {
  98. return {
  99. code: SUCCESS_CODE,
  100. data: {
  101. list: departmentList,
  102. total: 5
  103. }
  104. }
  105. }
  106. },
  107. {
  108. url: '/mock/department/users',
  109. method: 'get',
  110. timeout: 1000,
  111. response: ({ query }) => {
  112. const { pageSize } = query
  113. // 根据pageSize来创建数据
  114. const mockList: any = []
  115. for (let i = 0; i < pageSize; i++) {
  116. mockList.push(
  117. Mock.mock({
  118. // 用户名
  119. username: '@cname',
  120. // 账号
  121. account: '@first',
  122. // 邮箱
  123. email: '@EMAIL',
  124. // 创建时间
  125. createTime: '@datetime',
  126. // 用户id
  127. id: toAnyString()
  128. })
  129. )
  130. }
  131. return {
  132. code: SUCCESS_CODE,
  133. data: {
  134. total: 100,
  135. list: mockList
  136. }
  137. }
  138. }
  139. },
  140. // 保存接口
  141. {
  142. url: '/mock/department/user/save',
  143. method: 'post',
  144. timeout: 1000,
  145. response: () => {
  146. return {
  147. code: SUCCESS_CODE,
  148. data: 'success'
  149. }
  150. }
  151. },
  152. // 删除接口
  153. {
  154. url: '/mock/department/user/delete',
  155. method: 'post',
  156. response: ({ body }) => {
  157. const ids = body.ids
  158. if (!ids) {
  159. return {
  160. code: 500,
  161. message: '请选择需要删除的数据'
  162. }
  163. } else {
  164. return {
  165. code: SUCCESS_CODE,
  166. data: 'success'
  167. }
  168. }
  169. }
  170. },
  171. // 保存接口
  172. {
  173. url: '/mock/department/save',
  174. method: 'post',
  175. timeout: 1000,
  176. response: () => {
  177. return {
  178. code: SUCCESS_CODE,
  179. data: 'success'
  180. }
  181. }
  182. },
  183. // 删除接口
  184. {
  185. url: '/mock/department/delete',
  186. method: 'post',
  187. response: ({ body }) => {
  188. const ids = body.ids
  189. if (!ids) {
  190. return {
  191. code: 500,
  192. message: '请选择需要删除的数据'
  193. }
  194. } else {
  195. return {
  196. code: SUCCESS_CODE,
  197. data: 'success'
  198. }
  199. }
  200. }
  201. }
  202. ]