Compare commits
23 Commits
fix/next-b
...
fix/next-b
| Author | SHA1 | Date | |
|---|---|---|---|
| ad65d7a8a9 | |||
| 24e8aea39c | |||
| 74a8d9aeb6 | |||
| 13b675e63d | |||
| 5f1ead03ab | |||
| c19f6e8276 | |||
| e28f5f9c0f | |||
| 4df02edc53 | |||
| 0451633bf5 | |||
| 7af83b96ca | |||
| 30bb69f52c | |||
| 42993d47ee | |||
| eeb9b0aa88 | |||
| 7bcb1d1a5b | |||
| 371aa74c31 | |||
| 395e837de8 | |||
| 7abc219659 | |||
| 9beddc387a | |||
| b28b1c7f62 | |||
| 9f072e48f8 | |||
| a3bf13c58d | |||
| fba66b42c2 | |||
| 67d268bc92 |
@@ -227,6 +227,8 @@ def init_db():
|
||||
c.execute("ALTER TABLE oils ADD COLUMN is_active INTEGER DEFAULT 1")
|
||||
if "en_name" not in oil_cols:
|
||||
c.execute("ALTER TABLE oils ADD COLUMN en_name TEXT DEFAULT ''")
|
||||
if "unit" not in oil_cols:
|
||||
c.execute("ALTER TABLE oils ADD COLUMN unit TEXT DEFAULT 'drop'")
|
||||
|
||||
# Migration: add new columns to category_modules if missing
|
||||
cat_cols = [row[1] for row in c.execute("PRAGMA table_info(category_modules)").fetchall()]
|
||||
@@ -246,6 +248,8 @@ def init_db():
|
||||
c.execute("ALTER TABLE recipes ADD COLUMN updated_by INTEGER")
|
||||
if "en_name" not in cols:
|
||||
c.execute("ALTER TABLE recipes ADD COLUMN en_name TEXT DEFAULT ''")
|
||||
if "volume" not in cols:
|
||||
c.execute("ALTER TABLE recipes ADD COLUMN volume TEXT DEFAULT ''")
|
||||
|
||||
# Seed admin user if no users exist
|
||||
count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]
|
||||
|
||||
@@ -87,6 +87,7 @@ class OilIn(BaseModel):
|
||||
retail_price: Optional[float] = None
|
||||
en_name: Optional[str] = None
|
||||
is_active: Optional[int] = None
|
||||
unit: Optional[str] = None
|
||||
|
||||
|
||||
class IngredientIn(BaseModel):
|
||||
@@ -109,6 +110,7 @@ class RecipeUpdate(BaseModel):
|
||||
ingredients: Optional[list[IngredientIn]] = None
|
||||
tags: Optional[list[str]] = None
|
||||
version: Optional[int] = None
|
||||
volume: Optional[str] = None
|
||||
|
||||
|
||||
class UserIn(BaseModel):
|
||||
@@ -318,7 +320,7 @@ def symptom_search(body: dict, user=Depends(get_current_user)):
|
||||
conn = get_db()
|
||||
# Search in recipe names
|
||||
rows = conn.execute(
|
||||
"SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id"
|
||||
"SELECT id, name, note, owner_id, version, en_name, volume FROM recipes ORDER BY id"
|
||||
).fetchall()
|
||||
exact = []
|
||||
related = []
|
||||
@@ -715,7 +717,7 @@ def impersonate(body: dict, user=Depends(require_role("admin"))):
|
||||
@app.get("/api/oils")
|
||||
def list_oils():
|
||||
conn = get_db()
|
||||
rows = conn.execute("SELECT name, bottle_price, drop_count, retail_price, is_active, en_name FROM oils ORDER BY name").fetchall()
|
||||
rows = conn.execute("SELECT name, bottle_price, drop_count, retail_price, is_active, en_name, unit FROM oils ORDER BY name").fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
@@ -724,11 +726,11 @@ def list_oils():
|
||||
def upsert_oil(oil: OilIn, user=Depends(require_role("admin", "senior_editor"))):
|
||||
conn = get_db()
|
||||
conn.execute(
|
||||
"INSERT INTO oils (name, bottle_price, drop_count, retail_price, en_name, is_active) VALUES (?, ?, ?, ?, ?, ?) "
|
||||
"INSERT INTO oils (name, bottle_price, drop_count, retail_price, en_name, is_active, unit) VALUES (?, ?, ?, ?, ?, ?, ?) "
|
||||
"ON CONFLICT(name) DO UPDATE SET bottle_price=excluded.bottle_price, drop_count=excluded.drop_count, "
|
||||
"retail_price=excluded.retail_price, en_name=COALESCE(excluded.en_name, oils.en_name), "
|
||||
"is_active=COALESCE(excluded.is_active, oils.is_active)",
|
||||
(oil.name, oil.bottle_price, oil.drop_count, oil.retail_price, title_case(oil.en_name) if oil.en_name else oil.en_name, oil.is_active),
|
||||
"is_active=COALESCE(excluded.is_active, oils.is_active), unit=COALESCE(excluded.unit, oils.unit)",
|
||||
(oil.name, oil.bottle_price, oil.drop_count, oil.retail_price, title_case(oil.en_name) if oil.en_name else oil.en_name, oil.is_active, oil.unit),
|
||||
)
|
||||
log_audit(conn, user["id"], "upsert_oil", "oil", oil.name, oil.name,
|
||||
json.dumps({"bottle_price": oil.bottle_price, "drop_count": oil.drop_count}))
|
||||
@@ -772,6 +774,7 @@ def _recipe_to_dict(conn, row):
|
||||
"version": row["version"] if "version" in row.keys() else 1,
|
||||
"ingredients": [{"oil_name": i["oil_name"], "drops": i["drops"]} for i in ings],
|
||||
"tags": [t["tag_name"] for t in tags],
|
||||
"volume": row["volume"] if "volume" in row.keys() else "",
|
||||
}
|
||||
|
||||
|
||||
@@ -780,19 +783,19 @@ def list_recipes(user=Depends(get_current_user)):
|
||||
conn = get_db()
|
||||
# Admin sees all; others see admin-owned (adopted) + their own
|
||||
if user["role"] == "admin":
|
||||
rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
|
||||
rows = conn.execute("SELECT id, name, note, owner_id, version, en_name, volume FROM recipes ORDER BY id").fetchall()
|
||||
else:
|
||||
admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone()
|
||||
admin_id = admin["id"] if admin else 1
|
||||
user_id = user.get("id")
|
||||
if user_id:
|
||||
rows = conn.execute(
|
||||
"SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id",
|
||||
"SELECT id, name, note, owner_id, version, en_name, volume FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id",
|
||||
(admin_id, user_id)
|
||||
).fetchall()
|
||||
else:
|
||||
rows = conn.execute(
|
||||
"SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? ORDER BY id",
|
||||
"SELECT id, name, note, owner_id, version, en_name, volume FROM recipes WHERE owner_id = ? ORDER BY id",
|
||||
(admin_id,)
|
||||
).fetchall()
|
||||
result = [_recipe_to_dict(conn, r) for r in rows]
|
||||
@@ -803,7 +806,7 @@ def list_recipes(user=Depends(get_current_user)):
|
||||
@app.get("/api/recipes/{recipe_id}")
|
||||
def get_recipe(recipe_id: int):
|
||||
conn = get_db()
|
||||
row = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
|
||||
row = conn.execute("SELECT id, name, note, owner_id, version, en_name, volume FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
|
||||
if not row:
|
||||
conn.close()
|
||||
raise HTTPException(404, "Recipe not found")
|
||||
@@ -893,6 +896,8 @@ def update_recipe(recipe_id: int, update: RecipeUpdate, user=Depends(get_current
|
||||
c.execute("UPDATE recipes SET note = ? WHERE id = ?", (update.note, recipe_id))
|
||||
if update.en_name is not None:
|
||||
c.execute("UPDATE recipes SET en_name = ? WHERE id = ?", (title_case(update.en_name), recipe_id))
|
||||
if update.volume is not None:
|
||||
c.execute("UPDATE recipes SET volume = ? WHERE id = ?", (update.volume, recipe_id))
|
||||
if update.ingredients is not None:
|
||||
c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,))
|
||||
for ing in update.ingredients:
|
||||
@@ -932,7 +937,7 @@ def delete_recipe(recipe_id: int, user=Depends(get_current_user)):
|
||||
conn = get_db()
|
||||
row = _check_recipe_permission(conn, recipe_id, user)
|
||||
# Save full snapshot for undo
|
||||
full = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
|
||||
full = conn.execute("SELECT id, name, note, owner_id, version, en_name, volume FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
|
||||
snapshot = _recipe_to_dict(conn, full)
|
||||
log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"],
|
||||
json.dumps(snapshot, ensure_ascii=False))
|
||||
@@ -1595,7 +1600,7 @@ def recipes_by_inventory(user=Depends(get_current_user)):
|
||||
if not inv:
|
||||
conn.close()
|
||||
return []
|
||||
rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
|
||||
rows = conn.execute("SELECT id, name, note, owner_id, version, en_name, volume FROM recipes ORDER BY id").fetchall()
|
||||
result = []
|
||||
for r in rows:
|
||||
recipe = _recipe_to_dict(conn, r)
|
||||
|
||||
@@ -48,13 +48,33 @@ const priceInfo = computed(() => oilsStore.fmtCostWithRetail(props.recipe.ingred
|
||||
const isFav = computed(() => recipesStore.isFavorite(props.recipe))
|
||||
|
||||
const volumeLabel = computed(() => {
|
||||
// Priority 1: stored volume from editor selection
|
||||
const vol = props.recipe.volume
|
||||
if (vol) {
|
||||
if (vol === 'single') return '单次'
|
||||
if (vol === 'custom') return ''
|
||||
if (/^\d+$/.test(vol)) return `${vol}ml`
|
||||
return vol
|
||||
}
|
||||
// Priority 2: calculate from ingredients
|
||||
const ings = props.recipe.ingredients || []
|
||||
const coco = ings.find(i => i.oil === '椰子油')
|
||||
if (!coco || !coco.drops) return ''
|
||||
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`
|
||||
}
|
||||
// Priority 3: sum portion products as ml
|
||||
let totalMl = 0
|
||||
let hasProduct = false
|
||||
for (const ing of ings) {
|
||||
if (!oilsStore.isPortionUnit(ing.oil)) continue
|
||||
hasProduct = true
|
||||
totalMl += ing.drops || 0
|
||||
}
|
||||
if (hasProduct && totalMl > 0) return `${Math.round(totalMl)}ml`
|
||||
return ''
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
<ul style="list-style:none;margin-bottom:20px;padding:0">
|
||||
<li v-for="(ing, i) in cardIngredients" :key="i" class="ec-ing">
|
||||
<span class="ec-oil-name">{{ getCardOilName(ing.oil) }}</span>
|
||||
<span class="ec-drops">{{ ing.drops }} {{ cardLang === 'en' ? (ing.drops === 1 ? 'drop' : 'drops') : '滴' }}</span>
|
||||
<span class="ec-drops">{{ ing.drops }} {{ oilsStore.unitLabelPlural(ing.oil, ing.drops, cardLang) }}</span>
|
||||
<span class="ec-cost">{{ oilsStore.fmtPrice(oilsStore.pricePerDrop(ing.oil) * ing.drops) }}</span>
|
||||
<span v-if="hasRetailForOil(ing.oil) && retailPerDrop(ing.oil) > oilsStore.pricePerDrop(ing.oil)" class="ec-retail">{{ oilsStore.fmtPrice(retailPerDrop(ing.oil) * ing.drops) }}</span>
|
||||
</li>
|
||||
@@ -170,7 +170,7 @@
|
||||
<div class="editor-section">
|
||||
<table class="editor-table">
|
||||
<thead>
|
||||
<tr><th>精油</th><th>滴数</th><th>单价/滴</th><th>小计</th><th></th></tr>
|
||||
<tr><th>成分</th><th>用量</th><th>单价</th><th>小计</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(ing, i) in editEoIngredients" :key="'eo-'+i">
|
||||
@@ -180,8 +180,13 @@
|
||||
<option v-for="name in oilsStore.oilNames" :key="name" :value="name">{{ name }}</option>
|
||||
</select>
|
||||
</td>
|
||||
<td><input v-model.number="ing.drops" type="number" min="0.5" step="0.5" class="editor-drops" /></td>
|
||||
<td class="ing-ppd">{{ ing.oil ? oilsStore.fmtPrice(oilsStore.pricePerDrop(ing.oil)) : '-' }}</td>
|
||||
<td>
|
||||
<div class="drops-with-unit">
|
||||
<input v-model.number="ing.drops" type="number" min="0.5" step="0.5" class="editor-drops" />
|
||||
<span class="unit-hint">{{ oilsStore.unitLabel(ing.oil) }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="ing-ppd">{{ ing.oil ? oilsStore.fmtPrice(oilsStore.pricePerDrop(ing.oil)) : '-' }}/{{ oilsStore.unitLabel(ing.oil) }}</td>
|
||||
<td class="ing-cost">{{ ing.oil ? oilsStore.fmtPrice(oilsStore.pricePerDrop(ing.oil) * (ing.drops || 0)) : '-' }}</td>
|
||||
<td><button class="remove-row-btn" @click="editIngredients.splice(editIngredients.indexOf(ing), 1)">✕</button></td>
|
||||
</tr>
|
||||
@@ -1703,6 +1708,8 @@ async function saveRecipe() {
|
||||
.editor-drops:focus {
|
||||
border-color: var(--sage, #7a9e7e);
|
||||
}
|
||||
.drops-with-unit { display: flex; align-items: center; gap: 2px; }
|
||||
.unit-hint { font-size: 11px; color: #b0aab5; white-space: nowrap; }
|
||||
|
||||
.ing-ppd {
|
||||
font-size: 12px;
|
||||
|
||||
@@ -70,20 +70,23 @@ export const useOilsStore = defineStore('oils', () => {
|
||||
retailPrice: oil.retail_price ?? null,
|
||||
isActive: oil.is_active !== 0,
|
||||
enName: oil.en_name ?? null,
|
||||
unit: oil.unit || 'drop',
|
||||
}
|
||||
}
|
||||
oils.value = newOils
|
||||
oilsMeta.value = newMeta
|
||||
}
|
||||
|
||||
async function saveOil(name, bottlePrice, dropCount, retailPrice, enName = null) {
|
||||
await api.post('/api/oils', {
|
||||
async function saveOil(name, bottlePrice, dropCount, retailPrice, enName = null, unit = null) {
|
||||
const payload = {
|
||||
name,
|
||||
bottle_price: bottlePrice,
|
||||
drop_count: dropCount,
|
||||
retail_price: retailPrice,
|
||||
en_name: enName,
|
||||
})
|
||||
}
|
||||
if (unit) payload.unit = unit
|
||||
await api.post('/api/oils', payload)
|
||||
await loadOils()
|
||||
}
|
||||
|
||||
@@ -93,6 +96,41 @@ export const useOilsStore = defineStore('oils', () => {
|
||||
delete oilsMeta.value[name]
|
||||
}
|
||||
|
||||
const UNIT_LABELS = {
|
||||
drop: { zh: '滴', en: 'drop', enPlural: 'drops' },
|
||||
ml: { zh: 'ml', en: 'ml', enPlural: 'ml' },
|
||||
g: { zh: 'g', en: 'g', enPlural: 'g' },
|
||||
capsule: { zh: '颗', en: 'capsule', enPlural: 'capsules' },
|
||||
}
|
||||
|
||||
function getUnit(name) {
|
||||
const meta = oilsMeta.value[name]
|
||||
return (meta && meta.unit) || 'drop'
|
||||
}
|
||||
|
||||
function isDropUnit(name) {
|
||||
return getUnit(name) === 'drop'
|
||||
}
|
||||
|
||||
function isMlUnit(name) {
|
||||
return getUnit(name) === 'ml'
|
||||
}
|
||||
|
||||
function isPortionUnit(name) {
|
||||
return !isDropUnit(name)
|
||||
}
|
||||
|
||||
function unitLabel(name, lang = 'zh') {
|
||||
const u = UNIT_LABELS[getUnit(name)] || UNIT_LABELS.drop
|
||||
return lang === 'en' ? u.en : u.zh
|
||||
}
|
||||
|
||||
function unitLabelPlural(name, count, lang = 'zh') {
|
||||
const u = UNIT_LABELS[getUnit(name)] || UNIT_LABELS.drop
|
||||
if (lang === 'en') return count === 1 ? u.en : u.enPlural
|
||||
return u.zh
|
||||
}
|
||||
|
||||
return {
|
||||
oils,
|
||||
oilsMeta,
|
||||
@@ -105,5 +143,11 @@ export const useOilsStore = defineStore('oils', () => {
|
||||
loadOils,
|
||||
saveOil,
|
||||
deleteOil,
|
||||
getUnit,
|
||||
isDropUnit,
|
||||
isMlUnit,
|
||||
isPortionUnit,
|
||||
unitLabel,
|
||||
unitLabelPlural,
|
||||
}
|
||||
})
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
class="match-ing"
|
||||
:class="{ missing: !ownedSet.has(ing.oil) }"
|
||||
>
|
||||
{{ ing.oil }} {{ ing.drops }}滴
|
||||
{{ ing.oil }} {{ ing.drops }}{{ oils.unitLabel(ing.oil) }}
|
||||
</span>
|
||||
</div>
|
||||
<div class="match-meta">
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
<div class="diary-name">{{ d.name || '未命名' }}</div>
|
||||
<div class="diary-ings">
|
||||
<span v-for="ing in (d.ingredients || []).slice(0, 3)" :key="ing.oil" class="diary-ing">
|
||||
{{ ing.oil }} {{ ing.drops }}滴
|
||||
{{ ing.oil }} {{ ing.drops }}{{ oils.unitLabel(ing.oil) }}
|
||||
</span>
|
||||
<span v-if="(d.ingredients || []).length > 3" class="diary-more">+{{ (d.ingredients || []).length - 3 }}</span>
|
||||
</div>
|
||||
|
||||
@@ -107,7 +107,12 @@
|
||||
|
||||
<!-- Add Oil Form (toggleable) -->
|
||||
<div v-if="showAddForm && auth.canManage" class="add-oil-form">
|
||||
<div class="form-row">
|
||||
<div class="add-type-tabs">
|
||||
<button class="add-type-tab" :class="{ active: addType === 'oil' }" @click="addType = 'oil'">精油</button>
|
||||
<button class="add-type-tab" :class="{ active: addType === 'product' }" @click="addType = 'product'">其他</button>
|
||||
</div>
|
||||
<!-- 新增精油 -->
|
||||
<div v-if="addType === 'oil'" class="form-row">
|
||||
<input v-model="newOilName" style="flex:1;min-width:120px" placeholder="精油名称" class="form-input-sm" />
|
||||
<input v-model="newOilEnName" style="flex:1;min-width:100px" placeholder="英文名" class="form-input-sm" />
|
||||
<input v-model.number="newBottlePrice" style="width:100px" type="number" step="0.01" min="0" placeholder="会员价 ¥" class="form-input-sm" />
|
||||
@@ -124,6 +129,20 @@
|
||||
<input v-model.number="newRetailPrice" style="width:100px" type="number" step="0.01" min="0" placeholder="零售价 ¥" class="form-input-sm" />
|
||||
<button class="btn btn-primary btn-sm" @click="addOil" :disabled="!newOilName.trim()">➕ 添加</button>
|
||||
</div>
|
||||
<!-- 新增其他产品 -->
|
||||
<div v-else class="form-row">
|
||||
<input v-model="newOilName" style="flex:1;min-width:120px" placeholder="产品名称" class="form-input-sm" />
|
||||
<input v-model="newOilEnName" style="flex:1;min-width:100px" placeholder="英文名" class="form-input-sm" />
|
||||
<input v-model.number="newBottlePrice" style="width:100px" type="number" step="0.01" min="0" placeholder="会员价 ¥" class="form-input-sm" />
|
||||
<input v-model.number="newProductAmount" style="width:70px" type="number" step="1" min="1" placeholder="容量" class="form-input-sm" />
|
||||
<select v-model="newProductUnit" class="form-input-sm" style="width:60px">
|
||||
<option value="ml">ml</option>
|
||||
<option value="g">g</option>
|
||||
<option value="capsule">颗</option>
|
||||
</select>
|
||||
<input v-model.number="newRetailPrice" style="width:100px" type="number" step="0.01" min="0" placeholder="零售价 ¥" class="form-input-sm" />
|
||||
<button class="btn btn-primary btn-sm" @click="addProduct" :disabled="!newOilName.trim() || !newProductAmount">➕ 添加</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Oil Grid -->
|
||||
@@ -146,9 +165,9 @@
|
||||
<div v-if="getMeta(name)?.retailPrice" class="oil-retail-line">¥{{ getMeta(name).retailPrice }}/瓶</div>
|
||||
</template>
|
||||
<template v-else>
|
||||
<div class="oil-price-line">¥{{ oils.pricePerDrop(name).toFixed(2) }}<span class="oil-price-unit">{{ name === '植物空胶囊' ? '/颗' : '/滴' }}</span></div>
|
||||
<div class="oil-price-line">¥{{ oils.pricePerDrop(name).toFixed(2) }}<span class="oil-price-unit">/{{ oilPriceUnit(name) }}</span></div>
|
||||
<div v-if="getMeta(name)?.retailPrice && getMeta(name)?.dropCount" class="oil-retail-line">
|
||||
¥{{ (getMeta(name).retailPrice / getMeta(name).dropCount).toFixed(2) }}{{ name === '植物空胶囊' ? '/颗' : '/滴' }}
|
||||
¥{{ (getMeta(name).retailPrice / getMeta(name).dropCount).toFixed(2) }}/{{ oilPriceUnit(name) }}
|
||||
</div>
|
||||
</template>
|
||||
</div>
|
||||
@@ -172,7 +191,7 @@
|
||||
<div class="oil-card-price-info" v-if="getMeta(activeCardName)">
|
||||
¥ {{ (getMeta(activeCardName).bottlePrice || 0).toFixed(2) }}
|
||||
<span v-if="oils.pricePerDrop(activeCardName)">
|
||||
· ¥ {{ oils.pricePerDrop(activeCardName).toFixed(4) }}/滴
|
||||
· ¥ {{ oils.pricePerDrop(activeCardName).toFixed(4) }}/{{ oilPriceUnit(activeCardName) }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -216,7 +235,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Simple Oil Detail Panel (for oils without a knowledge card) -->
|
||||
<div v-if="selectedOilName && !activeCard" class="modal-overlay" @click.self="selectedOilName = null">
|
||||
<div v-if="selectedOilName && !activeCard" class="modal-overlay" @mousedown.self="selectedOilName = null">
|
||||
<div class="oil-detail-panel">
|
||||
<div class="detail-header">
|
||||
<div>
|
||||
@@ -226,32 +245,58 @@
|
||||
<button class="btn-close" @click="selectedOilName = null">✕</button>
|
||||
</div>
|
||||
<div class="detail-body">
|
||||
<!-- 精油(非ml产品) -->
|
||||
<template v-if="oils.isDropUnit(selectedOilName)">
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">总容量</span>
|
||||
<span class="detail-value">{{ volumeWithDrops(selectedOilName) }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">会员价</span>
|
||||
<span class="detail-value">{{ getMeta(selectedOilName)?.bottlePrice != null ? ('¥ ' + getMeta(selectedOilName).bottlePrice.toFixed(2)) : '--' }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">总滴数</span>
|
||||
<span class="detail-value">{{ getMeta(selectedOilName)?.dropCount || '--' }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">每滴价格</span>
|
||||
<span class="detail-label">每{{ oilPriceUnit(selectedOilName) }}价格</span>
|
||||
<span class="detail-value">{{ oils.pricePerDrop(selectedOilName) ? ('¥ ' + oils.pricePerDrop(selectedOilName).toFixed(4)) : '--' }}</span>
|
||||
</div>
|
||||
<div class="detail-row" v-if="getMeta(selectedOilName)?.retailPrice">
|
||||
<span class="detail-label">零售价</span>
|
||||
<span class="detail-value">¥ {{ getMeta(selectedOilName).retailPrice.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">每ml价格</span>
|
||||
<span class="detail-value">{{ oils.pricePerDrop(selectedOilName) ? ('¥ ' + (oils.pricePerDrop(selectedOilName) * DROPS_PER_ML).toFixed(2)) : '--' }}</span>
|
||||
<div class="detail-row" v-if="getMeta(selectedOilName)?.retailPrice && getMeta(selectedOilName)?.dropCount">
|
||||
<span class="detail-label">每{{ oilPriceUnit(selectedOilName) }}价格</span>
|
||||
<span class="detail-value">¥ {{ (getMeta(selectedOilName).retailPrice / getMeta(selectedOilName).dropCount).toFixed(4) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
<!-- ml产品 -->
|
||||
<template v-else>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">总容量</span>
|
||||
<span class="detail-value">{{ getMeta(selectedOilName)?.dropCount || '--' }}{{ oils.unitLabel(selectedOilName) }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">会员价</span>
|
||||
<span class="detail-value">{{ getMeta(selectedOilName)?.bottlePrice != null ? ('¥ ' + getMeta(selectedOilName).bottlePrice.toFixed(2)) : '--' }}</span>
|
||||
</div>
|
||||
<div class="detail-row">
|
||||
<span class="detail-label">每{{ oils.unitLabel(selectedOilName) }}价格</span>
|
||||
<span class="detail-value">{{ oils.pricePerDrop(selectedOilName) ? ('¥ ' + oils.pricePerDrop(selectedOilName).toFixed(2)) : '--' }}</span>
|
||||
</div>
|
||||
<div class="detail-row" v-if="getMeta(selectedOilName)?.retailPrice">
|
||||
<span class="detail-label">零售价</span>
|
||||
<span class="detail-value">¥ {{ getMeta(selectedOilName).retailPrice.toFixed(2) }}</span>
|
||||
</div>
|
||||
<div class="detail-row" v-if="getMeta(selectedOilName)?.retailPrice && getMeta(selectedOilName)?.dropCount">
|
||||
<span class="detail-label">每{{ oils.unitLabel(selectedOilName) }}价格</span>
|
||||
<span class="detail-value">¥ {{ (getMeta(selectedOilName).retailPrice / getMeta(selectedOilName).dropCount).toFixed(2) }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<h4 style="margin:16px 0 8px">含此精油的配方</h4>
|
||||
<h4 style="margin:16px 0 8px">含此{{ oils.isDropUnit(selectedOilName) ? '精油' : '产品' }}的配方</h4>
|
||||
<div v-if="recipesWithOil.length" class="detail-recipes">
|
||||
<div v-for="r in recipesWithOil" :key="r._id" class="detail-recipe-item">
|
||||
<span class="dr-name">{{ r.name }}</span>
|
||||
<span class="dr-drops">{{ getDropsForOil(r, selectedOilName) }}滴</span>
|
||||
<span class="dr-drops">{{ getDropsForOil(r, selectedOilName) }}{{ oils.unitLabel(selectedOilName) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="empty-hint">暂无使用此精油的配方</div>
|
||||
@@ -260,7 +305,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Edit Oil Overlay -->
|
||||
<div v-if="editingOilName" class="modal-overlay" @click.self="editingOilName = null" @keydown.enter="$event.isComposing || saveEditOil()">
|
||||
<div v-if="editingOilName" class="modal-overlay" @mousedown.self="editingOilName = null" @keydown.enter="$event.isComposing || saveEditOil()">
|
||||
<div class="modal-panel">
|
||||
<div class="modal-header">
|
||||
<h3>{{ editingOilName }}</h3>
|
||||
@@ -387,12 +432,15 @@ const activeCardName = ref(null)
|
||||
const activeCard = ref(null)
|
||||
|
||||
// Add oil form
|
||||
const addType = ref('oil')
|
||||
const newOilName = ref('')
|
||||
const newOilEnName = ref('')
|
||||
const newBottlePrice = ref(null)
|
||||
const newVolume = ref('5')
|
||||
const newCustomDrops = ref(null)
|
||||
const newRetailPrice = ref(null)
|
||||
const newProductAmount = ref(null)
|
||||
const newProductUnit = ref('ml')
|
||||
|
||||
// Edit oil
|
||||
const editingOilName = ref(null)
|
||||
@@ -472,11 +520,24 @@ for (const [ml, drops] of Object.entries(VOLUME_OPTIONS)) {
|
||||
DROPS_TO_VOLUME[drops] = ml + 'ml'
|
||||
}
|
||||
|
||||
function oilPriceUnit(name) {
|
||||
return oils.unitLabel(name)
|
||||
}
|
||||
|
||||
function volumeLabel(dropCount, name) {
|
||||
if (dropCount === 160) return '160颗'
|
||||
if (!oils.isDropUnit(name)) return dropCount + oils.unitLabel(name)
|
||||
return DROPS_TO_VOLUME[dropCount] || (dropCount + '滴')
|
||||
}
|
||||
|
||||
function volumeWithDrops(name) {
|
||||
const meta = getMeta(name)
|
||||
if (!meta || !meta.dropCount) return '--'
|
||||
if (!oils.isDropUnit(name)) return meta.dropCount + oils.unitLabel(name)
|
||||
const ml = DROPS_TO_VOLUME[meta.dropCount]
|
||||
if (ml) return `${ml}/${meta.dropCount}滴`
|
||||
return meta.dropCount + '滴'
|
||||
}
|
||||
|
||||
function chipStyle(name) {
|
||||
const hasCard = !!getOilCard(name)
|
||||
if (hasCard) return 'cursor:pointer;border-left:3px solid var(--sage);background:linear-gradient(90deg,var(--sage-mist),white)'
|
||||
@@ -618,6 +679,29 @@ async function addOil() {
|
||||
}
|
||||
}
|
||||
|
||||
async function addProduct() {
|
||||
if (!newOilName.value.trim() || !newProductAmount.value) return
|
||||
try {
|
||||
await oils.saveOil(
|
||||
newOilName.value.trim(),
|
||||
newBottlePrice.value || 0,
|
||||
newProductAmount.value,
|
||||
newRetailPrice.value || null,
|
||||
newOilEnName.value.trim() || null,
|
||||
newProductUnit.value
|
||||
)
|
||||
ui.showToast(`已添加: ${newOilName.value}`)
|
||||
newOilName.value = ''
|
||||
newOilEnName.value = ''
|
||||
newBottlePrice.value = null
|
||||
newProductAmount.value = null
|
||||
newProductUnit.value = 'ml'
|
||||
newRetailPrice.value = null
|
||||
} catch (e) {
|
||||
ui.showToast('添加失败: ' + (e.message || ''))
|
||||
}
|
||||
}
|
||||
|
||||
function editOil(name) {
|
||||
editingOilName.value = name
|
||||
editOilDisplayName.value = name
|
||||
@@ -1026,12 +1110,24 @@ async function saveCardImage(name) {
|
||||
}
|
||||
|
||||
/* ===== Add Oil Form ===== */
|
||||
.add-type-tabs { display: flex; gap: 0; margin-bottom: 10px; }
|
||||
.add-type-tab {
|
||||
padding: 6px 20px; text-align: center; font-size: 13px; cursor: pointer;
|
||||
border: 1.5px solid var(--border, #d4cfc7); background: #fff; color: var(--text-mid, #6b6375);
|
||||
font-family: inherit;
|
||||
}
|
||||
.add-type-tab:first-child { border-radius: 8px 0 0 8px; }
|
||||
.add-type-tab:last-child { border-radius: 0 8px 8px 0; border-left: none; }
|
||||
.add-type-tab.active { background: var(--sage, #7a9e7e); color: #fff; border-color: var(--sage, #7a9e7e); }
|
||||
|
||||
.add-oil-form {
|
||||
margin-bottom: 16px;
|
||||
padding: 14px;
|
||||
background: var(--sage-mist, #eef4ee);
|
||||
border-radius: 12px;
|
||||
border: 1.5px solid var(--border, #e0d4c0);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
/* Hide number input spinners in add form */
|
||||
.add-oil-form input[type="number"]::-webkit-inner-spin-button,
|
||||
|
||||
@@ -171,7 +171,7 @@
|
||||
/>
|
||||
<div class="row-info" @click="editRecipe(r)">
|
||||
<span class="row-name">{{ r.name }}</span>
|
||||
<span v-if="getVolumeLabel(r.ingredients)" class="row-volume">{{ getVolumeLabel(r.ingredients) }}</span>
|
||||
<span v-if="getVolumeLabel(r.ingredients, r.volume)" class="row-volume">{{ getVolumeLabel(r.ingredients, r.volume) }}</span>
|
||||
<span class="row-tags">
|
||||
<span v-for="t in [...(r.tags || [])].sort((a,b)=>a.localeCompare(b,'zh'))" :key="t" class="mini-tag">{{ t }}</span>
|
||||
</span>
|
||||
@@ -271,7 +271,7 @@
|
||||
<div class="editor-section">
|
||||
<table class="editor-table">
|
||||
<thead>
|
||||
<tr><th>精油</th><th>滴数</th><th>单价/滴</th><th>小计</th><th></th></tr>
|
||||
<tr><th>成分</th><th>用量</th><th>单价</th><th>小计</th><th></th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(ing, i) in formEoIngredients" :key="'eo-'+i">
|
||||
@@ -296,8 +296,13 @@
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td><input v-model.number="ing.drops" type="number" min="0.5" step="0.5" class="editor-drops" /></td>
|
||||
<td class="ing-ppd">{{ ing.oil ? oils.fmtPrice(oils.pricePerDrop(ing.oil)) : '-' }}</td>
|
||||
<td>
|
||||
<div class="drops-with-unit">
|
||||
<input v-model.number="ing.drops" type="number" min="0.5" step="0.5" class="editor-drops" />
|
||||
<span class="unit-hint">{{ oils.unitLabel(ing.oil) }}</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="ing-ppd">{{ ing.oil ? oils.fmtPrice(oils.pricePerDrop(ing.oil)) : '-' }}/{{ oils.unitLabel(ing.oil) }}</td>
|
||||
<td class="ing-cost">{{ ing.oil && ing.drops ? oils.fmtPrice(oils.pricePerDrop(ing.oil) * ing.drops) : '-' }}</td>
|
||||
<td><button class="remove-row-btn" @click="removeEoRow(i)">✕</button></td>
|
||||
</tr>
|
||||
@@ -772,8 +777,15 @@ function editRecipe(recipe) {
|
||||
const coco = ings.find(i => i.oil === '椰子油')
|
||||
if (coco) {
|
||||
formCocoRow.value = { ...coco, _search: '椰子油', _open: false }
|
||||
// Guess volume from total drops
|
||||
const eoDrops = ings.filter(i => i.oil && i.oil !== '椰子油').reduce((s, i) => s + (i.drops || 0), 0)
|
||||
// Use stored volume if available, otherwise guess from drops
|
||||
if (recipe.volume) {
|
||||
formVolume.value = recipe.volume
|
||||
if (recipe.volume === 'custom') {
|
||||
const totalDrops = eoDrops + coco.drops
|
||||
formCustomVolume.value = Math.round(totalDrops / DROPS_PER_ML)
|
||||
}
|
||||
} else {
|
||||
const totalDrops = eoDrops + coco.drops
|
||||
const ml = totalDrops / DROPS_PER_ML
|
||||
if (ml <= 2) formVolume.value = 'single'
|
||||
@@ -783,6 +795,7 @@ function editRecipe(recipe) {
|
||||
else if (Math.abs(ml - 20) < 3) formVolume.value = '20'
|
||||
else if (Math.abs(ml - 30) < 6) formVolume.value = '30'
|
||||
else { formVolume.value = 'custom'; formCustomVolume.value = Math.round(ml) }
|
||||
}
|
||||
// Guess dilution
|
||||
if (eoDrops > 0 && coco.drops > 0) {
|
||||
const ratio = Math.round(coco.drops / eoDrops)
|
||||
@@ -867,7 +880,7 @@ function selectOil(ing, name) {
|
||||
// Check for duplicate oil in current recipe
|
||||
const existing = formIngredients.value.find(i => i !== ing && i.oil === name)
|
||||
if (existing) {
|
||||
ui.showToast(`已有「${name}」,请直接修改滴数`)
|
||||
ui.showToast(`已有「${name}」,请直接修改用量`)
|
||||
ing._open = false
|
||||
return
|
||||
}
|
||||
@@ -1019,8 +1032,8 @@ async function checkDupName(name, ings, target = 'diary') {
|
||||
return false
|
||||
}
|
||||
|
||||
const existIngs = dupIngs.map(i => `${i.oil}${i.drops}滴`).join('、')
|
||||
const newIngs = myIngs.map(i => `${i.oil}${i.drops}滴`).join('、')
|
||||
const existIngs = dupIngs.map(i => `${i.oil}${i.drops}${oils.unitLabel(i.oil)}`).join('、')
|
||||
const newIngs = myIngs.map(i => `${i.oil}${i.drops}${oils.unitLabel(i.oil)}`).join('、')
|
||||
const ok = await showConfirm(
|
||||
`${where}中已有同名配方「${currentName}」,内容不同:\n\n已有:${existIngs}\n新的:${newIngs}\n\n请改名后保存`,
|
||||
{ okText: '改名', cancelText: '取消' }
|
||||
@@ -1086,6 +1099,7 @@ async function saveCurrentRecipe() {
|
||||
ingredients: mappedIngs,
|
||||
note: formNote.value,
|
||||
tags: formTags.value,
|
||||
volume: formVolume.value || '',
|
||||
}
|
||||
try {
|
||||
await recipeStore.saveRecipe(payload)
|
||||
@@ -1450,15 +1464,34 @@ function openRecipeDetail(recipe) {
|
||||
if (idx >= 0) previewRecipeIndex.value = idx
|
||||
}
|
||||
|
||||
function getVolumeLabel(ingredients) {
|
||||
function getVolumeLabel(ingredients, volume) {
|
||||
// Priority 1: stored volume
|
||||
if (volume) {
|
||||
if (volume === 'single') return '单次'
|
||||
if (volume === 'custom') return ''
|
||||
if (/^\d+$/.test(volume)) return `${volume}ml`
|
||||
return volume
|
||||
}
|
||||
// Priority 2: calculate from ingredients
|
||||
const ings = ingredients || []
|
||||
const coco = ings.find(i => i.oil === '椰子油')
|
||||
if (!coco || !coco.drops) return ''
|
||||
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`
|
||||
}
|
||||
// Priority 3: sum portion products as 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 ''
|
||||
}
|
||||
|
||||
function diaryMatchesPublic(d) {
|
||||
const pub = recipeStore.recipes.find(r => r.name === d.name)
|
||||
@@ -1563,7 +1596,7 @@ function recipesIdentical(a, b) {
|
||||
}
|
||||
|
||||
function formatIngsCompare(ings) {
|
||||
return (ings || []).map(i => `${i.oil} ${i.drops}滴`).join('、')
|
||||
return (ings || []).map(i => `${i.oil} ${i.drops}${oils.unitLabel(i.oil)}`).join('、')
|
||||
}
|
||||
|
||||
async function approveRecipe(recipe) {
|
||||
@@ -1645,7 +1678,7 @@ async function exportExcel() {
|
||||
return list.map(r => ({
|
||||
'配方名称': r.name,
|
||||
'标签': (r.tags || []).join('/'),
|
||||
'精油成分': r.ingredients.map(i => `${i.oil}${i.drops}滴`).join('、'),
|
||||
'精油成分': r.ingredients.map(i => `${i.oil}${i.drops}${oils.unitLabel(i.oil)}`).join('、'),
|
||||
'成本': oils.fmtPrice(oils.calcCost(r.ingredients)),
|
||||
'备注': r.note || '',
|
||||
}))
|
||||
@@ -2081,6 +2114,8 @@ watch(() => recipeStore.recipes, () => {
|
||||
.editor-table td { padding: 6px 4px; border-bottom: 1px solid #f5f5f5; }
|
||||
.editor-drops { width: 65px; padding: 6px 8px; border: 1.5px solid #d4cfc7; border-radius: 8px; font-size: 13px; text-align: center; outline: none; font-family: inherit; }
|
||||
.editor-drops:focus { border-color: #7ec6a4; }
|
||||
.drops-with-unit { display: flex; align-items: center; gap: 2px; }
|
||||
.unit-hint { font-size: 11px; color: #b0aab5; white-space: nowrap; }
|
||||
.editor-input { padding: 8px 10px; border: 1.5px solid #d4cfc7; border-radius: 8px; font-size: 13px; outline: none; font-family: inherit; width: 100%; box-sizing: border-box; }
|
||||
.editor-input:focus { border-color: #7ec6a4; }
|
||||
.editor-textarea { width: 100%; padding: 8px 10px; border: 1.5px solid #d4cfc7; border-radius: 8px; font-size: 13px; font-family: inherit; outline: none; resize: vertical; box-sizing: border-box; }
|
||||
|
||||
Reference in New Issue
Block a user