dept.mock.ts 2.7 KB

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