feat: 配方卡片加入上传个人二维码功能 #5
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user