@@ -205,6 +231,7 @@ import { useUiStore } from '../stores/ui'
import { api } from '../composables/useApi'
import { showConfirm, showPrompt } from '../composables/useDialog'
import { parseSingleBlock } from '../composables/useSmartPaste'
+import { matchesPinyinInitials } from '../composables/usePinyinMatch'
import RecipeCard from '../components/RecipeCard.vue'
import TagPicker from '../components/TagPicker.vue'
@@ -218,7 +245,7 @@ const manageSearch = ref('')
const selectedTags = ref([])
const showTagFilter = ref(false)
const selectedIds = reactive(new Set())
-const batchAction = ref('')
+const selectedDiaryIds = reactive(new Set())
const showAddOverlay = ref(false)
const editingRecipe = ref(null)
const showPending = ref(false)
@@ -259,7 +286,7 @@ function filterBySearchAndTags(list) {
r.tags && selectedTags.value.every(t => r.tags.includes(t))
)
}
- return result
+ return result.slice().sort((a, b) => a.name.localeCompare(b.name, 'zh'))
}
const myFilteredRecipes = computed(() => filterBySearchAndTags(myRecipes.value))
@@ -276,47 +303,84 @@ function toggleSelect(id) {
else selectedIds.add(id)
}
-function clearSelection() {
- selectedIds.clear()
- batchAction.value = ''
+function toggleDiarySelect(id) {
+ if (selectedDiaryIds.has(id)) selectedDiaryIds.delete(id)
+ else selectedDiaryIds.add(id)
}
-async function executeBatch() {
- const ids = [...selectedIds]
- if (!ids.length || !batchAction.value) return
+function clearSelection() {
+ selectedIds.clear()
+ selectedDiaryIds.clear()
+}
- if (batchAction.value === 'delete') {
- const ok = await showConfirm(`确定删除 ${ids.length} 个配方?`)
+function toggleSelectAllDiary() {
+ if (selectedDiaryIds.size === myFilteredRecipes.value.length) {
+ selectedDiaryIds.clear()
+ } else {
+ myFilteredRecipes.value.forEach(d => selectedDiaryIds.add(d.id))
+ }
+}
+
+async function executeBatchAction(action) {
+ const pubIds = [...selectedIds]
+ const diaryIds = [...selectedDiaryIds]
+ const totalCount = pubIds.length + diaryIds.length
+ if (!totalCount) return
+
+ if (action === 'delete') {
+ const ok = await showConfirm(`确定删除 ${totalCount} 个配方?`)
if (!ok) return
- for (const id of ids) {
+ for (const id of pubIds) {
await recipeStore.deleteRecipe(id)
}
- ui.showToast(`已删除 ${ids.length} 个配方`)
- } else if (batchAction.value === 'tag') {
+ for (const id of diaryIds) {
+ await diaryStore.deleteDiary(id)
+ }
+ ui.showToast(`已删除 ${totalCount} 个配方`)
+ } else if (action === 'tag') {
const tagName = await showPrompt('输入要添加的标签:')
if (!tagName) return
- for (const id of ids) {
+ for (const id of pubIds) {
const recipe = recipeStore.recipes.find(r => r._id === id)
if (recipe && !recipe.tags.includes(tagName)) {
recipe.tags.push(tagName)
await recipeStore.saveRecipe(recipe)
}
}
- ui.showToast(`已为 ${ids.length} 个配方添加标签`)
- } else if (batchAction.value === 'share') {
- const text = ids.map(id => {
- const r = recipeStore.recipes.find(rec => rec._id === id)
- if (!r) return ''
- const ings = r.ingredients.map(ing => `${ing.oil} ${ing.drops}滴`).join(',')
- return `${r.name}:${ings}`
- }).filter(Boolean).join('\n\n')
- try {
- await navigator.clipboard.writeText(text)
- ui.showToast('已复制到剪贴板')
- } catch {
- ui.showToast('复制失败')
+ for (const id of diaryIds) {
+ const d = diaryStore.userDiary.find(r => r.id === id)
+ if (d) {
+ const tags = [...(d.tags || [])]
+ if (!tags.includes(tagName)) {
+ tags.push(tagName)
+ await diaryStore.updateDiary(id, { ...d, tags })
+ }
+ }
}
- } else if (batchAction.value === 'export') {
+ ui.showToast(`已为 ${totalCount} 个配方添加标签`)
+ } else if (action === 'share_public') {
+ const ok = await showConfirm(`将 ${diaryIds.length} 个配方分享到公共配方库?`)
+ if (!ok) return
+ let count = 0
+ for (const id of diaryIds) {
+ const d = diaryStore.userDiary.find(r => r.id === id)
+ if (!d) continue
+ try {
+ await api('/api/recipes', {
+ method: 'POST',
+ body: JSON.stringify({
+ name: d.name,
+ note: d.note || '',
+ ingredients: (d.ingredients || []).map(i => ({ oil_name: i.oil, drops: i.drops })),
+ tags: d.tags || [],
+ }),
+ })
+ count++
+ } catch {}
+ }
+ await recipeStore.loadRecipes()
+ ui.showToast(`已提交 ${count} 个配方,等待审核`)
+ } else if (action === 'export') {
ui.showToast('导出卡片功能开发中')
}
clearSelection()
@@ -325,7 +389,7 @@ async function executeBatch() {
function editRecipe(recipe) {
editingRecipe.value = recipe
formName.value = recipe.name
- formIngredients.value = recipe.ingredients.map(i => ({ ...i }))
+ formIngredients.value = recipe.ingredients.map(i => ({ ...i, _search: i.oil, _open: false }))
formNote.value = recipe.note || ''
formTags.value = [...(recipe.tags || [])]
showAddOverlay.value = true
@@ -339,7 +403,7 @@ function closeOverlay() {
function resetForm() {
formName.value = ''
- formIngredients.value = [{ oil: '', drops: 1 }]
+ formIngredients.value = [{ oil: '', drops: 1, _search: '', _open: false }]
formNote.value = ''
formTags.value = []
smartPasteText.value = ''
@@ -356,6 +420,28 @@ function handleSmartPaste() {
}
}
+function filteredOilNames(search) {
+ if (!search) return oils.oilNames
+ const q = search.toLowerCase()
+ return oils.oilNames.filter(name =>
+ name.toLowerCase().includes(q) || matchesPinyinInitials(name, q)
+ )
+}
+
+function selectOil(ing, name) {
+ ing.oil = name
+ ing._search = name
+ ing._open = false
+}
+
+function onOilBlur(ing) {
+ setTimeout(() => {
+ ing._open = false
+ if (!ing.oil) ing._search = ''
+ else ing._search = ing.oil
+ }, 150)
+}
+
function toggleFormTag(tag) {
const idx = formTags.value.indexOf(tag)
if (idx >= 0) formTags.value.splice(idx, 1)
@@ -380,6 +466,18 @@ async function saveCurrentRecipe() {
tags: formTags.value,
}
+ if (editingRecipe.value && editingRecipe.value._diary_id) {
+ // Editing a diary (personal) recipe
+ try {
+ await diaryStore.updateDiary(editingRecipe.value._diary_id, payload)
+ ui.showToast('个人配方已更新')
+ closeOverlay()
+ } catch (e) {
+ ui.showToast('保存失败: ' + (e.message || '未知错误'))
+ }
+ return
+ }
+
if (editingRecipe.value) {
payload._id = editingRecipe.value._id
payload._version = editingRecipe.value._version
@@ -402,9 +500,12 @@ onMounted(async () => {
})
function editDiaryRecipe(diary) {
- // For now, navigate to MyDiary page to edit
- // TODO: inline editing
- ui.showToast('请到「我的」页面编辑个人配方')
+ editingRecipe.value = { _diary_id: diary.id, name: diary.name }
+ formName.value = diary.name
+ formIngredients.value = (diary.ingredients || []).map(i => ({ ...i, _search: i.oil, _open: false }))
+ formNote.value = diary.note || ''
+ formTags.value = [...(diary.tags || [])]
+ showAddOverlay.value = true
}
async function removeDiaryRecipe(diary) {
@@ -882,6 +983,44 @@ watch(() => recipeStore.recipes, () => {
text-align: center;
}
+.oil-search-wrap {
+ flex: 1;
+ position: relative;
+}
+
+.oil-dropdown {
+ position: absolute;
+ top: 100%;
+ left: 0;
+ right: 0;
+ background: #fff;
+ border: 1.5px solid #d4cfc7;
+ border-radius: 8px;
+ max-height: 180px;
+ overflow-y: auto;
+ z-index: 10;
+ box-shadow: 0 4px 12px rgba(0,0,0,0.1);
+}
+
+.oil-option {
+ padding: 8px 12px;
+ font-size: 13px;
+ cursor: pointer;
+}
+
+.oil-option:hover {
+ background: #e8f5e9;
+}
+
+.oil-empty {
+ color: #999;
+ cursor: default;
+}
+
+.oil-empty:hover {
+ background: transparent;
+}
+
.btn-icon-sm {
border: none;
background: transparent;
@@ -938,6 +1077,32 @@ watch(() => recipeStore.recipes, () => {
background: #f8f7f5;
}
+.toolbar-actions {
+ display: flex;
+ gap: 8px;
+}
+
+.btn-sm {
+ padding: 7px 14px;
+ font-size: 13px;
+}
+
+.btn-danger-outline {
+ background: #fff;
+ color: #c0392b;
+ border: 1.5px solid #e8b4b0;
+ border-radius: 10px;
+ padding: 7px 14px;
+ font-size: 13px;
+ cursor: pointer;
+ font-family: inherit;
+ white-space: nowrap;
+}
+
+.btn-danger-outline:hover {
+ background: #fdf0ee;
+}
+
.btn-sm {
padding: 6px 14px;
font-size: 12px;
diff --git a/frontend/src/views/RecipeSearch.vue b/frontend/src/views/RecipeSearch.vue
index 3048915..7c80905 100644
--- a/frontend/src/views/RecipeSearch.vue
+++ b/frontend/src/views/RecipeSearch.vue
@@ -49,57 +49,91 @@
+
-
-
{{ d.name }}
-
{{ (d.ingredients || []).map(i => i.oil).join('、') }}
-
- {{ oils.fmtPrice(oils.calcCost(d.ingredients || [])) }}
-
-
+
+
+ 已共享
+ 审核中
暂无个人配方
+
-
-
+
+
+
+
-
🔍 公共配方搜索结果 ({{ fuzzyResults.length }})
-
-
-
未找到匹配的公共配方
+
+
+ 🔍 搜索结果 ({{ exactResults.length }})
+
+
+
+
+
+
+
+
+ {{ exactResults.length > 0 ? '💡 相关配方' : '💡 没有完全匹配,以下是相关配方' }}
+ ({{ similarResults.length }})
+
+
+
+
+
+
+
+
+
未找到「{{ searchQuery }}」相关配方
+
+
+
+
+
+
已通知编辑,感谢反馈!
@@ -121,9 +155,11 @@
@@ -152,9 +188,11 @@ const searchQuery = ref('')
const selectedCategory = ref(null)
const categories = ref([])
const selectedRecipeIndex = ref(null)
+const selectedDiaryRecipe = ref(null)
const showMyRecipes = ref(true)
const showFavorites = ref(true)
const catIdx = ref(0)
+const sharedCount = ref(0)
onMounted(async () => {
try {
@@ -164,9 +202,16 @@ onMounted(async () => {
}
} catch {}
- // Load personal diary recipes
+ // Load personal diary recipes & contribution stats
if (auth.isLoggedIn) {
await diaryStore.loadDiary()
+ try {
+ const cRes = await api('/api/me/contribution')
+ if (cRes.ok) {
+ const data = await cRes.json()
+ sharedCount.value = data.shared_count || 0
+ }
+ } catch {}
}
// Return to a recipe card after QR upload redirect
@@ -206,21 +251,107 @@ const filteredRecipes = computed(() => {
if (selectedCategory.value) {
list = list.filter(r => r.tags && r.tags.includes(selectedCategory.value))
}
- return list
+ return list.slice().sort((a, b) => a.name.localeCompare(b.name, 'zh'))
})
-// Search results from public recipes
-const fuzzyResults = computed(() => {
+// Synonym groups for broader fuzzy matching
+const synonymGroups = [
+ ['胸', '乳腺', '乳房', '丰胸', '胸部'],
+ ['瘦', '减肥', '减脂', '消脂', '纤体', '塑形', '体重'],
+ ['痘', '痤疮', '粉刺', '暗疮', '长痘', '祛痘'],
+ ['斑', '色斑', '淡斑', '雀斑', '黑色素', '美白', '亮肤'],
+ ['皱', '抗皱', '皱纹', '紧致', '抗衰', '抗老'],
+ ['睡', '眠', '失眠', '助眠', '安眠', '好眠', '入睡'],
+ ['焦虑', '紧张', '压力', '情绪', '放松', '舒缓', '安神', '宁神'],
+ ['头', '头痛', '头疼', '偏头痛', '头晕'],
+ ['咳', '咳嗽', '止咳', '清咽'],
+ ['鼻', '鼻炎', '鼻塞', '过敏性鼻炎', '打喷嚏'],
+ ['感冒', '发烧', '发热', '流感', '风寒', '风热'],
+ ['胃', '消化', '肠胃', '胃痛', '胃胀', '积食', '便秘'],
+ ['肝', '护肝', '养肝', '肝脏', '排毒'],
+ ['肾', '补肾', '养肾', '肾虚'],
+ ['腰', '腰痛', '腰酸', '腰椎'],
+ ['肩', '肩颈', '颈椎', '肩周'],
+ ['关节', '骨骼', '骨质', '风湿', '类风湿'],
+ ['肌肉', '酸痛', '疼痛', '拉伤'],
+ ['月经', '痛经', '经期', '姨妈', '生理期', '调经'],
+ ['子宫', '卵巢', '生殖', '备孕', '怀孕', '孕'],
+ ['前列腺', '男性', '阳'],
+ ['湿', '祛湿', '排湿', '湿气', '化湿'],
+ ['免疫', '免疫力', '抵抗力'],
+ ['脱发', '掉发', '生发', '头发', '发际线', '秃'],
+ ['过敏', '敏感', '荨麻疹', '湿疹', '皮炎'],
+ ['血压', '高血压', '低血压', '血管', '循环'],
+ ['血糖', '糖尿病', '降糖'],
+ ['淋巴', '排毒', '水肿', '浮肿'],
+ ['呼吸', '肺', '支气管', '哮喘', '气管'],
+ ['眼', '眼睛', '视力', '近视', '干眼'],
+ ['耳', '耳鸣', '中耳炎', '耳朵'],
+ ['口', '口腔', '口臭', '牙', '牙龈', '牙疼'],
+ ['皮肤', '护肤', '保湿', '修复', '焕肤'],
+ ['疤', '疤痕', '伤疤', '妊娠纹'],
+ ['心', '心脏', '心悸', '养心'],
+ ['甲状腺', '甲亢', '甲减'],
+ ['高', '长高', '增高', '个子'],
+ ['静脉', '静脉曲张'],
+ ['痔', '痔疮'],
+]
+
+function expandQuery(q) {
+ const terms = [q]
+ for (const group of synonymGroups) {
+ if (group.some(t => q.includes(t) || t.includes(q))) {
+ for (const t of group) {
+ if (!terms.includes(t)) terms.push(t)
+ }
+ }
+ }
+ return terms
+}
+
+// Search results: exact matches (query in recipe name or tags, NOT oil names to avoid noise like 西班牙牛至)
+const exactResults = computed(() => {
if (!searchQuery.value.trim()) return []
const q = searchQuery.value.trim().toLowerCase()
return recipeStore.recipes.filter(r => {
const nameMatch = r.name.toLowerCase().includes(q)
- const oilMatch = r.ingredients.some(ing => ing.oil.toLowerCase().includes(q))
const tagMatch = r.tags && r.tags.some(t => t.toLowerCase().includes(q))
- return nameMatch || oilMatch || tagMatch
- })
+ return nameMatch || tagMatch
+ }).sort((a, b) => a.name.localeCompare(b.name, 'zh'))
})
+// Similar results: synonym expansion, only match against recipe NAME (not ingredients/tags)
+// Filter out single-char expanded terms to avoid overly broad matches
+const similarResults = computed(() => {
+ if (!searchQuery.value.trim()) return []
+ const q = searchQuery.value.trim()
+ const exactIds = new Set(exactResults.value.map(r => r._id))
+ const terms = expandQuery(q).filter(t => t.length >= 2 || t === q)
+
+ return recipeStore.recipes.filter(r => {
+ if (exactIds.has(r._id)) return false
+ const name = r.name
+ // Match by expanded synonyms (name only, not ingredients)
+ if (terms.some(t => name.includes(t))) return true
+ return false
+ }).sort((a, b) => a.name.localeCompare(b.name, 'zh')).slice(0, 30)
+})
+
+const reportedMissing = ref(false)
+
+async function reportMissing() {
+ try {
+ await api('/api/symptom-search', {
+ method: 'POST',
+ body: JSON.stringify({ query: searchQuery.value.trim(), report_missing: true }),
+ })
+ reportedMissing.value = true
+ ui.showToast('已通知编辑,感谢反馈!')
+ } catch {
+ ui.showToast('通知失败')
+ }
+}
+
// Personal recipes from diary (separate from public recipes)
const myDiaryRecipes = computed(() => {
if (!auth.isLoggedIn) return []
@@ -260,27 +391,24 @@ function openDetail(index) {
}
}
-function openDiaryDetail(diary) {
- // Create a temporary recipe-like object from diary and open it
- const tmpRecipe = {
- _id: null,
- _diary_id: diary.id,
- name: diary.name,
- note: diary.note || '',
- tags: diary.tags || [],
- ingredients: diary.ingredients || [],
- _owner_id: auth.user.id,
+function getDiaryShareStatus(d) {
+ const pub = recipeStore.recipes.find(r => r.name === d.name && r._owner_id === auth.user?.id)
+ if (pub) return 'shared'
+ return null
+}
+
+function diaryAsRecipe(d) {
+ return {
+ _id: 'diary-' + d.id,
+ name: d.name,
+ note: d.note || '',
+ tags: d.tags || [],
+ ingredients: d.ingredients || [],
}
- recipeStore.recipes.push(tmpRecipe)
- const tmpIdx = recipeStore.recipes.length - 1
- selectedRecipeIndex.value = tmpIdx
- // Clean up temp recipe when detail closes
- const unwatch = watch(selectedRecipeIndex, (val) => {
- if (val === null) {
- recipeStore.recipes.splice(tmpIdx, 1)
- unwatch()
- }
- })
+}
+
+function openDiaryDetail(diary) {
+ selectedDiaryRecipe.value = diaryAsRecipe(diary)
}
async function handleToggleFav(recipe) {
@@ -317,12 +445,13 @@ async function shareDiaryToPublic(diary) {
}
function onSearch() {
- // fuzzyResults computed handles the filtering reactively
+ reportedMissing.value = false
}
function clearSearch() {
searchQuery.value = ''
selectedCategory.value = null
+ reportedMissing.value = false
}
// Carousel swipe
@@ -535,6 +664,40 @@ function onCarouselTouchEnd(e) {
color: #999;
}
+.diary-card-wrap {
+ position: relative;
+}
+
+.share-status {
+ position: absolute;
+ top: 8px;
+ right: 8px;
+ font-size: 10px;
+ padding: 2px 8px;
+ border-radius: 8px;
+ font-weight: 600;
+}
+
+.share-status.shared {
+ background: #e8f5e9;
+ color: #2e7d32;
+}
+
+.share-status.pending {
+ background: #fff3e0;
+ color: #e65100;
+}
+
+.contrib-badge {
+ font-size: 11px;
+ color: #4a9d7e;
+ background: #e8f5e9;
+ padding: 2px 8px;
+ border-radius: 8px;
+ font-weight: 500;
+ margin-left: auto;
+}
+
.section-label {
font-size: 14px;
font-weight: 600;
@@ -562,6 +725,40 @@ function onCarouselTouchEnd(e) {
padding: 24px 0;
}
+.similar-label {
+ color: #e65100;
+ background: #fff8e1;
+ padding: 8px 14px;
+ border-radius: 10px;
+}
+
+.no-match-box {
+ text-align: center;
+ padding: 12px 0;
+}
+
+.btn-report-missing {
+ background: linear-gradient(135deg, #ffb74d, #e65100);
+ color: #fff;
+ border: none;
+ border-radius: 10px;
+ padding: 10px 20px;
+ font-size: 14px;
+ cursor: pointer;
+ font-family: inherit;
+ margin-top: 8px;
+}
+
+.btn-report-missing:hover {
+ opacity: 0.9;
+}
+
+.reported-hint {
+ color: #4a9d7e;
+ font-size: 13px;
+ font-weight: 500;
+}
+
.diary-card {
background: white;
border-radius: 14px;