feat: 大量管理配方和搜索改进
- 存为我的:修复调用错误API,改用 diaryStore.createDiary - 存为我的:同名检测(我的配方 + 公共配方库) - 我的配方:使用 RecipeCard 统一卡片格式 - 管理配方:按钮缩小、编辑时隐藏智能粘贴、精油搜索框支持拼音跳转 - 管理配方:批量操作改为按钮组(打标签/删除/导出卡片/分享到公共库) - 管理配方:我的配方加勾选框、全选按钮、编辑功能 - 搜索:模糊匹配 + 同义词扩展(37组),精确/相似分层显示 - 搜索:无匹配时通知编辑添加,搜索时隐藏无匹配的收藏/我的配方区 - 搜索:配方按首字母排序 - 共享审核:通知高级编辑+管理员,我的配方显示共享状态 - 通知:搜索未收录→已添加按钮,审核类→去审核按钮跳转 - 贡献统计:非管理员显示已贡献公共配方数 - 登录弹窗:加反馈问题按钮(无需登录) - 精油编辑:右上角加保存按钮,支持回车保存 - 后端:新增 /api/me/contribution 接口 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -49,57 +49,91 @@
|
||||
|
||||
<!-- Personal Section (logged in) -->
|
||||
<div v-if="auth.isLoggedIn" class="personal-section">
|
||||
<template v-if="!searchQuery || myDiaryRecipes.length > 0">
|
||||
<div class="section-header" @click="showMyRecipes = !showMyRecipes">
|
||||
<span>📖 我的配方 ({{ myDiaryRecipes.length }})</span>
|
||||
<span v-if="!auth.isAdmin && sharedCount > 0" class="contrib-badge">已贡献 {{ sharedCount }} 条公共配方</span>
|
||||
<span class="toggle-icon">{{ showMyRecipes ? '▾' : '▸' }}</span>
|
||||
</div>
|
||||
<div v-if="showMyRecipes" class="recipe-grid">
|
||||
<div
|
||||
v-for="d in myDiaryRecipes"
|
||||
:key="'diary-' + d.id"
|
||||
class="recipe-card diary-card"
|
||||
@click="openDiaryDetail(d)"
|
||||
>
|
||||
<div class="card-name">{{ d.name }}</div>
|
||||
<div class="card-oils">{{ (d.ingredients || []).map(i => i.oil).join('、') }}</div>
|
||||
<div class="card-bottom">
|
||||
<span class="card-price">{{ oils.fmtPrice(oils.calcCost(d.ingredients || [])) }}</span>
|
||||
<button class="share-btn" @click.stop="shareDiaryToPublic(d)" title="共享到公共配方库">📤</button>
|
||||
</div>
|
||||
<div v-for="d in myDiaryRecipes" :key="'diary-' + d.id" class="diary-card-wrap">
|
||||
<RecipeCard
|
||||
:recipe="diaryAsRecipe(d)"
|
||||
:index="-1"
|
||||
@click="openDiaryDetail(d)"
|
||||
/>
|
||||
<span v-if="getDiaryShareStatus(d) === 'shared'" class="share-status shared">已共享</span>
|
||||
<span v-else-if="getDiaryShareStatus(d) === 'pending'" class="share-status pending">审核中</span>
|
||||
</div>
|
||||
<div v-if="myDiaryRecipes.length === 0" class="empty-hint">暂无个人配方</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<div class="section-header" @click="showFavorites = !showFavorites">
|
||||
<span>⭐ 收藏配方 ({{ favoritesPreview.length }})</span>
|
||||
<span class="toggle-icon">{{ showFavorites ? '▾' : '▸' }}</span>
|
||||
</div>
|
||||
<div v-if="showFavorites" class="recipe-grid">
|
||||
<RecipeCard
|
||||
v-for="r in favoritesPreview"
|
||||
:key="r._id"
|
||||
:recipe="r"
|
||||
:index="findGlobalIndex(r)"
|
||||
@click="openDetail(findGlobalIndex(r))"
|
||||
@toggle-fav="handleToggleFav(r)"
|
||||
/>
|
||||
<div v-if="favoritesPreview.length === 0" class="empty-hint">暂无收藏配方</div>
|
||||
</div>
|
||||
<template v-if="!searchQuery || favoritesPreview.length > 0">
|
||||
<div class="section-header" @click="showFavorites = !showFavorites">
|
||||
<span>⭐ 收藏配方 ({{ favoritesPreview.length }})</span>
|
||||
<span class="toggle-icon">{{ showFavorites ? '▾' : '▸' }}</span>
|
||||
</div>
|
||||
<div v-if="showFavorites" class="recipe-grid">
|
||||
<RecipeCard
|
||||
v-for="r in favoritesPreview"
|
||||
:key="r._id"
|
||||
:recipe="r"
|
||||
:index="findGlobalIndex(r)"
|
||||
@click="openDetail(findGlobalIndex(r))"
|
||||
@toggle-fav="handleToggleFav(r)"
|
||||
/>
|
||||
<div v-if="favoritesPreview.length === 0" class="empty-hint">暂无收藏配方</div>
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<!-- Search Results (public recipes) -->
|
||||
<div v-if="searchQuery" class="search-results-section">
|
||||
<div class="section-label">🔍 公共配方搜索结果 ({{ fuzzyResults.length }})</div>
|
||||
<div class="recipe-grid">
|
||||
<RecipeCard
|
||||
v-for="(r, i) in fuzzyResults"
|
||||
:key="r._id"
|
||||
:recipe="r"
|
||||
:index="findGlobalIndex(r)"
|
||||
@click="openDetail(findGlobalIndex(r))"
|
||||
@toggle-fav="handleToggleFav(r)"
|
||||
/>
|
||||
<div v-if="fuzzyResults.length === 0" class="empty-hint">未找到匹配的公共配方</div>
|
||||
<!-- Exact matches -->
|
||||
<template v-if="exactResults.length > 0">
|
||||
<div class="section-label">🔍 搜索结果 ({{ exactResults.length }})</div>
|
||||
<div class="recipe-grid">
|
||||
<RecipeCard
|
||||
v-for="r in exactResults"
|
||||
:key="r._id"
|
||||
:recipe="r"
|
||||
:index="findGlobalIndex(r)"
|
||||
@click="openDetail(findGlobalIndex(r))"
|
||||
@toggle-fav="handleToggleFav(r)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- Similar/related matches -->
|
||||
<template v-if="similarResults.length > 0">
|
||||
<div class="section-label similar-label">
|
||||
{{ exactResults.length > 0 ? '💡 相关配方' : '💡 没有完全匹配,以下是相关配方' }}
|
||||
({{ similarResults.length }})
|
||||
</div>
|
||||
<div class="recipe-grid">
|
||||
<RecipeCard
|
||||
v-for="r in similarResults"
|
||||
:key="'sim-' + r._id"
|
||||
:recipe="r"
|
||||
:index="findGlobalIndex(r)"
|
||||
@click="openDetail(findGlobalIndex(r))"
|
||||
@toggle-fav="handleToggleFav(r)"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- No results at all -->
|
||||
<div v-if="exactResults.length === 0 && similarResults.length === 0" class="no-match-box">
|
||||
<div class="empty-hint">未找到「{{ searchQuery }}」相关配方</div>
|
||||
</div>
|
||||
|
||||
<!-- Report missing button -->
|
||||
<div v-if="exactResults.length === 0" class="no-match-box" style="margin-top:12px">
|
||||
<button v-if="!reportedMissing" class="btn-report-missing" @click="reportMissing">
|
||||
📢 {{ similarResults.length > 0 ? '以上都不是我想找的,通知编辑添加' : '通知编辑添加此配方' }}
|
||||
</button>
|
||||
<div v-else class="reported-hint">已通知编辑,感谢反馈!</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -121,9 +155,11 @@
|
||||
|
||||
<!-- Recipe Detail Overlay -->
|
||||
<RecipeDetailOverlay
|
||||
v-if="selectedRecipeIndex !== null"
|
||||
v-if="selectedRecipeIndex !== null || selectedDiaryRecipe !== null"
|
||||
:recipeIndex="selectedRecipeIndex"
|
||||
@close="selectedRecipeIndex = null"
|
||||
:recipeData="selectedDiaryRecipe"
|
||||
:isDiary="selectedDiaryRecipe !== null"
|
||||
@close="selectedRecipeIndex = null; selectedDiaryRecipe = null"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user