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
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:
@@ -672,17 +672,26 @@ async function saveToDiary() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const name = await showPrompt('保存为我的配方,名称:', recipe.value.name)
|
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 {
|
try {
|
||||||
await recipesStore.saveRecipe({
|
const payload = {
|
||||||
name,
|
name: name.trim(),
|
||||||
note: recipe.value.note || '',
|
note: recipe.value.note || '',
|
||||||
ingredients: recipe.value.ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
|
ingredients: recipe.value.ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
|
||||||
tags: recipe.value.tags || [],
|
tags: recipe.value.tags || [],
|
||||||
})
|
}
|
||||||
ui.showToast('已保存到「我的配方」')
|
console.log('[saveToDiary] saving recipe:', payload)
|
||||||
|
await recipesStore.saveRecipe(payload)
|
||||||
|
ui.showToast('已保存!可在「配方查询 → 我的配方」查看')
|
||||||
} catch (e) {
|
} 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
|
return data
|
||||||
} else {
|
} else {
|
||||||
const data = await api.post('/api/recipes', recipe)
|
const data = await api.post('/api/recipes', recipe)
|
||||||
|
// Refresh list; if refresh fails, still return success (recipe was saved)
|
||||||
|
try {
|
||||||
await loadRecipes()
|
await loadRecipes()
|
||||||
|
} catch (e) {
|
||||||
|
console.warn('[saveRecipe] loadRecipes failed after save:', e)
|
||||||
|
}
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user