feat: 配方卡片加入上传个人二维码功能 #5

Merged
hera merged 23 commits from feature/qr-upload-hint into main 2026-04-08 22:09:30 +00:00
2 changed files with 21 additions and 7 deletions
Showing only changes of commit 0c19153156 - Show all commits

View File

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

View File

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