fix: 审核同名配方流程优化
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 55s

- 一模一样:提示忽略,确认后删除重复,从待审核消失
- 不一样:显示对比,改名后采纳 / 放弃(删除并从待审核消失)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 19:05:51 +00:00
parent 3adcfc1169
commit 8a7fb75b75

View File

@@ -1275,29 +1275,42 @@ async function approveRecipe(recipe) {
const dup = recipeStore.recipes.find(r => r.name === recipe.name && r._id !== recipe._id) const dup = recipeStore.recipes.find(r => r.name === recipe.name && r._id !== recipe._id)
if (dup) { if (dup) {
if (recipesIdentical(recipe, dup)) { if (recipesIdentical(recipe, dup)) {
ui.showToast('公共配方库中已有一模一样的配方「' + recipe.name + '」,无需重复采纳') // Identical — delete this duplicate silently
const ok = await showConfirm(`公共配方库中已有一模一样的配方「${recipe.name}」,忽略这条?`)
if (!ok) return
try {
await api(`/api/recipes/${recipe._id}/reject`, { method: 'POST', body: '{}' })
await recipeStore.loadRecipes()
ui.showToast('已忽略重复配方')
} catch { ui.showToast('操作失败') }
return return
} }
// Different content, show comparison // Different content
const msg = `公共配方库中已有同名配方「${recipe.name}」但内容不同:\n\n` + const msg = `已有同名配方「${recipe.name}」但内容不同:\n\n` +
`已有:${formatIngsCompare(dup.ingredients)}\n` + `已有:${formatIngsCompare(dup.ingredients)}\n` +
`新的:${formatIngsCompare(recipe.ingredients)}\n\n` + `新的:${formatIngsCompare(recipe.ingredients)}`
`点击"采纳"直接采纳,或"改名"修改新配方名称后采纳` const action = await showConfirm(msg, { okText: '改名后采纳', cancelText: '放弃' })
const action = await showConfirm(msg, { okText: '采纳', cancelText: '改名' })
if (!action) { if (!action) {
// User wants to rename // User chose to discard
const newName = await showPrompt('请输入新名称:', recipe.name)
if (!newName || !newName.trim()) return
try { try {
await api(`/api/recipes/${recipe._id}`, { await api(`/api/recipes/${recipe._id}/reject`, { method: 'POST', body: JSON.stringify({ reason: '与已有同名配方重复' }) })
method: 'PUT', await recipeStore.loadRecipes()
body: JSON.stringify({ name: newName.trim() }), ui.showToast('已放弃')
}) } catch { ui.showToast('操作失败') }
recipe.name = newName.trim() return
} catch { }
ui.showToast('改名失败') // User wants to rename
return const newName = await showPrompt('请输入新名称:', recipe.name)
} if (!newName || !newName.trim()) return
try {
await api(`/api/recipes/${recipe._id}`, {
method: 'PUT',
body: JSON.stringify({ name: newName.trim() }),
})
recipe.name = newName.trim()
} catch {
ui.showToast('改名失败')
return
} }
} }
try { try {