feat: 套装方案对比与导出功能 #32

Merged
hera merged 37 commits from feat/kit-comparison-export into main 2026-04-14 13:32:34 +00:00
2 changed files with 30 additions and 2 deletions
Showing only changes of commit f03bf699e5 - Show all commits

View File

@@ -1010,6 +1010,7 @@ async function saveRecipe() {
note: editNote.value.trim(),
tags: editTags.value,
ingredients: allIngs,
volume: selectedVolume.value || '',
}
await recipesStore.saveRecipe(payload)
// Reload recipes so the data is fresh when re-opened

View File

@@ -48,7 +48,7 @@
</thead>
<tbody>
<tr v-for="r in activeKitData.recipes" :key="r._id">
<td class="td-name">{{ r.name }} <span class="td-volume">{{ r.volume || '单次' }}</span></td>
<td class="td-name">{{ r.name }} <span v-if="volumeLabel(r)" class="td-volume">{{ volumeLabel(r) }}</span></td>
<td class="td-times">{{ calcMaxTimes(r) }}</td>
<td class="td-cost">{{ fmtPrice(r.kitCost) }}</td>
<td class="td-cost original">{{ fmtPrice(r.originalCost) }}</td>
@@ -85,7 +85,7 @@
</thead>
<tbody>
<tr v-for="row in crossComparison" :key="row.id">
<td class="td-name">{{ row.name }} <span class="td-volume">{{ row.volume || '单次' }}</span></td>
<td class="td-name">{{ row.name }} <span v-if="volumeLabel(row)" class="td-volume">{{ volumeLabel(row) }}</span></td>
<td v-for="ka in kitAnalysis" :key="ka.id" :class="row.costs[ka.id] != null ? 'td-kit-available' : 'td-kit-na'">
<template v-if="row.costs[ka.id] != null">{{ fmtPrice(row.costs[ka.id]) }}</template>
<template v-else><span class="na"></span></template>
@@ -120,6 +120,33 @@ const sellingPrices = ref({})
const activeKitData = computed(() => kitAnalysis.value.find(k => k.id === activeKit.value))
function volumeLabel(recipe) {
const vol = recipe.volume
if (vol) {
if (vol === 'single') return '单次'
if (vol === 'custom') return ''
if (/^\d+$/.test(vol)) return `${vol}ml`
return vol
}
const ings = recipe.ingredients || []
const coco = ings.find(i => i.oil === '椰子油')
if (coco && coco.drops) {
const totalDrops = ings.reduce((s, i) => s + (i.drops || 0), 0)
const ml = totalDrops / 18.6
if (ml <= 2) return '单次'
return `${Math.round(ml)}ml`
}
let totalMl = 0
let hasProduct = false
for (const ing of ings) {
if (!oils.isPortionUnit(ing.oil)) continue
hasProduct = true
totalMl += ing.drops || 0
}
if (hasProduct && totalMl > 0) return `${Math.round(totalMl)}ml`
return ''
}
onMounted(async () => {
if (!auth.isBusiness && !auth.isAdmin) {
router.replace('/projects')