From 0c191531568008b042d911f21fa7b093968285c1 Mon Sep 17 00:00:00 2001 From: YoYo Date: Wed, 8 Apr 2026 20:27:03 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A2=9E=E5=BC=BA=E5=AD=98=E4=B8=BA?= =?UTF-8?q?=E6=88=91=E7=9A=84=E8=B0=83=E8=AF=95=E6=97=A5=E5=BF=97=E5=92=8C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=8F=90=E7=A4=BA=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=A9=BA=E5=90=8D=E7=A7=B0=E9=9D=99=E9=BB=98=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 区分「取消」(null) 和「清空名称后确认」(空字符串) 两种情况 前者静默返回,后者提示「请输入配方名称」 - 添加 console.log/error 方便在浏览器控制台定位问题 - 成功 toast 改为「已保存!可在「配方查询 → 我的配方」查看」提示去向 - 错误 toast 延长至 3s,并显示 status code - saveRecipe:loadRecipes 失败不再抛出,保证保存成功后不误报失败 Co-Authored-By: Claude Sonnet 4.6 --- .../src/components/RecipeDetailOverlay.vue | 21 +++++++++++++------ frontend/src/stores/recipes.js | 7 ++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/RecipeDetailOverlay.vue b/frontend/src/components/RecipeDetailOverlay.vue index da08c3d..02c8d27 100644 --- a/frontend/src/components/RecipeDetailOverlay.vue +++ b/frontend/src/components/RecipeDetailOverlay.vue @@ -672,17 +672,26 @@ async function saveToDiary() { return } const name = await showPrompt('保存为我的配方,名称:', recipe.value.name) - if (!name) return + // null = user cancelled (clicked 取消) + if (name === null) return + // empty string = user cleared the name field + if (!name.trim()) { + ui.showToast('请输入配方名称') + return + } try { - await recipesStore.saveRecipe({ - name, + const payload = { + name: name.trim(), note: recipe.value.note || '', ingredients: recipe.value.ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })), tags: recipe.value.tags || [], - }) - ui.showToast('已保存到「我的配方」') + } + console.log('[saveToDiary] saving recipe:', payload) + await recipesStore.saveRecipe(payload) + ui.showToast('已保存!可在「配方查询 → 我的配方」查看') } catch (e) { - ui.showToast('保存失败: ' + (e?.message || '未知错误')) + console.error('[saveToDiary] failed:', e) + ui.showToast('保存失败:' + (e?.message || e?.status || '未知错误'), 3000) } } diff --git a/frontend/src/stores/recipes.js b/frontend/src/stores/recipes.js index a4ce180..c8f8291 100644 --- a/frontend/src/stores/recipes.js +++ b/frontend/src/stores/recipes.js @@ -53,7 +53,12 @@ export const useRecipesStore = defineStore('recipes', () => { return data } else { const data = await api.post('/api/recipes', recipe) - await loadRecipes() + // Refresh list; if refresh fails, still return success (recipe was saved) + try { + await loadRecipes() + } catch (e) { + console.warn('[saveRecipe] loadRecipes failed after save:', e) + } return data } }