dictTenantDtl.vue 5.5 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. getList();
  36. });
  37. const sourceList = ref({
  38. data: [],
  39. pagination: {
  40. total: 3,
  41. pageNum: 1,
  42. pageSize: 10,
  43. },
  44. });
  45. let dialogVisible = ref(false);
  46. let modalType = ref("add");
  47. let rules = ref({
  48. dictKey: [{ required: true, message: "请输入key", trigger: "blur" }],
  49. dictValue: [{ required: true, message: "请输入val", trigger: "blur" }],
  50. sort: [{ required: true, message: "请输入排序", trigger: "blur" }],
  51. });
  52. const config = computed(() => {
  53. return [
  54. {
  55. attrs: {
  56. label: "键",
  57. prop: "dictKey",
  58. },
  59. },
  60. {
  61. attrs: {
  62. label: "值",
  63. prop: "dictValue",
  64. },
  65. },
  66. {
  67. attrs: {
  68. label: "排序",
  69. prop: "sort",
  70. },
  71. },
  72. {
  73. attrs: {
  74. label: "操作",
  75. width: "200",
  76. align: "right",
  77. },
  78. // 渲染 el-button,一般用在最后一列。
  79. renderHTML(row) {
  80. if (row.type == 2) {
  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("/dictTenantData/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. });
  128. let formData = reactive({
  129. data: {},
  130. treeData: [],
  131. });
  132. const formOption = reactive({
  133. inline: true,
  134. labelWidth: 100,
  135. itemWidth: 100,
  136. rules: [],
  137. });
  138. const byform = ref(null);
  139. const formConfig = computed(() => {
  140. return [
  141. {
  142. type: "input",
  143. prop: "dictKey",
  144. label: "键",
  145. required: true,
  146. },
  147. {
  148. type: "input",
  149. prop: "dictValue",
  150. label: "值",
  151. },
  152. {
  153. label: "排序",
  154. prop: "sort",
  155. type: "input",
  156. itemType: "number",
  157. },
  158. ];
  159. });
  160. const getList = async (req) => {
  161. console.log(proxy.data.data.code);
  162. sourceList.value.pagination = {
  163. ...sourceList.value.pagination,
  164. ...req,
  165. dictCode: proxy.data.data.code,
  166. tenantId: proxy.data.data.tenantId,
  167. };
  168. loading.value = true;
  169. proxy.post("/dictTenantData/page", sourceList.value.pagination).then((message) => {
  170. sourceList.value.data = message.rows;
  171. sourceList.value.pagination.total = message.total;
  172. console.log(sourceList.value.data);
  173. setTimeout(() => {
  174. loading.value = false;
  175. }, 200);
  176. });
  177. };
  178. const openModal = () => {
  179. dialogVisible.value = true;
  180. modalType.value = "add";
  181. formData.data = {};
  182. };
  183. const submitForm = () => {
  184. console.log(byform.value);
  185. byform.value.handleSubmit(() => {
  186. submitLoading.value = true;
  187. formData.data.dictCode = proxy.data.data.code;
  188. formData.data.tenantId = proxy.data.data.tenantId;
  189. proxy
  190. .post("/dictTenantData/" + modalType.value, formData.data)
  191. .then(() => {
  192. ElMessage({
  193. message: modalType.value == "add" ? "添加成功" : "编辑成功",
  194. type: "success",
  195. });
  196. dialogVisible.value = false;
  197. submitLoading.value = false;
  198. getList();
  199. })
  200. .catch(() => {
  201. submitLoading.value = false;
  202. });
  203. });
  204. };
  205. const getDtl = (row) => {
  206. formData.data = { ...row };
  207. modalType.value = "edit";
  208. dialogVisible.value = true;
  209. };
  210. getList();
  211. </script>
  212. <style lang="scss" scoped>
  213. .tenant {
  214. padding: 20px;
  215. }
  216. </style>