verce-vue-test 0.0.44 → 0.0.46
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 +1 -1
- package/src/views/HomeView.vue +71 -25
- package/src/utils/homeBalance.ts +0 -133
package/package.json
CHANGED
package/src/views/HomeView.vue
CHANGED
|
@@ -23,13 +23,18 @@ 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
|
-
|
|
26
|
+
|
|
27
|
+
/** 金额在卡片上的展示结构,整数和小数分开渲染。 */
|
|
28
|
+
type HomeBalanceAmount = {
|
|
29
|
+
amount: string
|
|
30
|
+
decimal: string
|
|
31
|
+
}
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
34
|
* 首页余额卡片的渲染模型。
|
|
30
35
|
*
|
|
31
36
|
* 注意:
|
|
32
|
-
* - id
|
|
37
|
+
* - id 用于按卡片更新金额;接口字段由调用方自己取值。
|
|
33
38
|
* - amount / decimal 分开存放,是为了让整数位和小数位在视觉上使用不同字号。
|
|
34
39
|
* - background / accent 系列字段只负责视觉,不参与接口转换。
|
|
35
40
|
*/
|
|
@@ -65,8 +70,8 @@ const router = useRouter()
|
|
|
65
70
|
/**
|
|
66
71
|
* 首页余额卡片的默认展示数据。
|
|
67
72
|
*
|
|
68
|
-
*
|
|
69
|
-
*
|
|
73
|
+
* 后续对接接口时不用直接改这个数组结构,调用方取到具体金额值后,
|
|
74
|
+
* 通过 updateBalanceCardAmount(cardId, value) 更新指定卡片。
|
|
70
75
|
*/
|
|
71
76
|
const balanceCards = ref<BalanceCard[]>([
|
|
72
77
|
{
|
|
@@ -207,28 +212,47 @@ function isLongAmount(card: BalanceCard) {
|
|
|
207
212
|
}
|
|
208
213
|
|
|
209
214
|
/**
|
|
210
|
-
*
|
|
215
|
+
* 首页单个金额更新入口。
|
|
211
216
|
*
|
|
212
217
|
* 用法示例:
|
|
213
|
-
*
|
|
214
|
-
*
|
|
218
|
+
* updateBalanceCardAmount('rmb', res.body.balanceAmt)
|
|
219
|
+
* updateBalanceCardAmount('usd', usdItem.mainAcctAmt)
|
|
215
220
|
*
|
|
216
|
-
*
|
|
217
|
-
* 请求、错误提示、loading 状态可以在调用方自行处理。
|
|
221
|
+
* 这里不读取后端返回结构,只负责把单个金额值格式化后更新到指定卡片。
|
|
218
222
|
*/
|
|
219
|
-
function
|
|
220
|
-
const
|
|
223
|
+
function updateBalanceCardAmount(cardId: string, value: unknown) {
|
|
224
|
+
const amount = formatHomeBalanceAmount(value)
|
|
221
225
|
|
|
222
226
|
balanceCards.value = balanceCards.value.map((card) => {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
return amount ? { ...card, ...amount } : card
|
|
227
|
+
return card.id === cardId ? { ...card, ...amount } : card
|
|
226
228
|
})
|
|
227
229
|
updatedAt.value = formatDateTime(new Date())
|
|
228
230
|
}
|
|
229
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
|
+
|
|
230
254
|
defineExpose({
|
|
231
|
-
|
|
255
|
+
updateBalanceCardAmount,
|
|
232
256
|
})
|
|
233
257
|
|
|
234
258
|
function formatDateTime(date: Date) {
|
|
@@ -239,6 +263,23 @@ function formatDateTime(date: Date) {
|
|
|
239
263
|
`${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`,
|
|
240
264
|
].join(' ')
|
|
241
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
|
+
}
|
|
242
283
|
</script>
|
|
243
284
|
|
|
244
285
|
<template>
|
|
@@ -368,7 +409,7 @@ function formatDateTime(date: Date) {
|
|
|
368
409
|
min-height: 0;
|
|
369
410
|
}
|
|
370
411
|
|
|
371
|
-
/*
|
|
412
|
+
/* 外层主面板保留一层外边框;每个币种项单独使用轻量彩色边框表达分组。 */
|
|
372
413
|
.balance-panel {
|
|
373
414
|
position: relative;
|
|
374
415
|
display: grid;
|
|
@@ -497,34 +538,39 @@ function formatDateTime(date: Date) {
|
|
|
497
538
|
min-height: 0;
|
|
498
539
|
overflow: hidden;
|
|
499
540
|
padding: 0 clamp(0.55rem, 1vw, 1.05rem) 0 clamp(0.5rem, 0.9vw, 0.95rem);
|
|
500
|
-
border:
|
|
541
|
+
border: 1px solid var(--card-border);
|
|
501
542
|
border-radius: var(--card-radius);
|
|
502
543
|
background:
|
|
503
544
|
linear-gradient(90deg, rgba(255, 255, 255, 0.74), rgba(255, 255, 255, 0.28)),
|
|
504
545
|
#ffffff;
|
|
505
546
|
box-shadow:
|
|
547
|
+
0 0 0 1px color-mix(in srgb, var(--accent-soft) 42%, rgba(255, 255, 255, 0.72)) inset,
|
|
506
548
|
0 0.12rem clamp(0.28rem, 0.5vw, 0.55rem) color-mix(in srgb, var(--card-glow) 55%, transparent),
|
|
507
549
|
0 0 clamp(0.4rem, 0.75vw, 0.85rem) rgba(255, 255, 255, 0.76) inset,
|
|
508
|
-
|
|
550
|
+
0.24rem 0 0 var(--accent) inset;
|
|
509
551
|
}
|
|
510
552
|
|
|
511
|
-
/*
|
|
553
|
+
/* 左侧色条拉满高度并提升层级,避免被卡片底图或柔光覆盖。 */
|
|
512
554
|
.balance-card::before {
|
|
513
555
|
position: absolute;
|
|
514
|
-
top:
|
|
515
|
-
bottom:
|
|
556
|
+
top: 0;
|
|
557
|
+
bottom: 0;
|
|
516
558
|
left: 0;
|
|
517
|
-
|
|
559
|
+
z-index: 2;
|
|
560
|
+
width: clamp(0.24rem, 0.34vw, 0.38rem);
|
|
518
561
|
content: "";
|
|
519
|
-
border-radius: 0
|
|
562
|
+
border-radius: var(--card-radius) 0 0 var(--card-radius);
|
|
520
563
|
background: linear-gradient(180deg, var(--accent-soft), var(--accent-deep));
|
|
521
|
-
box-shadow:
|
|
564
|
+
box-shadow:
|
|
565
|
+
0.08rem 0 0 color-mix(in srgb, var(--accent-soft) 62%, rgba(255, 255, 255, 0.82)),
|
|
566
|
+
0 0 clamp(0.45rem, 0.85vw, 1rem) var(--card-glow);
|
|
522
567
|
}
|
|
523
568
|
|
|
524
569
|
/* 柔光覆盖层让底图和金额文字有层次;不参与交互。 */
|
|
525
570
|
.balance-card::after {
|
|
526
571
|
position: absolute;
|
|
527
572
|
inset: 0;
|
|
573
|
+
z-index: 1;
|
|
528
574
|
content: "";
|
|
529
575
|
pointer-events: none;
|
|
530
576
|
background:
|
|
@@ -548,7 +594,7 @@ function formatDateTime(date: Date) {
|
|
|
548
594
|
.balance-card h2,
|
|
549
595
|
.amount-block {
|
|
550
596
|
position: relative;
|
|
551
|
-
z-index:
|
|
597
|
+
z-index: 3;
|
|
552
598
|
}
|
|
553
599
|
|
|
554
600
|
.badge-shell {
|
package/src/utils/homeBalance.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
export type HomeBalanceAmount = {
|
|
2
|
-
amount: string
|
|
3
|
-
decimal: string
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type HomeBalanceData = Partial<Record<string, HomeBalanceAmount>>
|
|
7
|
-
|
|
8
|
-
type PlainObject = Record<string, unknown>
|
|
9
|
-
|
|
10
|
-
const DIRECT_FIELDS: Record<string, string[]> = {
|
|
11
|
-
rmb: ['balanceAmt', 'balanceAmount', 'availableBalance', 'rmbAmount', 'cnyAmount'],
|
|
12
|
-
clearing: ['settleAccount', 'settleAmount', 'clearingAmount'],
|
|
13
|
-
'cross-border-rmb': ['crossBorderRmbAmount', 'crossBorderAmount'],
|
|
14
|
-
'digital-currency': ['dccyAvailableAmt', 'dccyAvailableAmount', 'digitalCurrencyAmount'],
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const FOREIGN_CARD_ID: Record<string, string> = {
|
|
18
|
-
USD: 'usd',
|
|
19
|
-
EUR: 'eur',
|
|
20
|
-
HKD: 'hkd',
|
|
21
|
-
JPY: 'jpy',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* 把首页余额接口原始数据转换成页面需要的金额展示数据。
|
|
26
|
-
*
|
|
27
|
-
* 当前只处理两类返回:
|
|
28
|
-
* - 人民币类字段在 body 上,例如 balanceAmt / settleAccount
|
|
29
|
-
* - 外币字段在 body.resultInfos 数组里,例如 { ccy: 'USD', mainAcctAmt: '47631' }
|
|
30
|
-
*/
|
|
31
|
-
export function transformHomeBalanceData(payload: unknown): HomeBalanceData {
|
|
32
|
-
const body = getBody(payload)
|
|
33
|
-
const result: HomeBalanceData = {}
|
|
34
|
-
|
|
35
|
-
Object.entries(DIRECT_FIELDS).forEach(([cardId, fields]) => {
|
|
36
|
-
const value = pickValue(body, fields)
|
|
37
|
-
|
|
38
|
-
if (value !== undefined) {
|
|
39
|
-
result[cardId] = formatAmount(value)
|
|
40
|
-
}
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
Object.entries(collectForeignAmounts(body)).forEach(([cardId, amount]) => {
|
|
44
|
-
result[cardId] = formatAmount(amount)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
return result
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function getBody(payload: unknown) {
|
|
51
|
-
const root = toObject(payload)
|
|
52
|
-
|
|
53
|
-
return toObject(root?.body) ?? root ?? {}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function collectForeignAmounts(body: PlainObject) {
|
|
57
|
-
const rows = Array.isArray(body.resultInfos) ? body.resultInfos : []
|
|
58
|
-
const totals: Record<string, number> = {}
|
|
59
|
-
|
|
60
|
-
rows.forEach((row) => {
|
|
61
|
-
const item = toObject(row)
|
|
62
|
-
const currency = String(item?.ccy ?? '').toUpperCase()
|
|
63
|
-
const cardId = FOREIGN_CARD_ID[currency]
|
|
64
|
-
const amount = toNumber(item?.mainAcctAmt)
|
|
65
|
-
|
|
66
|
-
if (!cardId || !Number.isFinite(amount)) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
totals[cardId] = (totals[cardId] ?? 0) + amount
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
return totals
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function pickValue(source: PlainObject, fields: string[]) {
|
|
77
|
-
for (const field of fields) {
|
|
78
|
-
const value = source[field]
|
|
79
|
-
|
|
80
|
-
if (value !== null && value !== undefined && value !== '') {
|
|
81
|
-
return value
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return undefined
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function formatAmount(value: unknown): HomeBalanceAmount {
|
|
89
|
-
const text = normalizeNumberText(value)
|
|
90
|
-
|
|
91
|
-
if (!text) {
|
|
92
|
-
return { amount: '0', decimal: '.00' }
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const isNegative = text.startsWith('-')
|
|
96
|
-
const unsignedText = isNegative ? text.slice(1) : text
|
|
97
|
-
const [integer = '0', decimal = ''] = unsignedText.split('.')
|
|
98
|
-
const normalizedInteger = integer.replace(/^0+(?=\d)/, '') || '0'
|
|
99
|
-
|
|
100
|
-
return {
|
|
101
|
-
amount: `${isNegative ? '-' : ''}${addThousands(normalizedInteger)}`,
|
|
102
|
-
decimal: `.${decimal.padEnd(2, '0').slice(0, 2)}`,
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function toNumber(value: unknown) {
|
|
107
|
-
const text = normalizeNumberText(value)
|
|
108
|
-
|
|
109
|
-
return text ? Number(text) : Number.NaN
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function normalizeNumberText(value: unknown) {
|
|
113
|
-
const raw = String(value ?? '').trim()
|
|
114
|
-
|
|
115
|
-
if (!raw || raw === '-' || raw === '--' || raw === '—') {
|
|
116
|
-
return ''
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const isNegative = raw.startsWith('-') || /^\(.+\)$/.test(raw)
|
|
120
|
-
const text = raw.replace(/,/g, '').replace(/[^\d.]/g, '')
|
|
121
|
-
|
|
122
|
-
return /\d/.test(text) ? `${isNegative ? '-' : ''}${text}` : ''
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function addThousands(value: string) {
|
|
126
|
-
return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function toObject(value: unknown): PlainObject | undefined {
|
|
130
|
-
return Object.prototype.toString.call(value) === '[object Object]'
|
|
131
|
-
? value as PlainObject
|
|
132
|
-
: undefined
|
|
133
|
-
}
|