fix: validateUnique 编辑模式下值未变时跳过重复校验,仅值改变时才检查冲突
This commit is contained in:
@ -1029,6 +1029,13 @@ const hasFormFieldPermission = (fieldName: string) => {
|
||||
const validateUnique = (rule: any, value: string, callback: any) => {
|
||||
if (!value) return callback()
|
||||
const currentId = form.id != null ? Number(form.id) : null
|
||||
// 编辑模式:如果值未改变,跳过重复校验(用户可能在编辑其他字段)
|
||||
if (dialogStatus.value === 'update' && currentId != null) {
|
||||
const self = tableData.value.find((r: any) => Number(r.id) === currentId)
|
||||
if (self && String(self[rule.field]) === value) {
|
||||
return callback() // 值未变,无需校验重复
|
||||
}
|
||||
}
|
||||
const isDuplicate = tableData.value.some((row: any) => {
|
||||
if (dialogStatus.value === 'update' && currentId != null && Number(row.id) === currentId) return false
|
||||
if (rule.field === 'serial_number' && row.serial_number === value) return true
|
||||
|
||||
Reference in New Issue
Block a user