editConfig.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="system-edit-dic-container">
  3. <el-dialog :title="(ruleForm.configId!==0?'修改':'添加')+'参数'" v-model="isShowDialog" width="769px">
  4. <el-form :model="ruleForm" ref="formRef" :rules="rules" label-width="90px">
  5. <el-form-item label="参数名称" prop="configName">
  6. <el-input v-model="ruleForm.configName" placeholder="请输入参数名称" />
  7. </el-form-item>
  8. <el-form-item label="参数键名" prop="configKey">
  9. <el-input v-model="ruleForm.configKey" placeholder="请输入参数键名" />
  10. </el-form-item>
  11. <!-- 字典类型下拉框 -->
  12. <el-form-item label="字典分类" prop="moduleClassify">
  13. <el-select v-model="ruleForm.moduleClassify" placeholder="字典分类" clearable style="width: 240px">
  14. <el-option v-for="dict in param_class_type" :label="dict.label" :value="dict.value" />
  15. </el-select>
  16. </el-form-item>
  17. <el-form-item label="参数键值" prop="configValue">
  18. <el-input v-model="ruleForm.configValue" placeholder="请输入参数键值" />
  19. </el-form-item>
  20. <el-form-item label="系统内置" prop="configType">
  21. <el-radio-group v-model="ruleForm.configType">
  22. <el-radio v-for="dict in sysYesNoOptions" :key="dict.value" :label="Number(dict.value)">{{dict.label}}</el-radio>
  23. </el-radio-group>
  24. </el-form-item>
  25. <el-form-item label="备注" prop="remark">
  26. <el-input v-model="ruleForm.remark" type="textarea" placeholder="请输入内容" />
  27. </el-form-item>
  28. </el-form>
  29. <template #footer>
  30. <span class="dialog-footer">
  31. <el-button @click="onCancel">取 消</el-button>
  32. <el-button type="primary" @click="onSubmit">{{ruleForm.configId!==0?'修 改':'添 加'}}</el-button>
  33. </span>
  34. </template>
  35. </el-dialog>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. import { reactive, toRefs, defineComponent, ref, unref, getCurrentInstance,} from 'vue';
  40. import { ElMessage } from 'element-plus';
  41. import api from '/@/api/system';
  42. interface RuleFormState {
  43. configId: number;
  44. configName: string;
  45. configKey: string;
  46. configValue: string;
  47. configType: number;
  48. remark: string;
  49. moduleClassify:string; // 字典分类
  50. }
  51. interface DicState {
  52. isShowDialog: boolean;
  53. ruleForm: RuleFormState;
  54. rules: {};
  55. }
  56. const baseForm: RuleFormState = {
  57. configId: 0,
  58. configName: '',
  59. configKey: '',
  60. configValue: '',
  61. configType: 0,
  62. remark: '',
  63. moduleClassify: '',
  64. }
  65. export default defineComponent({
  66. name: 'systemEditDicData',
  67. props: {
  68. sysYesNoOptions: {
  69. type: Array,
  70. default: () => [],
  71. },
  72. },
  73. setup(prop, { emit }) {
  74. const { proxy } = getCurrentInstance() as any;
  75. const { param_class_type } = proxy.useDict('param_class_type'); // 获取字典分类
  76. const formRef = ref<HTMLElement | null>(null);
  77. const state = reactive<DicState>({
  78. isShowDialog: false,
  79. ruleForm: {
  80. ...baseForm
  81. },
  82. rules: {
  83. configName: [{ required: true, message: '参数名称不能为空', trigger: 'change' }],
  84. configKey: [{ required: true, message: '参数键名不能为空', trigger: 'change' }],
  85. moduleClassify: [{ required: true, message: '字典分类不能为空', trigger: 'change' }],
  86. configValue: [{ required: true, message: '参数键值不能为空', trigger: 'change' }],
  87. },
  88. });
  89. // 打开弹窗
  90. const openDialog = (row: RuleFormState | null) => {
  91. resetForm();
  92. if (row) {
  93. state.ruleForm = row;
  94. api.config.detail(row.configId).then((res: any) => {
  95. const data: RuleFormState = res.data;
  96. state.ruleForm = data;
  97. });
  98. }
  99. state.isShowDialog = true;
  100. };
  101. const resetForm = () => {
  102. state.ruleForm = {
  103. ...baseForm
  104. };
  105. };
  106. // 关闭弹窗
  107. const closeDialog = () => {
  108. state.isShowDialog = false;
  109. };
  110. // 取消
  111. const onCancel = () => {
  112. closeDialog();
  113. };
  114. // 新增
  115. const onSubmit = () => {
  116. const formWrap = unref(formRef) as any;
  117. if (!formWrap) return;
  118. formWrap.validate((valid: boolean) => {
  119. if (valid) {
  120. if (state.ruleForm.configId !== 0) {
  121. //修改
  122. api.config.edit(state.ruleForm).then(() => {
  123. ElMessage.success('参数修改成功');
  124. closeDialog(); // 关闭弹窗
  125. emit('dataList');
  126. });
  127. } else {
  128. //添加
  129. api.config.add(state.ruleForm).then(() => {
  130. ElMessage.success('参数添加成功');
  131. closeDialog(); // 关闭弹窗
  132. emit('dataList');
  133. });
  134. }
  135. }
  136. });
  137. };
  138. return {
  139. openDialog,
  140. closeDialog,
  141. onCancel,
  142. onSubmit,
  143. formRef,
  144. ...toRefs(state),
  145. param_class_type,
  146. };
  147. },
  148. });
  149. </script>