refactor(CheckinDetailPage): 使用 Object.assign 更新目标对象并优化选中列表检查
用 Object.assign 替代展开运算符来保持对象引用 优化选中列表的检查逻辑,支持 id 和 name 匹配
Showing
1 changed file
with
8 additions
and
7 deletions
| ... | @@ -391,17 +391,18 @@ const confirmAddTarget = async (formFields) => { | ... | @@ -391,17 +391,18 @@ const confirmAddTarget = async (formFields) => { |
| 391 | // 编辑模式或确认模式 | 391 | // 编辑模式或确认模式 |
| 392 | const index = targetList.value.findIndex(t => t === editingTarget.value) | 392 | const index = targetList.value.findIndex(t => t === editingTarget.value) |
| 393 | if (index > -1) { | 393 | if (index > -1) { |
| 394 | - // 更新对象 | 394 | + // 更新对象 (使用 Object.assign 保持引用) |
| 395 | - targetList.value[index] = { ...targetList.value[index], ...formData } | 395 | + Object.assign(targetList.value[index], formData) |
| 396 | + | ||
| 396 | if (isConfirmMode.value) { | 397 | if (isConfirmMode.value) { |
| 397 | targetList.value[index].has_confirmed = true // 标记为已确认 | 398 | targetList.value[index].has_confirmed = true // 标记为已确认 |
| 398 | } | 399 | } |
| 399 | 400 | ||
| 400 | - // 如果在选中列表中,也需要更新 | 401 | + // 检查是否在选中列表中 |
| 401 | - const selectedIndex = selectedTargets.value.findIndex(t => t.id === editingTarget.value.id) | 402 | + const selectedIndex = selectedTargets.value.findIndex(t => |
| 402 | - if (selectedIndex > -1) { | 403 | + (editingTarget.value.id && t.id && t.id == editingTarget.value.id) || |
| 403 | - selectedTargets.value[selectedIndex] = { ...selectedTargets.value[selectedIndex], ...formData } | 404 | + (!editingTarget.value.id && t.name === editingTarget.value.name) |
| 404 | - } | 405 | + ) |
| 405 | 406 | ||
| 406 | // 如果是确认模式,确认后自动加入选中列表 | 407 | // 如果是确认模式,确认后自动加入选中列表 |
| 407 | if (isConfirmMode.value && selectedIndex === -1) { | 408 | if (isConfirmMode.value && selectedIndex === -1) { | ... | ... |
-
Please register or login to post a comment