dept.mock.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { defineMock } from './base'
  2. export default defineMock([
  3. {
  4. url: 'dept/options',
  5. method: ['GET'],
  6. body: {
  7. code: '200',
  8. data: [
  9. {
  10. value: 1,
  11. label: '有来技术',
  12. children: [
  13. {
  14. value: 2,
  15. label: '研发部门'
  16. },
  17. {
  18. value: 3,
  19. label: '测试部门'
  20. }
  21. ]
  22. }
  23. ],
  24. message: '一切ok'
  25. }
  26. },
  27. {
  28. url: 'dept',
  29. method: ['GET'],
  30. body: {
  31. code: '200',
  32. data: [
  33. {
  34. id: 1,
  35. parentId: 0,
  36. name: '有来技术',
  37. sort: 1,
  38. status: 1,
  39. children: [
  40. {
  41. id: 2,
  42. parentId: 1,
  43. name: '研发部门',
  44. sort: 1,
  45. status: 1,
  46. children: [],
  47. createTime: null,
  48. updateTime: '2022-04-19 12:46'
  49. },
  50. {
  51. id: 3,
  52. parentId: 1,
  53. name: '测试部门',
  54. sort: 1,
  55. status: 1,
  56. children: [],
  57. createTime: null,
  58. updateTime: '2022-04-19 12:46'
  59. }
  60. ],
  61. createTime: null,
  62. updateTime: null
  63. }
  64. ],
  65. message: '一切ok'
  66. }
  67. },
  68. // 新增部门
  69. {
  70. url: 'dept',
  71. method: ['POST'],
  72. body({ body }) {
  73. return {
  74. code: '200',
  75. data: null,
  76. message: '新增部门' + body.name + '成功'
  77. }
  78. }
  79. },
  80. // 获取部门表单数据
  81. {
  82. url: 'dept/:id/form',
  83. method: ['GET'],
  84. body: ({ params }) => {
  85. return {
  86. code: '200',
  87. data: deptMap[params.id],
  88. message: '一切ok'
  89. }
  90. }
  91. },
  92. // 修改部门
  93. {
  94. url: 'dept/:id',
  95. method: ['PUT'],
  96. body({ body }) {
  97. return {
  98. code: '200',
  99. data: null,
  100. message: '修改部门' + body.name + '成功'
  101. }
  102. }
  103. },
  104. // 删除部门
  105. {
  106. url: 'dept/:id',
  107. method: ['DELETE'],
  108. body({ params }) {
  109. return {
  110. code: '200',
  111. data: null,
  112. message: '删除部门' + params.id + '成功'
  113. }
  114. }
  115. }
  116. ])
  117. // 部门映射表数据
  118. const deptMap: Record<string, any> = {
  119. 1: {
  120. id: 1,
  121. name: '有来技术',
  122. parentId: 0,
  123. status: 1,
  124. sort: 1
  125. },
  126. 2: {
  127. id: 2,
  128. name: '研发部门',
  129. parentId: 1,
  130. status: 1,
  131. sort: 1
  132. },
  133. 3: {
  134. id: 3,
  135. name: '测试部门',
  136. parentId: 1,
  137. status: 1,
  138. sort: 1
  139. }
  140. }