dictCommonDtl.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <template>
  2. <div class="dictTenantDtl">
  3. <el-button type="primary" @click="openModal">添加</el-button>
  4. <div class="content">
  5. <byTable :source="sourceList.data" :pagination="sourceList.pagination" :config="config" :loading="loading" highlight-current-row @get-list="getList">
  6. <template #slotName="{ item }">
  7. {{ item.createTime }}
  8. </template>
  9. </byTable>
  10. </div>
  11. <el-dialog :title="modalType == 'add' ? '新增' : '编辑'" v-model="dialogVisible" width="400" v-loading="loading">
  12. <byForm :formConfig="formConfig" :formOption="formOption" v-model="formData.data" :rules="rules" ref="byform"> </byForm>
  13. <template #footer>
  14. <el-button @click="dialogVisible = false" size="large">取 消</el-button>
  15. <el-button type="primary" @click="submitForm('byform')" size="large" :loading="submitLoading"> 确 定 </el-button>
  16. </template>
  17. </el-dialog>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { ElMessage, ElMessageBox } from "element-plus";
  22. import byTable from "@/components/byTable/index";
  23. import byForm from "@/components/byForm/index";
  24. import { computed, ref, watch } from "vue";
  25. const { proxy } = getCurrentInstance();
  26. const loading = ref(false);
  27. const submitLoading = ref(false);
  28. defineProps({
  29. data: {
  30. type: Object,
  31. default: false,
  32. },
  33. });
  34. watch(proxy.data, () => {
  35. console.log(proxy.data);
  36. getList();
  37. });
  38. const sourceList = ref({
  39. data: [],
  40. pagination: {
  41. total: 3,
  42. pageNum: 1,
  43. pageSize: 10,
  44. },
  45. });
  46. let dialogVisible = ref(false);
  47. let modalType = ref("add");
  48. let rules = ref({
  49. dictKey: [{ required: true, message: "请输入key", trigger: "blur" }],
  50. dictValue: [{ required: true, message: "请输入val", trigger: "blur" }],
  51. sort: [{ required: true, message: "请输入排序", trigger: "blur" }],
  52. });
  53. const config = computed(() => {
  54. return [
  55. {
  56. attrs: {
  57. label: "键",
  58. prop: "dictKey",
  59. },
  60. },
  61. {
  62. attrs: {
  63. label: "值",
  64. prop: "dictValue",
  65. },
  66. },
  67. {
  68. attrs: {
  69. label: "排序",
  70. prop: "sort",
  71. },
  72. },
  73. {
  74. attrs: {
  75. label: "操作",
  76. width: "200",
  77. align: "right",
  78. },
  79. // 渲染 el-button,一般用在最后一列。
  80. renderHTML(row) {
  81. return [
  82. {
  83. attrs: {
  84. label: "修改",
  85. type: "primary",
  86. text: true,
  87. },
  88. el: "button",
  89. click() {
  90. getDtl(row);
  91. },
  92. },
  93. {
  94. attrs: {
  95. label: "删除",
  96. type: "danger",
  97. text: true,
  98. },
  99. el: "button",
  100. click() {
  101. // 弹窗提示是否删除
  102. ElMessageBox.confirm("此操作将删除该数据, 是否继续?", "提示", {
  103. confirmButtonText: "确定",
  104. cancelButtonText: "取消",
  105. type: "warning",
  106. }).then(() => {
  107. // 删除
  108. proxy
  109. .post("/dictCommonData/delete", {
  110. id: row.id,
  111. })
  112. .then((res) => {
  113. ElMessage({
  114. message: "删除成功",
  115. type: "success",
  116. });
  117. getList();
  118. });
  119. });
  120. },
  121. },
  122. ];
  123. },
  124. },
  125. ];
  126. });
  127. let formData = reactive({
  128. data: {},
  129. treeData: [],
  130. });
  131. const formOption = reactive({
  132. inline: true,
  133. labelWidth: 100,
  134. itemWidth: 100,
  135. rules: [],
  136. });
  137. const byform = ref(null);
  138. const formConfig = computed(() => {
  139. return [
  140. {
  141. type: "input",
  142. prop: "dictKey",
  143. label: "键",
  144. required: true,
  145. },
  146. {
  147. type: "input",
  148. prop: "dictValue",
  149. label: "值",
  150. },
  151. {
  152. label: "排序",
  153. prop: "sort",
  154. type: "input",
  155. itemType: "number",
  156. },
  157. ];
  158. });
  159. const getList = async (req) => {
  160. console.log(proxy.data.data.code);
  161. sourceList.value.pagination = {
  162. ...sourceList.value.pagination,
  163. ...req,
  164. dictCode: proxy.data.data.code,
  165. tenantId: proxy.data.data.tenantId,
  166. };
  167. loading.value = true;
  168. proxy.post("/dictCommonData/page", sourceList.value.pagination).then((message) => {
  169. console.log(message);
  170. sourceList.value.data = message.rows;
  171. sourceList.value.pagination.total = message.total;
  172. setTimeout(() => {
  173. loading.value = false;
  174. }, 200);
  175. });
  176. };
  177. const openModal = () => {
  178. dialogVisible.value = true;
  179. modalType.value = "add";
  180. formData.data = {};
  181. };
  182. const submitForm = () => {
  183. console.log(byform.value);
  184. byform.value.handleSubmit((valid) => {
  185. submitLoading.value = true;
  186. formData.data.dictCode = proxy.data.data.code;
  187. formData.data.tenantId = proxy.data.data.tenantId;
  188. proxy
  189. .post("/dictCommonData/" + modalType.value, formData.data)
  190. .then((res) => {
  191. ElMessage({
  192. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  193. type: "success",
  194. });
  195. dialogVisible.value = false;
  196. submitLoading.value = false;
  197. getList();
  198. })
  199. .catch((err) => {
  200. submitLoading.value = false;
  201. });
  202. });
  203. };
  204. const getDtl = (row) => {
  205. formData.data = { ...row };
  206. modalType.value = "edit";
  207. dialogVisible.value = true;
  208. };
  209. getList();
  210. </script>
  211. <style lang="scss" scoped>
  212. .tenant {
  213. padding: 20px;
  214. }
  215. </style>