diff --git a/frontend/src/views/RecipeManager.vue b/frontend/src/views/RecipeManager.vue index 6cd0750..0b6c0af 100644 --- a/frontend/src/views/RecipeManager.vue +++ b/frontend/src/views/RecipeManager.vue @@ -62,6 +62,7 @@

📖 我的配方 ({{ myRecipes.length }}) + 已贡献 {{ sharedCount }} 条

@@ -84,8 +85,11 @@ {{ t }} {{ oils.fmtPrice(oils.calcCost(d.ingredients || [])) }} + +
+
@@ -609,10 +613,19 @@ async function saveAllParsed() { closeOverlay() } +const sharedCount = ref(0) + // Load diary on mount onMounted(async () => { if (auth.isLoggedIn) { await diaryStore.loadDiary() + try { + const res = await api('/api/me/contribution') + if (res.ok) { + const data = await res.json() + sharedCount.value = data.shared_count || 0 + } + } catch {} } }) @@ -625,6 +638,40 @@ function editDiaryRecipe(diary) { showAddOverlay.value = true } +function getDiaryShareStatus(d) { + // Check if a public recipe with same name exists, owned by current user or adopted by admin + const pub = recipeStore.recipes.find(r => r.name === d.name) + if (!pub) return null + if (pub._owner_id === auth.user?.id) return 'pending' + return 'shared' +} + +async function shareDiaryToPublic(diary) { + const ok = await showConfirm(`将「${diary.name}」共享到公共配方库?`) + if (!ok) return + try { + const res = await api('/api/recipes', { + method: 'POST', + body: JSON.stringify({ + name: diary.name, + note: diary.note || '', + ingredients: (diary.ingredients || []).map(i => ({ oil_name: i.oil, drops: i.drops })), + tags: diary.tags || [], + }), + }) + if (res.ok) { + if (auth.isAdmin) { + ui.showToast('已共享到公共配方库') + } else { + ui.showToast('已提交,等待管理员审核') + } + await recipeStore.loadRecipes() + } + } catch { + ui.showToast('共享失败') + } +} + async function removeDiaryRecipe(diary) { const ok = await showConfirm(`确定删除个人配方 "${diary.name}"?`) if (!ok) return @@ -928,6 +975,25 @@ watch(() => recipeStore.recipes, () => { color: #6b6375; } +.share-tag { + font-size: 11px; + padding: 1px 8px; + border-radius: 8px; + font-weight: 500; + white-space: nowrap; +} +.share-tag.shared { background: #e8f5e9; color: #2e7d32; } +.share-tag.pending { background: #fff3e0; color: #e65100; } + +.contrib-tag { + font-size: 11px; + color: #4a9d7e; + background: #e8f5e9; + padding: 2px 8px; + border-radius: 8px; + font-weight: 500; +} + .row-cost { font-size: 13px; color: #4a9d7e; diff --git a/frontend/src/views/RecipeSearch.vue b/frontend/src/views/RecipeSearch.vue index 1f04aa1..eaf465d 100644 --- a/frontend/src/views/RecipeSearch.vue +++ b/frontend/src/views/RecipeSearch.vue @@ -64,7 +64,6 @@ /> 已共享 审核中 -
暂无个人配方