fix: 智能识别配方名称 + 新增默认保存到个人配方
- 修复空格/无分隔符时配方名称无法识别的问题 - 支持"长高芳香调理8永久花10"连写格式自动分离名称 - 所有用户新增配方默认保存到个人配方(diary),不进公共库 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -520,16 +520,17 @@ async function saveCurrentRecipe() {
|
||||
}
|
||||
|
||||
const cleanIngs = validIngs.map(i => ({ oil: i.oil, drops: i.drops }))
|
||||
const diaryPayload = {
|
||||
name: formName.value.trim(),
|
||||
ingredients: cleanIngs,
|
||||
note: formNote.value,
|
||||
tags: formTags.value,
|
||||
}
|
||||
|
||||
if (editingRecipe.value && editingRecipe.value._diary_id) {
|
||||
// Editing a diary (personal) recipe
|
||||
// Editing an existing diary recipe
|
||||
try {
|
||||
await diaryStore.updateDiary(editingRecipe.value._diary_id, {
|
||||
name: formName.value.trim(),
|
||||
ingredients: cleanIngs,
|
||||
note: formNote.value,
|
||||
tags: formTags.value,
|
||||
})
|
||||
await diaryStore.updateDiary(editingRecipe.value._diary_id, diaryPayload)
|
||||
ui.showToast('个人配方已更新')
|
||||
closeOverlay()
|
||||
} catch (e) {
|
||||
@@ -538,22 +539,30 @@ async function saveCurrentRecipe() {
|
||||
return
|
||||
}
|
||||
|
||||
// Public recipe: API expects oil_name
|
||||
const payload = {
|
||||
name: formName.value.trim(),
|
||||
ingredients: cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops })),
|
||||
note: formNote.value,
|
||||
tags: formTags.value,
|
||||
}
|
||||
|
||||
if (editingRecipe.value) {
|
||||
payload._id = editingRecipe.value._id
|
||||
payload._version = editingRecipe.value._version
|
||||
if (editingRecipe.value && editingRecipe.value._id) {
|
||||
// Editing an existing public recipe
|
||||
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 })),
|
||||
note: formNote.value,
|
||||
tags: formTags.value,
|
||||
}
|
||||
try {
|
||||
await recipeStore.saveRecipe(payload)
|
||||
ui.showToast('配方已更新')
|
||||
closeOverlay()
|
||||
} catch (e) {
|
||||
ui.showToast('保存失败: ' + (e.message || '未知错误'))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// New recipe: always save to diary (personal)
|
||||
try {
|
||||
await recipeStore.saveRecipe(payload)
|
||||
ui.showToast(editingRecipe.value ? '配方已更新' : '配方已添加')
|
||||
await diaryStore.createDiary(diaryPayload)
|
||||
ui.showToast('已添加到我的配方')
|
||||
closeOverlay()
|
||||
} catch (e) {
|
||||
ui.showToast('保存失败: ' + (e.message || '未知错误'))
|
||||
|
||||
Reference in New Issue
Block a user