ModifyConfigItem.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <template>
  2. <el-dialog
  3. class="modify-black-item"
  4. :visible.sync="modalIsShow"
  5. :title="title"
  6. top="10vh"
  7. width="600px"
  8. :close-on-click-modal="false"
  9. :close-on-press-escape="false"
  10. append-to-body
  11. @open="visibleChange"
  12. >
  13. <el-form
  14. ref="modalFormComp"
  15. :model="modalForm"
  16. :rules="rules"
  17. label-width="120px"
  18. >
  19. <el-form-item prop="configKey" label="参数名称:">
  20. <span v-if="isEdit">{{ modalForm.configKey }}</span>
  21. <el-input
  22. v-else
  23. v-model.trim="modalForm.configKey"
  24. placeholder="请输入参数名称"
  25. clearable
  26. ></el-input>
  27. </el-form-item>
  28. <el-form-item prop="configValue" label="参数值:">
  29. <el-input
  30. v-model.trim="modalForm.configValue"
  31. placeholder="请输入参数值"
  32. clearable
  33. ></el-input>
  34. </el-form-item>
  35. <el-form-item prop="configName" label="描述:">
  36. <el-input
  37. v-model.trim="modalForm.configName"
  38. placeholder="请输入描述"
  39. clearable
  40. ></el-input>
  41. </el-form-item>
  42. </el-form>
  43. <div slot="footer">
  44. <el-button type="primary" :disabled="isSubmit" @click="submit"
  45. >确认</el-button
  46. >
  47. <el-button @click="cancel">取消</el-button>
  48. </div>
  49. </el-dialog>
  50. </template>
  51. <script>
  52. import { objAssign } from "@/utils/utils";
  53. import { saveSystemConfig } from "@/api/system";
  54. const initModalForm = {
  55. id: null,
  56. configKey: "", //参数名称
  57. configName: "", //描述
  58. configValue: "", //参数值,
  59. enable: null,
  60. };
  61. export default {
  62. name: "modify-config-item",
  63. props: {
  64. instance: {
  65. type: Object,
  66. default() {
  67. return {};
  68. },
  69. },
  70. },
  71. computed: {
  72. isEdit() {
  73. return !!this.instance.id;
  74. },
  75. title() {
  76. return (this.isEdit ? "编辑" : "新增") + "系统参数";
  77. },
  78. },
  79. data() {
  80. return {
  81. modalIsShow: false,
  82. isSubmit: false,
  83. modalForm: { ...initModalForm },
  84. rules: {
  85. configKey: [
  86. {
  87. required: true,
  88. message: "请设置参数名称",
  89. trigger: "change",
  90. },
  91. {
  92. message: "参数名称不能超过100个字",
  93. max: 100,
  94. trigger: "change",
  95. },
  96. ],
  97. configValue: [
  98. {
  99. required: true,
  100. message: "请设置参数值",
  101. trigger: "change",
  102. },
  103. {
  104. message: "参数值不能超过200个字",
  105. max: 200,
  106. trigger: "change",
  107. },
  108. ],
  109. configName: [
  110. {
  111. required: true,
  112. message: "请输入描述",
  113. trigger: "change",
  114. },
  115. {
  116. message: "描述不能超过100个字",
  117. max: 100,
  118. trigger: "change",
  119. },
  120. ],
  121. },
  122. };
  123. },
  124. methods: {
  125. initData(val) {
  126. if (val.id) {
  127. this.modalForm = objAssign(initModalForm, val);
  128. } else {
  129. this.modalForm = { ...initModalForm };
  130. }
  131. },
  132. visibleChange() {
  133. this.initData(this.instance);
  134. },
  135. cancel() {
  136. this.modalIsShow = false;
  137. },
  138. open() {
  139. this.modalIsShow = true;
  140. },
  141. async submit() {
  142. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  143. if (!valid) return;
  144. if (this.isSubmit) return;
  145. this.isSubmit = true;
  146. let datas = { ...this.modalForm };
  147. const data = await saveSystemConfig(datas).catch(() => {});
  148. this.isSubmit = false;
  149. if (!data) return;
  150. this.$message.success(this.title + "成功!");
  151. this.$emit("modified");
  152. this.cancel();
  153. },
  154. },
  155. };
  156. </script>