This commit is contained in:
zlwu committed 2026-07-11 17:15:17 +08:00
1 parent 843e13bce3
commit 7b1d4c8729
629 files changed
+74059 -7929

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
export function formatYuan(v) {
if (v == null || v === '') return '0.00'
const n = Number(v)
if (Number.isNaN(n)) return '0.00'
return n.toFixed(2)
}
export function formatFenAsYuan(fen) {
if (fen == null || Number.isNaN(fen)) return '0.00'
return (fen / 100).toFixed(2)
}
/**
* 计量 + 单位 +(规格),如 500 克(礼盒装);无规格时不显示括号
*/
export function formatMeasureUnitSpec(measureValue, unitName, spec) {
const unitText = (unitName || '').trim()
const specText = spec != null ? String(spec).trim() : ''
let base = ''
if (measureValue != null && measureValue !== '') {
const num = Number(measureValue)
if (!Number.isNaN(num)) {
const measureText = String(num).replace(/\.?0+$/, '')
base = unitText ? `${measureText} ${unitText}` : measureText
} else {
const measureText = String(measureValue).trim()
base = unitText ? `${measureText} ${unitText}` : measureText
}
} else if (unitText) {
base = unitText
} else if (!specText) {
return '-'
}
if (specText) {
return base ? `${base}(${specText})` : `(${specText})`
}
return base || '-'
}
/** 数量 × 计量单位(规格),如 10×500 克(礼盒装) */
export function formatQtyMeasureUnitSpec(qty, measureValue, unitName, spec) {
const inner = formatMeasureUnitSpec(measureValue, unitName, spec)
if (inner === '-') return String(qty)
return `${qty}×${inner}`
}