fix: 智能识别配方名称 + 新增默认保存到个人配方
All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Successful in 53s

- 修复空格/无分隔符时配方名称无法识别的问题
- 支持"长高芳香调理8永久花10"连写格式自动分离名称
- 所有用户新增配方默认保存到个人配方(diary),不进公共库

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 08:53:48 +00:00
parent 640f0d09f6
commit 951577d0bb
2 changed files with 64 additions and 21 deletions

View File

@@ -266,7 +266,41 @@ export function parseSingleBlock(raw, oilNames) {
* appears after some oils have been found, it starts a new recipe. * appears after some oils have been found, it starts a new recipe.
*/ */
export function parseMultiRecipes(raw, oilNames) { export function parseMultiRecipes(raw, oilNames) {
const parts = raw.split(/[,,、\n\r]+/).map(s => s.trim()).filter(s => s) // First split by lines/commas, then within each part also try space splitting
const roughParts = raw.split(/[,,、\n\r]+/).map(s => s.trim()).filter(s => s)
const parts = []
for (const rp of roughParts) {
// If the part has spaces and contains mixed name+oil, split by spaces too
// But only if spaces actually separate meaningful chunks
const spaceParts = rp.split(/\s+/).filter(s => s)
if (spaceParts.length > 1) {
parts.push(...spaceParts)
} else {
// No spaces or single chunk — try to separate name prefix from oil+number
// e.g. "长高芳香调理8" → check if any oil is inside
const hasOilInside = oilNames.some(oil => rp.includes(oil))
if (hasOilInside && rp.length > 2) {
// Find the earliest oil match position
let earliest = rp.length
let earliestOil = ''
for (const oil of oilNames) {
const pos = rp.indexOf(oil)
if (pos >= 0 && pos < earliest) {
earliest = pos
earliestOil = oil
}
}
if (earliest > 0) {
parts.push(rp.substring(0, earliest))
parts.push(rp.substring(earliest))
} else {
parts.push(rp)
}
} else {
parts.push(rp)
}
}
}
const recipes = [] const recipes = []
let current = { nameParts: [], ingredientParts: [], foundOil: false } let current = { nameParts: [], ingredientParts: [], foundOil: false }

View File

@@ -520,16 +520,17 @@ async function saveCurrentRecipe() {
} }
const cleanIngs = validIngs.map(i => ({ oil: i.oil, drops: i.drops })) const cleanIngs = validIngs.map(i => ({ oil: i.oil, drops: i.drops }))
const diaryPayload = {
if (editingRecipe.value && editingRecipe.value._diary_id) {
// Editing a diary (personal) recipe
try {
await diaryStore.updateDiary(editingRecipe.value._diary_id, {
name: formName.value.trim(), name: formName.value.trim(),
ingredients: cleanIngs, ingredients: cleanIngs,
note: formNote.value, note: formNote.value,
tags: formTags.value, tags: formTags.value,
}) }
if (editingRecipe.value && editingRecipe.value._diary_id) {
// Editing an existing diary recipe
try {
await diaryStore.updateDiary(editingRecipe.value._diary_id, diaryPayload)
ui.showToast('个人配方已更新') ui.showToast('个人配方已更新')
closeOverlay() closeOverlay()
} catch (e) { } catch (e) {
@@ -538,22 +539,30 @@ async function saveCurrentRecipe() {
return return
} }
// Public recipe: API expects oil_name if (editingRecipe.value && editingRecipe.value._id) {
// Editing an existing public recipe
const payload = { const payload = {
_id: editingRecipe.value._id,
_version: editingRecipe.value._version,
name: formName.value.trim(), name: formName.value.trim(),
ingredients: cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops })), ingredients: cleanIngs.map(i => ({ oil_name: i.oil, drops: i.drops })),
note: formNote.value, note: formNote.value,
tags: formTags.value, tags: formTags.value,
} }
if (editingRecipe.value) {
payload._id = editingRecipe.value._id
payload._version = editingRecipe.value._version
}
try { try {
await recipeStore.saveRecipe(payload) await recipeStore.saveRecipe(payload)
ui.showToast(editingRecipe.value ? '配方已更新' : '配方已添加') ui.showToast('配方已更新')
closeOverlay()
} catch (e) {
ui.showToast('保存失败: ' + (e.message || '未知错误'))
}
return
}
// New recipe: always save to diary (personal)
try {
await diaryStore.createDiary(diaryPayload)
ui.showToast('已添加到我的配方')
closeOverlay() closeOverlay()
} catch (e) { } catch (e) {
ui.showToast('保存失败: ' + (e.message || '未知错误')) ui.showToast('保存失败: ' + (e.message || '未知错误'))