dict-data.mock.ts 2.2 KB

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