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 @@
+ + + + + +