index.ts 5.0 KB

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