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:
2026-04-09 20:13:09 +00:00
committed by fam
parent 80397ec7ca
commit 27c46cb803
7 changed files with 645 additions and 154 deletions

View File

@@ -24,8 +24,10 @@
/>
<button v-if="manageSearch" class="search-clear-btn" @click="manageSearch = ''"></button>
</div>
<button class="btn-primary" @click="showAddOverlay = true">+ 添加配方</button>
<button class="btn-outline" @click="exportExcel">📊 导出Excel</button>
<div class="toolbar-actions">
<button class="btn-outline btn-sm" @click="showAddOverlay = true">+ 添加配方</button>
<button class="btn-outline btn-sm" @click="exportExcel">📥 导出Excel</button>
</div>
</div>
<!-- Tag Filter Bar -->
@@ -45,30 +47,37 @@
</div>
<!-- Batch Operations -->
<div v-if="selectedIds.size > 0" class="batch-bar">
<span>已选 {{ selectedIds.size }} </span>
<select v-model="batchAction" class="batch-select">
<option value="">批量操作...</option>
<option value="tag">添加标签</option>
<option value="share">分享</option>
<option value="export">导出卡片</option>
<option value="delete">删除</option>
</select>
<button class="btn-sm btn-primary" @click="executeBatch" :disabled="!batchAction">执行</button>
<button class="btn-sm btn-outline" @click="clearSelection">取消选择</button>
<div v-if="selectedIds.size > 0 || selectedDiaryIds.size > 0" class="batch-bar">
<span>已选 {{ selectedIds.size + selectedDiaryIds.size }} </span>
<button class="btn-sm btn-outline" @click="executeBatchAction('tag')">🏷 打标签</button>
<button class="btn-sm btn-outline" @click="executeBatchAction('share_public')" v-if="selectedDiaryIds.size > 0">📤 分享到公共库</button>
<button class="btn-sm btn-outline" @click="executeBatchAction('export')">📷 导出卡片</button>
<button class="btn-sm btn-danger-outline" @click="executeBatchAction('delete')">🗑 删除</button>
<button class="btn-sm btn-outline" @click="clearSelection">取消</button>
</div>
<!-- My Recipes Section (from diary) -->
<div class="recipe-section">
<h3 class="section-title">📖 我的配方 ({{ myRecipes.length }})</h3>
<h3 class="section-title">
<span>📖 我的配方 ({{ myRecipes.length }})</span>
<button class="btn-sm btn-outline" @click="toggleSelectAllDiary">全选/取消</button>
</h3>
<div class="recipe-list">
<div
v-for="d in myFilteredRecipes"
:key="'diary-' + d.id"
class="recipe-row diary-row"
class="recipe-row"
:class="{ selected: selectedDiaryIds.has(d.id) }"
>
<input
type="checkbox"
:checked="selectedDiaryIds.has(d.id)"
@change="toggleDiarySelect(d.id)"
class="row-check"
/>
<div class="row-info" @click="editDiaryRecipe(d)">
<span class="row-name">{{ d.name }}</span>
<span class="row-owner">{{ auth.user?.display_name || auth.user?.username }}</span>
<span class="row-tags">
<span v-for="t in (d.tags || [])" :key="t" class="mini-tag">{{ t }}</span>
</span>
@@ -124,20 +133,22 @@
<button class="btn-close" @click="closeOverlay"></button>
</div>
<!-- Smart Paste Section -->
<div class="paste-section">
<textarea
v-model="smartPasteText"
class="paste-input"
placeholder="粘贴配方文本,支持智能识别...&#10;例如: 薰衣草3滴 茶树2滴"
rows="4"
></textarea>
<button class="btn-primary" @click="handleSmartPaste" :disabled="!smartPasteText.trim()">
智能识别
</button>
</div>
<!-- Smart Paste Section (only for new recipes) -->
<template v-if="!editingRecipe">
<div class="paste-section">
<textarea
v-model="smartPasteText"
class="paste-input"
placeholder="粘贴配方文本,支持智能识别...&#10;例如: 薰衣草3滴 茶树2滴"
rows="4"
></textarea>
<button class="btn-primary" @click="handleSmartPaste" :disabled="!smartPasteText.trim()">
智能识别
</button>
</div>
<div class="divider-text">或手动输入</div>
<div class="divider-text">或手动输入</div>
</template>
<!-- Manual Form -->
<div class="form-group">
@@ -148,14 +159,29 @@
<div class="form-group">
<label>成分</label>
<div v-for="(ing, i) in formIngredients" :key="i" class="ing-row">
<select v-model="ing.oil" class="form-select">
<option value="">选择精油</option>
<option v-for="name in oils.oilNames" :key="name" :value="name">{{ name }}</option>
</select>
<div class="oil-search-wrap">
<input
v-model="ing._search"
class="form-select"
placeholder="输入搜索精油..."
@focus="ing._open = true"
@input="ing._open = true"
@blur="onOilBlur(ing)"
/>
<div v-if="ing._open" class="oil-dropdown">
<div
v-for="name in filteredOilNames(ing._search || '')"
:key="name"
class="oil-option"
@mousedown.prevent="selectOil(ing, name)"
>{{ name }}</div>
<div v-if="filteredOilNames(ing._search || '').length === 0" class="oil-option oil-empty">无匹配</div>
</div>
</div>
<input v-model.number="ing.drops" type="number" min="0" class="form-input-sm" placeholder="滴数" />
<button class="btn-icon-sm" @click="formIngredients.splice(i, 1)"></button>
</div>
<button class="btn-outline btn-sm" @click="formIngredients.push({ oil: '', drops: 1 })">+ 添加成分</button>
<button class="btn-outline btn-sm" @click="formIngredients.push({ oil: '', drops: 1, _search: '', _open: false })">+ 添加成分</button>
</div>
<div class="form-group">
@@ -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;