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 10 additions and 4 deletions
Showing only changes of commit 9fe6eeaf29 - Show all commits

View File

@@ -24,12 +24,14 @@ export function useKitCost() {
// Calculate per-drop costs for a kit
function calcKitPerDrop(kit) {
const resolved = kit.oils.map(name => resolveOilName(name))
// Sum of bottle prices for all oils in kit
const bc = kit.bottleCount || {} // e.g. { '椰子油': 2.57 }
// Sum of bottle prices for all oils in kit (accounting for multiple bottles)
let totalBottlePrice = 0
const oilBottlePrices = {}
for (const name of resolved) {
const meta = oils.oilsMeta[name]
const bp = meta ? meta.bottlePrice : 0
const count = bc[name] || 1
const bp = meta ? meta.bottlePrice * count : 0
oilBottlePrices[name] = bp
totalBottlePrice += bp
}
@@ -41,10 +43,11 @@ export function useKitCost() {
const perDrop = {}
for (const name of resolved) {
const meta = oils.oilsMeta[name]
const count = bc[name] || 1
const bp = oilBottlePrices[name]
const kitCostForOil = (bp / totalBottlePrice) * effectivePrice
const drops = meta ? meta.dropCount : 1
perDrop[name] = drops > 0 ? kitCostForOil / drops : 0
const totalDrops = meta ? meta.dropCount * count : 1
perDrop[name] = totalDrops > 0 ? kitCostForOil / totalDrops : 0
}
return perDrop
}

View File

@@ -1,5 +1,6 @@
// doTERRA 套装配置
// 价格和内容更新频率低,手动维护即可
// bottleCount: 某种油在套装中的瓶数用于成本分摊和可做次数计算默认1
export const KITS = [
{
id: 'aroma',
@@ -52,5 +53,7 @@ export const KITS = [
'柑橘清新', '顺畅呼吸', '净化清新', '赋活呼吸', '天然防护',
'椰子油',
],
// 115mL×1 + 30mL×6 = 295mL, 标准瓶115mL, 约2.57瓶
bottleCount: { '椰子油': 2.57 },
},
]