verce-vue-test 0.0.45 → 0.0.47

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verce-vue-test",
3
- "version": "0.0.45",
3
+ "version": "0.0.47",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
Binary file
Binary file
Binary file
@@ -23,7 +23,12 @@ import cardCrossBorderBg from '@/assets/home/card-cross-border-map.png'
23
23
  import cardHkdBg from '@/assets/home/card-hkd-skyline.png'
24
24
  import cardDigitalBg from '@/assets/home/card-digital-currency.png'
25
25
  import cardJpyBg from '@/assets/home/card-jpy-fuji.png'
26
- import { formatHomeBalanceAmount } from '@/utils/homeBalance'
26
+
27
+ /** 金额在卡片上的展示结构,整数和小数分开渲染。 */
28
+ type HomeBalanceAmount = {
29
+ amount: string
30
+ decimal: string
31
+ }
27
32
 
28
33
  /**
29
34
  * 首页余额卡片的渲染模型。
@@ -224,6 +229,28 @@ function updateBalanceCardAmount(cardId: string, value: unknown) {
224
229
  updatedAt.value = formatDateTime(new Date())
225
230
  }
226
231
 
232
+ /**
233
+ * 把单个金额值转换成卡片展示需要的整数部分和小数部分。
234
+ * 调用方自己取接口字段,这里只处理金额格式。
235
+ */
236
+ function formatHomeBalanceAmount(value: unknown): HomeBalanceAmount {
237
+ const text = normalizeNumberText(value)
238
+
239
+ if (!text) {
240
+ return { amount: '0', decimal: '.00' }
241
+ }
242
+
243
+ const isNegative = text.startsWith('-')
244
+ const unsignedText = isNegative ? text.slice(1) : text
245
+ const [integer = '0', decimal = ''] = unsignedText.split('.')
246
+ const normalizedInteger = integer.replace(/^0+(?=\d)/, '') || '0'
247
+
248
+ return {
249
+ amount: `${isNegative ? '-' : ''}${addThousands(normalizedInteger)}`,
250
+ decimal: `.${decimal.padEnd(2, '0').slice(0, 2)}`,
251
+ }
252
+ }
253
+
227
254
  defineExpose({
228
255
  updateBalanceCardAmount,
229
256
  })
@@ -236,6 +263,23 @@ function formatDateTime(date: Date) {
236
263
  `${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`,
237
264
  ].join(' ')
238
265
  }
266
+
267
+ function normalizeNumberText(value: unknown) {
268
+ const raw = String(value ?? '').trim()
269
+
270
+ if (!raw || raw === '-' || raw === '--' || raw === '—') {
271
+ return ''
272
+ }
273
+
274
+ const isNegative = raw.startsWith('-') || /^\(.+\)$/.test(raw)
275
+ const text = raw.replace(/,/g, '').replace(/[^\d.]/g, '')
276
+
277
+ return /\d/.test(text) ? `${isNegative ? '-' : ''}${text}` : ''
278
+ }
279
+
280
+ function addThousands(value: string) {
281
+ return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
282
+ }
239
283
  </script>
240
284
 
241
285
  <template>
@@ -1,46 +0,0 @@
1
- export type HomeBalanceAmount = {
2
- amount: string
3
- decimal: string
4
- }
5
-
6
- /**
7
- * 把单个金额值转换成首页卡片展示需要的金额结构。
8
- *
9
- * 示例:
10
- * formatHomeBalanceAmount('316789101.25')
11
- * => { amount: '316,789,101', decimal: '.25' }
12
- */
13
- export function formatHomeBalanceAmount(value: unknown): HomeBalanceAmount {
14
- const text = normalizeNumberText(value)
15
-
16
- if (!text) {
17
- return { amount: '0', decimal: '.00' }
18
- }
19
-
20
- const isNegative = text.startsWith('-')
21
- const unsignedText = isNegative ? text.slice(1) : text
22
- const [integer = '0', decimal = ''] = unsignedText.split('.')
23
- const normalizedInteger = integer.replace(/^0+(?=\d)/, '') || '0'
24
-
25
- return {
26
- amount: `${isNegative ? '-' : ''}${addThousands(normalizedInteger)}`,
27
- decimal: `.${decimal.padEnd(2, '0').slice(0, 2)}`,
28
- }
29
- }
30
-
31
- function normalizeNumberText(value: unknown) {
32
- const raw = String(value ?? '').trim()
33
-
34
- if (!raw || raw === '-' || raw === '--' || raw === '—') {
35
- return ''
36
- }
37
-
38
- const isNegative = raw.startsWith('-') || /^\(.+\)$/.test(raw)
39
- const text = raw.replace(/,/g, '').replace(/[^\d.]/g, '')
40
-
41
- return /\d/.test(text) ? `${isNegative ? '-' : ''}${text}` : ''
42
- }
43
-
44
- function addThousands(value: string) {
45
- return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
46
- }