Compare commits
16 Commits
fix/next-b
...
fix/next-b
| Author | SHA1 | Date | |
|---|---|---|---|
| eeb9b0aa88 | |||
| 7bcb1d1a5b | |||
| 371aa74c31 | |||
| 395e837de8 | |||
| 7abc219659 | |||
| 9beddc387a | |||
| b28b1c7f62 | |||
| 9f072e48f8 | |||
| a3bf13c58d | |||
| fba66b42c2 | |||
| 67d268bc92 | |||
| abc54f2d6a | |||
| 6d1ae6e682 | |||
| 1790ab3b44 | |||
| 36862a4dbe | |||
| eae9d507f2 |
@@ -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()]
|
||||
|
||||
@@ -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):
|
||||
@@ -715,7 +716,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 +725,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}))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { recipeNameEn, oilEn } from '../composables/useOilTranslation'
|
||||
import { matchesPinyinInitials, getPinyinInitials } from '../composables/usePinyinMatch'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// EDITOR_ONLY_TAGS includes '已下架'
|
||||
@@ -283,3 +284,95 @@ describe('one-time username change guard', () => {
|
||||
expect(!!user.username_changed).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Pinyin matching — PR29 extended coverage
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('pinyin matching — extended oil names', () => {
|
||||
it('matches mlk → 麦卢卡', () => {
|
||||
expect(matchesPinyinInitials('麦卢卡', 'mlk')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches tx → 檀香', () => {
|
||||
expect(matchesPinyinInitials('檀香', 'tx')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches xm → 香茅', () => {
|
||||
expect(matchesPinyinInitials('香茅', 'xm')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches gbxz → 古巴香脂', () => {
|
||||
expect(matchesPinyinInitials('古巴香脂', 'gbxz')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches my → 没药', () => {
|
||||
expect(matchesPinyinInitials('没药', 'my')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches xhx → 小茴香', () => {
|
||||
expect(matchesPinyinInitials('小茴香', 'xhx')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches jybh → 椒样薄荷', () => {
|
||||
expect(matchesPinyinInitials('椒样薄荷', 'jybh')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches xbynz → 西班牙牛至', () => {
|
||||
expect(matchesPinyinInitials('西班牙牛至', 'xbynz')).toBe(true)
|
||||
})
|
||||
|
||||
it('matches sc → 顺畅呼吸 prefix', () => {
|
||||
expect(matchesPinyinInitials('顺畅呼吸', 'sc')).toBe(true)
|
||||
})
|
||||
|
||||
it('does not match wrong initials', () => {
|
||||
expect(matchesPinyinInitials('麦卢卡', 'abc')).toBe(false)
|
||||
})
|
||||
|
||||
it('getPinyinInitials returns correct string', () => {
|
||||
expect(getPinyinInitials('麦卢卡')).toBe('mlk')
|
||||
expect(getPinyinInitials('檀香')).toBe('tx')
|
||||
expect(getPinyinInitials('没药')).toBe('my')
|
||||
})
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Viewer tag visibility — PR29
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('viewer tag visibility logic', () => {
|
||||
const EDITOR_ONLY_TAGS_VAL = ['已审核', '已下架']
|
||||
|
||||
it('editor sees all tags', () => {
|
||||
const allTags = ['美容', '儿童', '已审核', '已下架']
|
||||
const canEdit = true
|
||||
const visible = canEdit ? allTags : []
|
||||
expect(visible).toEqual(allTags)
|
||||
})
|
||||
|
||||
it('viewer sees no public tags', () => {
|
||||
const canEdit = false
|
||||
const myDiary = [
|
||||
{ tags: ['我的标签'] },
|
||||
{ tags: ['我的标签', '另一个'] },
|
||||
]
|
||||
// Viewer: collect tags from own diary only
|
||||
const myTags = new Set()
|
||||
for (const d of myDiary) {
|
||||
for (const t of (d.tags || [])) myTags.add(t)
|
||||
}
|
||||
const visible = canEdit ? ['美容', '已审核'] : [...myTags]
|
||||
expect(visible).toContain('我的标签')
|
||||
expect(visible).toContain('另一个')
|
||||
expect(visible).not.toContain('美容')
|
||||
expect(visible).not.toContain('已审核')
|
||||
})
|
||||
|
||||
it('viewer with no diary tags sees empty', () => {
|
||||
const myDiary = []
|
||||
const myTags = new Set()
|
||||
for (const d of myDiary) {
|
||||
for (const t of (d.tags || [])) myTags.add(t)
|
||||
}
|
||||
expect([...myTags]).toHaveLength(0)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -50,11 +50,21 @@ const isFav = computed(() => recipesStore.isFavorite(props.recipe))
|
||||
const volumeLabel = computed(() => {
|
||||
const ings = props.recipe.ingredients || []
|
||||
const coco = ings.find(i => i.oil === '椰子油')
|
||||
if (!coco || !coco.drops) return ''
|
||||
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`
|
||||
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`
|
||||
}
|
||||
// Non-coconut: check if has portion product, extract volume from note
|
||||
const hasPortion = ings.some(i => oilsStore.isPortionUnit(i.oil))
|
||||
if (hasPortion) {
|
||||
const note = props.recipe.note || ''
|
||||
const m = note.match(/(\d+)\s*(ml|毫升|克|g)/i)
|
||||
if (m) return `${m[1]}${m[2].toLowerCase()}`
|
||||
return '调配'
|
||||
}
|
||||
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;
|
||||
|
||||
@@ -57,6 +57,25 @@ const PINYIN_MAP = {
|
||||
'触': 'c', '修': 'x', '养': 'y', '滋': 'z', '润': 'r',
|
||||
'呼': 'h', '吸': 'x', '消': 'x', '化': 'h', '排': 'p',
|
||||
'毒': 'd', '净': 'j', '纤': 'x', '体': 't', '塑': 's',
|
||||
// Extended: all oil name chars
|
||||
'麦': 'm', '卢': 'l', '卡': 'k', '檀': 't', '橘': 'j',
|
||||
'茅': 'm', '茴': 'h', '芹': 'q', '菜': 'c', '蕾': 'l',
|
||||
'蜂': 'f', '蓍': 's', '莱': 'l', '姆': 'm', '莎': 's',
|
||||
'穗': 's', '醇': 'c', '郁': 'y', '没': 'm', '脂': 'z',
|
||||
'巴': 'b', '样': 'y', '班': 'b', '牙': 'y', '鸡': 'j',
|
||||
'苍': 'c', '卫': 'w', '畅': 'c', '顺': 's', '释': 's',
|
||||
'悦': 'y', '柔': 'r', '压': 'y', '定': 'd', '情': 'q',
|
||||
'绪': 'x', '神': 's', '气': 'q', '宽': 'k', '容': 'r',
|
||||
'恬': 't', '家': 'j', '欢': 'h', '欣': 'x', '舞': 'w',
|
||||
'鼓': 'g', '赋': 'f', '谧': 'm', '睡': 's', '烂': 'l',
|
||||
'绚': 'x', '焕': 'h', '肤': 'f', '年': 'n', '华': 'h',
|
||||
'完': 'w', '理': 'l', '注': 'z', '贯': 'g', '全': 'q',
|
||||
'仕': 's', '女': 'nv', '伯': 'b', '斯': 's', '道': 'd',
|
||||
'格': 'g', '拉': 'l', '元': 'y', '肌': 'j', '栀': 'z',
|
||||
'鹅': 'e', '掌': 'z', '柴': 'c', '胶': 'j', '囊': 'n',
|
||||
'空': 'k', '风': 'f', '文': 'w', '月': 'y', '云': 'y',
|
||||
'五': 'w', '味': 'w', '愈': 'y', '创': 'c', '慰': 'w',
|
||||
'扁': 'b', '广': 'g', '州': 'z', '热': 'r',
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -70,6 +70,7 @@ 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
|
||||
@@ -93,6 +94,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 +141,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>
|
||||
|
||||
@@ -146,9 +146,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 +172,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>
|
||||
@@ -226,32 +226,58 @@
|
||||
<button class="btn-close" @click="selectedOilName = null">✕</button>
|
||||
</div>
|
||||
<div class="detail-body">
|
||||
<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-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>
|
||||
<!-- 精油(非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">每{{ 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" 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>
|
||||
@@ -472,11 +498,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)'
|
||||
|
||||
@@ -83,7 +83,7 @@
|
||||
</div>
|
||||
<div class="candidate-tags">
|
||||
<span
|
||||
v-for="tag in recipeStore.allTags.filter(t => !batchTagsSelected.includes(t))"
|
||||
v-for="tag in visibleAllTags.filter(t => !batchTagsSelected.includes(t))"
|
||||
:key="tag"
|
||||
class="candidate-tag"
|
||||
@click="batchTagsSelected.push(tag)"
|
||||
@@ -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>
|
||||
@@ -1019,8 +1024,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: '取消' }
|
||||
@@ -1308,9 +1313,13 @@ const previewRecipeIndex = ref(null)
|
||||
const previewRecipeData = ref(null)
|
||||
const showBatchMenu = ref(false)
|
||||
const visibleAllTags = computed(() => {
|
||||
const tags = recipeStore.allTags
|
||||
if (auth.canEdit) return tags
|
||||
return tags.filter(t => !EDITOR_ONLY_TAGS.includes(t))
|
||||
if (auth.canEdit) return recipeStore.allTags
|
||||
// Viewer: only show tags from their own diary recipes
|
||||
const myTags = new Set()
|
||||
for (const d of diaryStore.userDiary) {
|
||||
for (const t of (d.tags || [])) myTags.add(t)
|
||||
}
|
||||
return [...myTags].sort((a, b) => a.localeCompare(b, 'zh'))
|
||||
})
|
||||
const showBatchTagPicker = ref(false)
|
||||
const batchTagsSelected = ref([])
|
||||
@@ -2077,6 +2086,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; }
|
||||
|
||||
@@ -91,18 +91,18 @@
|
||||
</div>
|
||||
<div class="user-actions">
|
||||
<select
|
||||
v-if="u.role !== 'admin'"
|
||||
:value="u.role"
|
||||
class="role-select"
|
||||
@change="changeRole(u, $event.target.value)"
|
||||
:disabled="u.role === 'admin'"
|
||||
>
|
||||
<option value="viewer">查看者</option>
|
||||
<option value="editor">编辑</option>
|
||||
<option value="senior_editor">高级编辑</option>
|
||||
</select>
|
||||
<button v-if="!u.business_verified" class="btn-sm btn-outline" @click="grantBusiness(u)" title="开通商业认证">💼</button>
|
||||
<button v-else class="btn-sm btn-outline" @click="revokeBusiness(u)" title="撤销商业认证" style="opacity:0.5">💼✕</button>
|
||||
<button class="btn-sm btn-delete" @click="removeUser(u)" title="删除用户">🗑️</button>
|
||||
<button v-if="u.business_verified" class="btn-sm btn-outline" @click="revokeBusiness(u)" title="撤销商业认证">💼</button>
|
||||
<button v-else class="btn-sm btn-outline" @click="grantBusiness(u)" title="开通商业认证" style="opacity:0.3">💼</button>
|
||||
<button class="btn-sm btn-delete" @click="removeUser(u)" :disabled="u.role === 'admin'" title="删除用户">🗑️</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="filteredUsers.length === 0" class="empty-hint">未找到用户</div>
|
||||
@@ -162,10 +162,10 @@ function formatDate(d) {
|
||||
}
|
||||
|
||||
const roles = [
|
||||
{ value: 'admin', label: '管理员' },
|
||||
{ value: 'senior_editor', label: '高级编辑' },
|
||||
{ value: 'editor', label: '编辑' },
|
||||
{ value: 'viewer', label: '查看者' },
|
||||
{ value: 'business', label: '企业用户' },
|
||||
]
|
||||
|
||||
const filteredUsers = computed(() => {
|
||||
@@ -178,7 +178,11 @@ const filteredUsers = computed(() => {
|
||||
)
|
||||
}
|
||||
if (filterRole.value) {
|
||||
list = list.filter(u => u.role === filterRole.value)
|
||||
if (filterRole.value === 'business') {
|
||||
list = list.filter(u => u.business_verified)
|
||||
} else {
|
||||
list = list.filter(u => u.role === filterRole.value)
|
||||
}
|
||||
}
|
||||
return list
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user