fix: 防止编辑配方意外清空成分 + 编辑器不直接引用store
All checks were successful
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 14s
Test / e2e-test (push) Successful in 52s
All checks were successful
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 14s
Test / e2e-test (push) Successful in 52s
- editRecipe不再直接引用store中的recipe对象(避免副作用) - 保存时如果成分为空,弹出确认提示防止误操作 - 标签筛选时自动展开配方列表 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -744,7 +744,7 @@ function calcDilutionFromIngs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function editRecipe(recipe) {
|
function editRecipe(recipe) {
|
||||||
editingRecipe.value = recipe
|
editingRecipe.value = { _id: recipe._id, _version: recipe._version, name: recipe.name }
|
||||||
formName.value = recipe.name
|
formName.value = recipe.name
|
||||||
const ings = recipe.ingredients || []
|
const ings = recipe.ingredients || []
|
||||||
formIngredients.value = ings.filter(i => i.oil !== '椰子油').map(i => ({ ...i, _search: i.oil, _open: false }))
|
formIngredients.value = ings.filter(i => i.oil !== '椰子油').map(i => ({ ...i, _search: i.oil, _open: false }))
|
||||||
@@ -1016,12 +1016,17 @@ async function saveCurrentRecipe() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (editingRecipe.value && editingRecipe.value._id) {
|
if (editingRecipe.value && editingRecipe.value._id) {
|
||||||
// Editing an existing public recipe
|
// Editing an existing public recipe — safety check
|
||||||
|
const mappedIngs = cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops }))
|
||||||
|
if (mappedIngs.length === 0) {
|
||||||
|
const ok = await showConfirm('配方中没有精油成分,确定保存吗?这将清空所有成分。')
|
||||||
|
if (!ok) return
|
||||||
|
}
|
||||||
const payload = {
|
const payload = {
|
||||||
_id: editingRecipe.value._id,
|
_id: editingRecipe.value._id,
|
||||||
_version: editingRecipe.value._version,
|
_version: editingRecipe.value._version,
|
||||||
name: formName.value.trim(),
|
name: formName.value.trim(),
|
||||||
ingredients: cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops })),
|
ingredients: mappedIngs,
|
||||||
note: formNote.value,
|
note: formNote.value,
|
||||||
tags: formTags.value,
|
tags: formTags.value,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user