fix(edit): 清空字段能真正提交(undefined→null,避免 JSON 丢键)

清空 relation/select 时 el-* 常 emit undefined,进 submitData 后 JSON.stringify 丢键 →
后端收不到、看似'提交无效'。修:
- handleSave 编辑 diff 把值归一成 null(??null),清空 → null → 提交 → 后端置空
- FieldRelation 清空归一成 null(单)/[](多),避免 ObjectId 存 '' cast 报错
This commit is contained in:
2026-06-29 21:17:38 +08:00
parent bba08dadcc
commit 3b0887b126
3 changed files with 8 additions and 5 deletions
+4 -2
View File
@@ -334,8 +334,10 @@ async function handleSave() {
formFields.value.forEach(field => {
if (field.editable === 'readonly') return
if (field.editable === 'addOnly') return
const newValue = formData.value[field.key]
const oldValue = originalData.value[field.key]
// 清空字段值为 undefined 时,JSON.stringify 会丢键 → 后端收不到、看似"提交无效"。
// 归一成 null:既保证清空能提交(后端置空),又让"两边都空"不误判为有改动。
const newValue = formData.value[field.key] ?? null
const oldValue = originalData.value[field.key] ?? null
if (newValue === oldValue) return
submitData[field.key] = newValue
})