From bdc815a39ddbdd023fdff91d32dac5003f341d2e Mon Sep 17 00:00:00 2001 From: aeizzz Date: Thu, 9 Mar 2023 08:55:23 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20Fixing=20a=20bug.=20=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E7=AE=A1=E7=90=86=09=E5=8F=82=E6=95=B0=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=B9=82=E7=AD=89=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/admin/param.ts | 41 +++++++++++++++++++++++++++- src/views/admin/param/form.vue | 47 +++++++++++++++++++++------------ src/views/admin/param/index.vue | 6 +++++ 3 files changed, 76 insertions(+), 18 deletions(-) diff --git a/src/api/admin/param.ts b/src/api/admin/param.ts index 150e261f..c39c07d9 100644 --- a/src/api/admin/param.ts +++ b/src/api/admin/param.ts @@ -1,4 +1,5 @@ import request from '/@/utils/request'; +import { getObjDetails } from '/@/api/admin/tenant'; export function fetchList(query?: Object) { return request({ @@ -18,7 +19,7 @@ export function addObj(obj?: Object) { export function getObj(id?: string) { return request({ - url: '/admin/param/' + id, + url: '/admin/param/details/' + id, method: 'get', }); } @@ -45,3 +46,41 @@ export function refreshCache() { method: 'put', }); } + +export function getObjDetails(obj?: object) { + return request({ + url: '/admin/param/details', + method: 'get', + params: obj, + }); +} + +export function validateParamsCode(rule: any, value: any, callback: any, isEdit: boolean) { + if (isEdit) { + return callback(); + } + + getObjDetails({ publicKey: value }).then((response) => { + const result = response.data; + if (result !== null) { + callback(new Error('参数编码已经存在')); + } else { + callback(); + } + }); +} + +export function validateParamsName(rule: any, value: any, callback: any, isEdit: boolean) { + if (isEdit) { + return callback(); + } + + getObjDetails({ publicName: value }).then((response) => { + const result = response.data; + if (result !== null) { + callback(new Error('参数名称已经存在')); + } else { + callback(); + } + }); +} diff --git a/src/views/admin/param/form.vue b/src/views/admin/param/form.vue index 0495f8b6..9bb6cc3a 100644 --- a/src/views/admin/param/form.vue +++ b/src/views/admin/param/form.vue @@ -2,39 +2,39 @@ - + - + - + - + - - - + + {{ item.label }} + - + - + @@ -42,11 +42,11 @@ - + - - - + + {{ item.label }} + @@ -64,7 +64,7 @@ // 定义子组件向父组件传值/事件 import { useDict } from '/@/hooks/dict'; import { useMessage } from '/@/hooks/message'; -import { addObj, getObj, putObj } from '/@/api/admin/param'; +import { addObj, getObj, putObj, validateParamsCode, validateParamsName } from '/@/api/admin/param'; import { useI18n } from 'vue-i18n'; import { rule } from '/@/utils/validate'; @@ -86,20 +86,33 @@ const form = reactive({ publicValue: '', status: '0', validateCode: '', - publicType: '', + publicType: '0', systemFlag: '0', }); // 定义校验规则 const dataRules = reactive({ - publicName: [{ required: true, message: '名称不能为空', trigger: 'blur' }], + publicName: [ + { required: true, message: '名称不能为空', trigger: 'blur' }, + { + validator: (rule: any, value: any, callback: any) => { + validateParamsName(rule, value, callback, form.publicId !== ''); + }, + trigger: 'blur', + }, + ], publicKey: [ { required: true, message: '参数键不能为空', trigger: 'blur' }, { validator: rule.validatorLowercase, trigger: 'blur' }, + { + validator: (rule: any, value: any, callback: any) => { + validateParamsCode(rule, value, callback, form.publicId !== ''); + }, + trigger: 'blur', + }, ], publicValue: [{ required: true, message: '参数值不能为空', trigger: 'blur' }], status: [{ required: true, message: '状态不能为空', trigger: 'blur' }], - validateCode: [{ required: true, message: '编码不能为空', trigger: 'blur' }], publicType: [{ required: true, message: '类型不能为空', trigger: 'blur' }], systemFlag: [{ required: true, message: '类型不能为空', trigger: 'blur' }], }); diff --git a/src/views/admin/param/index.vue b/src/views/admin/param/index.vue index faec9dbc..dab90fa7 100644 --- a/src/views/admin/param/index.vue +++ b/src/views/admin/param/index.vue @@ -3,6 +3,12 @@
+ + + + + +