feat: 审核同名配方智能检测
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 24s
Test / e2e-test (push) Failing after 55s
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 24s
Test / e2e-test (push) Failing after 55s
- 完全相同:提示"已有一模一样的",不采纳 - 内容不同:显示两个配方成分对比,可选择直接采纳或改名后采纳 - 存为我的只检查个人配方同名 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -621,15 +621,10 @@ async function saveToDiary() {
|
||||
}
|
||||
const trimmed = name.trim()
|
||||
const dupDiary = diaryStore.userDiary.some(d => d.name === trimmed)
|
||||
const dupPublic = recipesStore.recipes.some(r => r.name === trimmed)
|
||||
if (dupDiary) {
|
||||
ui.showToast('我的配方中已有同名配方「' + trimmed + '」')
|
||||
return
|
||||
}
|
||||
if (dupPublic) {
|
||||
ui.showToast('公共配方库中已有同名配方「' + trimmed + '」')
|
||||
return
|
||||
}
|
||||
try {
|
||||
const payload = {
|
||||
name: name.trim(),
|
||||
|
||||
@@ -1210,7 +1210,46 @@ async function removeRecipe(recipe) {
|
||||
}
|
||||
}
|
||||
|
||||
function recipesIdentical(a, b) {
|
||||
if ((a.ingredients || []).length !== (b.ingredients || []).length) return false
|
||||
const aIngs = [...a.ingredients].sort((x, y) => x.oil.localeCompare(y.oil))
|
||||
const bIngs = [...b.ingredients].sort((x, y) => x.oil.localeCompare(y.oil))
|
||||
return aIngs.every((ing, i) => ing.oil === bIngs[i].oil && ing.drops === bIngs[i].drops)
|
||||
}
|
||||
|
||||
function formatIngsCompare(ings) {
|
||||
return (ings || []).map(i => `${i.oil} ${i.drops}滴`).join('、')
|
||||
}
|
||||
|
||||
async function approveRecipe(recipe) {
|
||||
const dup = recipeStore.recipes.find(r => r.name === recipe.name && r._id !== recipe._id)
|
||||
if (dup) {
|
||||
if (recipesIdentical(recipe, dup)) {
|
||||
ui.showToast('公共配方库中已有一模一样的配方「' + recipe.name + '」,无需重复采纳')
|
||||
return
|
||||
}
|
||||
// Different content, show comparison
|
||||
const msg = `公共配方库中已有同名配方「${recipe.name}」但内容不同:\n\n` +
|
||||
`已有:${formatIngsCompare(dup.ingredients)}\n` +
|
||||
`新的:${formatIngsCompare(recipe.ingredients)}\n\n` +
|
||||
`点击"采纳"直接采纳,或"改名"修改新配方名称后采纳`
|
||||
const action = await showConfirm(msg, { okText: '采纳', cancelText: '改名' })
|
||||
if (!action) {
|
||||
// User wants to rename
|
||||
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 {
|
||||
const res = await api('/api/recipes/' + recipe._id + '/adopt', { method: 'POST' })
|
||||
if (res.ok) {
|
||||
|
||||
Reference in New Issue
Block a user