dict.mock.ts 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import { defineMock } from "./base";
  2. export default defineMock([
  3. {
  4. url: "dict/:code/options",
  5. method: ["GET"],
  6. body: ({ params }) => {
  7. const code = params.code;
  8. let list = null;
  9. if (code == "gender") {
  10. list = [
  11. {
  12. value: "1",
  13. label: "男",
  14. },
  15. {
  16. value: "2",
  17. label: "女",
  18. },
  19. {
  20. value: "0",
  21. label: "保密",
  22. },
  23. ];
  24. }
  25. return {
  26. code: "00000",
  27. data: list,
  28. msg: "一切ok",
  29. };
  30. },
  31. },
  32. {
  33. url: "dict/page",
  34. method: ["GET"],
  35. body: {
  36. code: "00000",
  37. data: {
  38. list: [
  39. {
  40. id: 1,
  41. name: "性别",
  42. code: "gender",
  43. status: 1,
  44. dictItems: [
  45. {
  46. id: 1,
  47. name: "男",
  48. value: "1",
  49. sort: 1,
  50. status: 1,
  51. },
  52. {
  53. id: 2,
  54. name: "女",
  55. value: "2",
  56. sort: 2,
  57. status: 1,
  58. },
  59. {
  60. id: 3,
  61. name: "保密",
  62. value: "0",
  63. sort: 3,
  64. status: 1,
  65. },
  66. ],
  67. },
  68. ],
  69. total: 1,
  70. },
  71. msg: "一切ok",
  72. },
  73. },
  74. // 新增字典
  75. {
  76. url: "dict",
  77. method: ["POST"],
  78. body({ body }) {
  79. return {
  80. code: "00000",
  81. data: null,
  82. msg: "新增字典" + body.name + "成功",
  83. };
  84. },
  85. },
  86. // 获取字典表单数据
  87. {
  88. url: "dict/:id/form",
  89. method: ["GET"],
  90. body: ({ params }) => {
  91. return {
  92. code: "00000",
  93. data: dictMap[params.id],
  94. msg: "一切ok",
  95. };
  96. },
  97. },
  98. // 修改字典
  99. {
  100. url: "dict/:id",
  101. method: ["PUT"],
  102. body({ body }) {
  103. return {
  104. code: "00000",
  105. data: null,
  106. msg: "修改字典" + body.name + "成功",
  107. };
  108. },
  109. },
  110. // 删除字典
  111. {
  112. url: "dict/:id",
  113. method: ["DELETE"],
  114. body({ params }) {
  115. return {
  116. code: "00000",
  117. data: null,
  118. msg: "删除字典" + params.id + "成功",
  119. };
  120. },
  121. },
  122. ]);
  123. // 字典映射表数据
  124. const dictMap: Record<string, any> = {
  125. 1: {
  126. code: "00000",
  127. data: {
  128. id: 1,
  129. name: "性别",
  130. code: "gender",
  131. status: 1,
  132. dictItems: [
  133. {
  134. id: 1,
  135. name: "男",
  136. value: "1",
  137. sort: 1,
  138. status: 1,
  139. },
  140. {
  141. id: 2,
  142. name: "女",
  143. value: "2",
  144. sort: 2,
  145. status: 1,
  146. },
  147. {
  148. id: 3,
  149. name: "未知",
  150. value: "0",
  151. sort: 3,
  152. status: 1,
  153. },
  154. ],
  155. },
  156. msg: "一切ok",
  157. },
  158. };