fix: 翻译保存修复 — 去掉version检查 + 保存后重新加载数据
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 1m29s

根因: PUT /api/recipes/{id} 传了 version 字段导致 409 冲突
(version 不匹配时后端拒绝),但修改 en_name 不需要 version 检查

修复:
- 保存 recipe en_name 时不传 version(后端只在 version 存在时才检查)
- 保存后 loadRecipes + loadOils 刷新数据
- 下次打开配方卡片读到最新的 en_name
- 精油价目页也同步更新(loadOils 刷新 oilsMeta.enName)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-09 16:56:45 +00:00
parent e04d572f27
commit 9dbaf95839

View File

@@ -611,16 +611,17 @@ async function applyTranslation() {
showTranslationEditor.value = false
let saved = 0
// 1. Save recipe English name
// 1. Save recipe English name (no version check — only updating en_name)
if (recipe.value._id && customRecipeNameEn.value) {
try {
await api.put(`/api/recipes/${recipe.value._id}`, {
en_name: customRecipeNameEn.value,
version: recipe.value._version,
})
recipe.value.en_name = customRecipeNameEn.value
saved++
} catch {}
} catch (e) {
console.error('Save recipe en_name failed:', e)
}
}
// 2. Save each oil's English name to oils table (syncs with oil reference page)
@@ -639,9 +640,16 @@ async function applyTranslation() {
}
}
if (saved > 0) ui.showToast(`翻译已保存(${saved}项)` + (failed > 0 ? `${failed}项失败` : ''))
else if (failed > 0) ui.showToast(`保存失败 ${failed}`)
else ui.showToast('没有修改')
if (saved > 0) {
ui.showToast(`翻译已保存(${saved}项)` + (failed > 0 ? `${failed}项失败` : ''))
// Reload data so next open shows updated names
recipesStore.loadRecipes()
oilsStore.loadOils()
} else if (failed > 0) {
ui.showToast(`保存失败 ${failed}`)
} else {
ui.showToast('没有修改')
}
cardImageUrl.value = null
nextTick(() => generateCardImage())