fix: 保存配方卡片所有英文翻译(含精油名称)
Some checks failed
Test / unit-test (push) Successful in 7s
Test / build-check (push) Successful in 3s
Test / e2e-test (push) Failing after 1m19s
PR Preview / test (pull_request) Has been skipped
PR Preview / teardown-preview (pull_request) Successful in 14s
PR Preview / deploy-preview (pull_request) Has been skipped

之前保存翻译时只保存了配方名的 en_name,精油的自定义英文名
(customOilNameEn)没有持久化,刷新后丢失。

- backend: recipes 表新增 en_oils(JSON 字符串)列
- RecipeUpdate 模型增加 en_oils 字段,update_recipe 写入 DB
- 所有 SELECT 语句补上 en_oils,_recipe_to_dict 返回该字段
- frontend: applyTranslation() 同时提交 en_oils
- onMounted 优先从 r.en_oils 还原精油译名,再 fallback 静态表
- recipes store 映射 en_oils 字段

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-08 19:57:52 +00:00
committed by Hera Zhao
parent dcf516f2de
commit 42aefaab17
4 changed files with 19 additions and 10 deletions

View File

@@ -576,11 +576,12 @@ function copyText() {
async function applyTranslation() {
showTranslationEditor.value = false
// Persist en_name to backend
if (recipe.value._id && customRecipeNameEn.value) {
// Persist en_name and en_oils to backend
if (recipe.value._id) {
try {
await api.put(`/api/recipes/${recipe.value._id}`, {
en_name: customRecipeNameEn.value,
en_oils: JSON.stringify(customOilNameEn.value),
version: recipe.value._version,
})
ui.showToast('翻译已保存')
@@ -708,9 +709,10 @@ onMounted(() => {
editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops }))
// Init translation defaults
customRecipeNameEn.value = r.en_name || recipeNameEn(r.name)
const savedOilMap = r.en_oils ? (() => { try { return JSON.parse(r.en_oils) } catch { return {} } })() : {}
const enMap = {}
;(r.ingredients || []).forEach(ing => {
enMap[ing.oil] = oilEn(ing.oil) || ing.oil
enMap[ing.oil] = savedOilMap[ing.oil] || oilEn(ing.oil) || ing.oil
})
customOilNameEn.value = enMap

View File

@@ -17,6 +17,7 @@ export const useRecipesStore = defineStore('recipes', () => {
_version: r._version ?? r.version ?? 1,
name: r.name,
en_name: r.en_name ?? '',
en_oils: r.en_oils ?? '{}',
note: r.note ?? '',
tags: r.tags ?? [],
ingredients: (r.ingredients ?? []).map((ing) => ({