fix: 增强存为我的调试日志和错误提示,修复空名称静默失败问题
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m23s

- 区分「取消」(null) 和「清空名称后确认」(空字符串) 两种情况
  前者静默返回,后者提示「请输入配方名称」
- 添加 console.log/error 方便在浏览器控制台定位问题
- 成功 toast 改为「已保存!可在「配方查询 → 我的配方」查看」提示去向
- 错误 toast 延长至 3s,并显示 status code
- saveRecipe:loadRecipes 失败不再抛出,保证保存成功后不误报失败

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-08 20:27:03 +00:00
parent 66766197a4
commit 0c19153156
2 changed files with 21 additions and 7 deletions

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