imeik-bizui 2.7.1 → 2.7.3

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.
@@ -242,6 +242,7 @@ export default {
242
242
  type: Boolean,
243
243
  default: false
244
244
  },
245
+ /** 价格/金额小数位;默认 null 不强制,跟随接口原值 */
245
246
  numberDigits: {
246
247
  type: Number,
247
248
  default: null
@@ -397,7 +397,7 @@ export default {
397
397
  },
398
398
  formatCell(value, col = {}) {
399
399
  if (col.type === 'number' || col.type === 'highlight' || col.digits != null) {
400
- // 与看板一致:不强制小数位,保留接口原值精度
400
+ // 金额按接口原样展示(不千分位、不截断小数)
401
401
  return formatNumber(value, {
402
402
  digits: col.digits != null ? col.digits : null,
403
403
  fallback: '-'
@@ -2,40 +2,55 @@
2
2
  * 底价看板 / 明细弹窗 · 纯展示工具(格式化、默认文案、前端差距推导)
3
3
  */
4
4
 
5
- /** 千分位金额/数量;无效值返回 fallback */
5
+ /**
6
+ * 数值展示:默认按接口原样(不千分位、不截断小数位)。
7
+ * 仅当显式传入 digits 时才按固定小数位输出。
8
+ * 注意:toLocaleString 默认最多 3 位小数,会导致四位金额被截断,故原样路径不用它。
9
+ */
6
10
  export function formatNumber(value, { digits = null, fallback = '-' } = {}) {
7
11
  if (value === undefined || value === null || value === '') return fallback
8
- const n = Number(value)
9
- if (Number.isNaN(n)) return String(value)
12
+
10
13
  if (digits === null || digits === undefined) {
11
- return n.toLocaleString('zh-CN')
14
+ if (typeof value === 'string') {
15
+ const s = value.trim()
16
+ if (s === '') return fallback
17
+ if (Number.isNaN(Number(s))) return fallback
18
+ return s
19
+ }
20
+ const n = Number(value)
21
+ if (Number.isNaN(n)) return String(value)
22
+ return String(n)
12
23
  }
13
- return n.toLocaleString('zh-CN', {
14
- minimumFractionDigits: digits,
15
- maximumFractionDigits: digits
16
- })
24
+
25
+ const n = Number(value)
26
+ if (Number.isNaN(n)) return String(value)
27
+ return n.toFixed(digits)
17
28
  }
18
29
 
19
- /** 金额带 ¥,如 ¥ 860 */
30
+ /** 金额带 ¥;默认跟随接口原值,如 ¥ 2401.4385 */
20
31
  export function formatMoney(value, { digits = null, fallback = '-' } = {}) {
21
32
  const body = formatNumber(value, { digits, fallback: null })
22
33
  if (body == null) return fallback
23
34
  return `¥ ${body}`
24
35
  }
25
36
 
26
- /** 带正负号的差距展示,如 -23.68 / +3.1;digits 默认 null 保留原精度 */
37
+ /** 绝对值的原样展示(去掉正负号) */
38
+ function rawAbsBody(value, n) {
39
+ if (typeof value === 'string') {
40
+ return value.trim().replace(/^[+-]/, '')
41
+ }
42
+ return String(Math.abs(n))
43
+ }
44
+
45
+ /** 带正负号的差距展示;默认跟随原精度,如 +23.6800 / -3.1 */
27
46
  export function formatSignedNumber(value, { digits = null, fallback = '-' } = {}) {
28
47
  if (value === undefined || value === null || value === '') return fallback
29
48
  const n = Number(value)
30
49
  if (Number.isNaN(n)) return String(value)
31
- const abs = Math.abs(n)
32
50
  const body =
33
51
  digits === null || digits === undefined
34
- ? abs.toLocaleString('zh-CN')
35
- : abs.toLocaleString('zh-CN', {
36
- minimumFractionDigits: digits,
37
- maximumFractionDigits: digits
38
- })
52
+ ? rawAbsBody(value, n)
53
+ : Math.abs(n).toFixed(digits)
39
54
  if (n > 0) return `+${body}`
40
55
  if (n < 0) return `-${body}`
41
56
  return body
@@ -46,7 +61,7 @@ export function formatSignedNumber(value, { digits = null, fallback = '-' } = {}
46
61
  * - gap < 0 → 低于底价 / 禁止;文案「低 N 元/支」
47
62
  * - gap > 0 → 通过;文案「高 N 元/支」
48
63
  * - gap = 0 → 持平
49
- * digits 默认 null,与看板金额一致不强制取整
64
+ * 展示不截断小数位(不用 toLocaleString)
50
65
  */
51
66
  export function computePriceGap(afterPrice, standard, { digits = null } = {}) {
52
67
  const after = Number(afterPrice)
@@ -68,11 +83,8 @@ export function computePriceGap(afterPrice, standard, { digits = null } = {}) {
68
83
  const abs = Math.abs(gap)
69
84
  const body =
70
85
  digits === null || digits === undefined
71
- ? abs.toLocaleString('zh-CN')
72
- : abs.toLocaleString('zh-CN', {
73
- minimumFractionDigits: digits,
74
- maximumFractionDigits: digits
75
- })
86
+ ? String(abs)
87
+ : abs.toFixed(digits)
76
88
  let gapLabel = '持平'
77
89
  if (gap < 0) gapLabel = `低 ${body} 元/支`
78
90
  else if (gap > 0) gapLabel = `高 ${body} 元/支`