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

- editRecipe不再直接引用store中的recipe对象(避免副作用)
- 保存时如果成分为空,弹出确认提示防止误操作
- 标签筛选时自动展开配方列表

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 21:03:35 +00:00
parent f2c95985cf
commit 49aa5a0f3c

View File

@@ -744,7 +744,7 @@ function calcDilutionFromIngs() {
}
function editRecipe(recipe) {
editingRecipe.value = recipe
editingRecipe.value = { _id: recipe._id, _version: recipe._version, name: recipe.name }
formName.value = recipe.name
const ings = recipe.ingredients || []
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) {
// 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 = {
_id: editingRecipe.value._id,
_version: editingRecipe.value._version,
name: formName.value.trim(),
ingredients: cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops })),
ingredients: mappedIngs,
note: formNote.value,
tags: formTags.value,
}