imeik-bizui 2.7.5 → 2.7.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -172,7 +172,7 @@ function buildSections(data = {}) {
172
172
  label: '合计(含本次)',
173
173
  theme: 'danger',
174
174
  values: [
175
- `数量 ${formatNumber(sumBy(nonSaleRows, 'qty'))}`,
175
+ `数量 ${sumBy(nonSaleRows, 'qty')}`,
176
176
  `折算费用 ${formatNumber(sumBy(nonSaleRows, 'amount'))}`
177
177
  ]
178
178
  }
@@ -10,7 +10,38 @@ export function roundMoney(value) {
10
10
  }
11
11
 
12
12
  /**
13
- * 数值展示:默认按接口原样(不千分位、不截断小数位)。
13
+ * 价格展示:不足 minDigits 位小数右侧补 0;已达则原样(不截断、不去尾)。
14
+ * 201 → 201.00;5756.3 → 5756.30;433.68 → 433.68;1442.7875 → 1442.7875
15
+ */
16
+ export function padDecimalMin(value, minDigits = 2) {
17
+ if (value === undefined || value === null || value === '') return null
18
+
19
+ let raw
20
+ if (typeof value === 'string') {
21
+ raw = value.trim()
22
+ if (raw === '') return null
23
+ if (Number.isNaN(Number(raw))) return raw
24
+ } else {
25
+ const n = Number(value)
26
+ if (Number.isNaN(n)) return String(value)
27
+ raw = String(n)
28
+ }
29
+
30
+ const sign = raw[0] === '-' ? '-' : ''
31
+ const body = sign ? raw.slice(1) : raw
32
+ if (!/^\d+(\.\d+)?$/.test(body)) return raw
33
+
34
+ const dot = body.indexOf('.')
35
+ if (dot < 0) {
36
+ return `${sign}${body}.${'0'.repeat(minDigits)}`
37
+ }
38
+ const decLen = body.length - dot - 1
39
+ if (decLen >= minDigits) return `${sign}${body}`
40
+ return `${sign}${body}${'0'.repeat(minDigits - decLen)}`
41
+ }
42
+
43
+ /**
44
+ * 数值展示:默认「不足两位补 0,两位及以上原样」。
14
45
  * 仅当显式传入 digits 时才按固定小数位输出。
15
46
  * 注意:toLocaleString 默认最多 3 位小数,会导致四位金额被截断,故原样路径不用它。
16
47
  */
@@ -18,15 +49,9 @@ export function formatNumber(value, { digits = null, fallback = '-' } = {}) {
18
49
  if (value === undefined || value === null || value === '') return fallback
19
50
 
20
51
  if (digits === null || digits === undefined) {
21
- if (typeof value === 'string') {
22
- const s = value.trim()
23
- if (s === '') return fallback
24
- if (Number.isNaN(Number(s))) return fallback
25
- return s
26
- }
27
- const n = Number(value)
28
- if (Number.isNaN(n)) return String(value)
29
- return String(n)
52
+ const padded = padDecimalMin(value, 2)
53
+ if (padded == null) return fallback
54
+ return padded
30
55
  }
31
56
 
32
57
  const n = Number(value)
@@ -34,30 +59,30 @@ export function formatNumber(value, { digits = null, fallback = '-' } = {}) {
34
59
  return n.toFixed(digits)
35
60
  }
36
61
 
37
- /** 金额带 ¥;默认跟随接口原值,如 ¥ 2401.4385 */
62
+ /** 金额带 ¥;默认不足两位补 0,两位及以上原样,如 ¥ 201.00 / ¥ 2401.4385 */
38
63
  export function formatMoney(value, { digits = null, fallback = '-' } = {}) {
39
64
  const body = formatNumber(value, { digits, fallback: null })
40
65
  if (body == null) return fallback
41
66
  return `¥ ${body}`
42
67
  }
43
68
 
44
- /** 绝对值的原样展示(去掉正负号) */
45
- function rawAbsBody(value, n) {
46
- if (typeof value === 'string') {
47
- return value.trim().replace(/^[+-]/, '')
48
- }
49
- return String(Math.abs(n))
50
- }
51
-
52
- /** 带正负号的差距展示;默认跟随原精度,如 +23.6800 / -3.1 */
69
+ /** 带正负号的差距展示;规则同 formatNumber */
53
70
  export function formatSignedNumber(value, { digits = null, fallback = '-' } = {}) {
54
71
  if (value === undefined || value === null || value === '') return fallback
55
72
  const n = Number(value)
56
73
  if (Number.isNaN(n)) return String(value)
57
- const body =
58
- digits === null || digits === undefined
59
- ? rawAbsBody(value, n)
60
- : Math.abs(n).toFixed(digits)
74
+
75
+ let body
76
+ if (digits === null || digits === undefined) {
77
+ const absRaw =
78
+ typeof value === 'string'
79
+ ? value.trim().replace(/^[+-]/, '')
80
+ : String(Math.abs(n))
81
+ body = padDecimalMin(absRaw, 2) || absRaw
82
+ } else {
83
+ body = Math.abs(n).toFixed(digits)
84
+ }
85
+
61
86
  if (n > 0) return `+${body}`
62
87
  if (n < 0) return `-${body}`
63
88
  return body