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 } }