feat: 通用单位系统 — drop/ml/g/capsule,去掉硬编码
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 3m5s

unit字段支持4种值,所有显示自动适配:
- drop: 精油(滴/drop)
- ml: 液体产品(ml)
- g: 膏霜产品(g)
- capsule: 胶囊(颗/capsule)
新增产品选单位即可,无需改代码。

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 16:10:36 +00:00
parent 7bcb1d1a5b
commit eeb9b0aa88
2 changed files with 48 additions and 27 deletions

View File

@@ -94,25 +94,39 @@ export const useOilsStore = defineStore('oils', () => {
delete oilsMeta.value[name]
}
function isMlUnit(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 === 'ml'
return (meta && meta.unit) || 'drop'
}
function isDropUnit(name) {
return getUnit(name) === 'drop'
}
function isMlUnit(name) {
return getUnit(name) === 'ml'
}
function isPortionUnit(name) {
return isMlUnit(name)
return !isDropUnit(name)
}
function unitLabel(name, lang = 'zh') {
if (isMlUnit(name)) return 'ml'
if (name === '植物空胶囊') return lang === 'en' ? 'capsule' : '颗'
return lang === 'en' ? 'drop' : '滴'
const u = UNIT_LABELS[getUnit(name)] || UNIT_LABELS.drop
return lang === 'en' ? u.en : u.zh
}
function unitLabelPlural(name, count, lang = 'zh') {
if (isMlUnit(name)) return 'ml'
if (name === '植物空胶囊') return lang === 'en' ? (count === 1 ? 'capsule' : 'capsules') : '颗'
return lang === 'en' ? (count === 1 ? 'drop' : 'drops') : '滴'
const u = UNIT_LABELS[getUnit(name)] || UNIT_LABELS.drop
if (lang === 'en') return count === 1 ? u.en : u.enPlural
return u.zh
}
return {
@@ -127,6 +141,8 @@ export const useOilsStore = defineStore('oils', () => {
loadOils,
saveOil,
deleteOil,
getUnit,
isDropUnit,
isMlUnit,
isPortionUnit,
unitLabel,