verce-vue-test 0.0.42 → 0.0.44
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/utils/homeBalance.ts +74 -356
- package/src/views/HomeView.vue +55 -3
- package/888/1 +0 -121
- package/888/mini2.0-main/.editorconfig +0 -8
- package/888/mini2.0-main/.env.development +0 -3
- package/888/mini2.0-main/.env.production +0 -3
- package/888/mini2.0-main/.env.test +0 -3
- package/888/mini2.0-main/.gitattributes +0 -1
- package/888/mini2.0-main/.oxlintrc.json +0 -10
- package/888/mini2.0-main/.prettierrc.json +0 -6
- package/888/mini2.0-main/.vscode/extensions.json +0 -9
- package/888/mini2.0-main/README.md +0 -179
- package/888/mini2.0-main/auto-imports.d.ts +0 -629
- package/888/mini2.0-main/components.d.ts +0 -21
- package/888/mini2.0-main/design-qa.md +0 -36
- package/888/mini2.0-main/docs/MX_API.md +0 -244
- package/888/mini2.0-main/docs/REQUEST.md +0 -217
- package/888/mini2.0-main/docs/jsapi.js +0 -515
- package/888/mini2.0-main/docs/package-json-guide.md +0 -132
- package/888/mini2.0-main/env.d.ts +0 -15
- package/888/mini2.0-main/eslint.config.ts +0 -26
- package/888/mini2.0-main/index.html +0 -16
- package/888/mini2.0-main/output/playwright/rmb-position/design-comparison.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-back-top.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-page.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-sticky-check.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-sticky-scrolled.png +0 -0
- package/888/mini2.0-main/package-lock.json +0 -6442
- package/888/mini2.0-main/package.json +0 -66
- package/888/mini2.0-main/plugins/bump-version.ts +0 -61
- package/888/mini2.0-main/postcss.config.ts +0 -15
- package/888/mini2.0-main/public/favicon.ico +0 -0
- package/888/mini2.0-main/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
- package/888/mini2.0-main/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
- package/888/mini2.0-main/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
- package/888/mini2.0-main/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
- package/888/mini2.0-main/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
- package/888/mini2.0-main/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
- package/888/mini2.0-main/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
- package/888/mini2.0-main/public/images/img.png +0 -0
- package/888/mini2.0-main/src/App.vue +0 -59
- package/888/mini2.0-main/src/api/health.ts +0 -13
- package/888/mini2.0-main/src/api/rmb-position.ts +0 -287
- package/888/mini2.0-main/src/api/user.ts +0 -54
- package/888/mini2.0-main/src/auto-imports.d.ts +0 -639
- package/888/mini2.0-main/src/components.d.ts +0 -30
- package/888/mini2.0-main/src/config/config.properties +0 -3
- package/888/mini2.0-main/src/config/env.ts +0 -6
- package/888/mini2.0-main/src/config/plugin.properties.pro +0 -6
- package/888/mini2.0-main/src/config/plugin.properties.test +0 -6
- package/888/mini2.0-main/src/core/mxApi/index.ts +0 -344
- package/888/mini2.0-main/src/core/request/index.ts +0 -135
- package/888/mini2.0-main/src/main.ts +0 -39
- package/888/mini2.0-main/src/router/index.ts +0 -77
- package/888/mini2.0-main/src/stores/app.ts +0 -24
- package/888/mini2.0-main/src/stores/counter.ts +0 -12
- package/888/mini2.0-main/src/stores/user.ts +0 -85
- package/888/mini2.0-main/src/types/api.d.ts +0 -14
- package/888/mini2.0-main/src/types/nprogress.d.ts +0 -8
- package/888/mini2.0-main/src/utils/auth-token.ts +0 -197
- package/888/mini2.0-main/src/utils/query.ts +0 -27
- package/888/mini2.0-main/src/utils/request.ts +0 -233
- package/888/mini2.0-main/src/views/clearing-detail/index.vue +0 -49
- package/888/mini2.0-main/src/views/foreign-position/index.vue +0 -49
- package/888/mini2.0-main/src/views/home/index.vue +0 -213
- package/888/mini2.0-main/src/views/login/index.vue +0 -202
- package/888/mini2.0-main/src/views/mine/index.vue +0 -143
- package/888/mini2.0-main/src/views/net-debit/index.vue +0 -49
- package/888/mini2.0-main/src/views/pbc-position/index.vue +0 -49
- package/888/mini2.0-main/src/views/position-estimate/index.vue +0 -49
- package/888/mini2.0-main/src/views/rmb-position/index.vue +0 -1042
- package/888/mini2.0-main/src/views/warning/index.vue +0 -49
- package/888/mini2.0-main/tsconfig.app.json +0 -18
- package/888/mini2.0-main/tsconfig.json +0 -11
- package/888/mini2.0-main/tsconfig.node.json +0 -28
- package/888/mini2.0-main/vite.config.ts +0 -98
package/package.json
CHANGED
package/src/utils/homeBalance.ts
CHANGED
|
@@ -1,375 +1,116 @@
|
|
|
1
|
-
export type
|
|
2
|
-
id: string
|
|
3
|
-
title?: string
|
|
4
|
-
unit: string
|
|
5
|
-
keys: string[]
|
|
6
|
-
currencyCodes?: string[]
|
|
7
|
-
amountKeys?: string[]
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export type NormalizedHomeBalance = {
|
|
11
|
-
id: string
|
|
12
|
-
title?: string
|
|
13
|
-
unit: string
|
|
14
|
-
amount: string
|
|
15
|
-
decimal: string
|
|
16
|
-
rawValue?: unknown
|
|
17
|
-
sourceKey?: string
|
|
18
|
-
found: boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export type HomeBalanceTarget = {
|
|
22
|
-
id: string
|
|
1
|
+
export type HomeBalanceAmount = {
|
|
23
2
|
amount: string
|
|
24
3
|
decimal: string
|
|
25
|
-
unit: string
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export type NormalizeHomeBalanceOptions = {
|
|
29
|
-
fields?: HomeBalanceFieldConfig[]
|
|
30
|
-
fractionDigits?: number
|
|
31
|
-
preserveWhenMissing?: boolean
|
|
32
4
|
}
|
|
33
5
|
|
|
34
|
-
|
|
35
|
-
'mainAcctAmt',
|
|
36
|
-
'mainAcctAmount',
|
|
37
|
-
'mainAccountAmt',
|
|
38
|
-
'mainAccountAmount',
|
|
39
|
-
'acctAmt',
|
|
40
|
-
'accountAmt',
|
|
41
|
-
'accountAmount',
|
|
42
|
-
'availableBalance',
|
|
43
|
-
'balanceAmount',
|
|
44
|
-
'availableAmt',
|
|
45
|
-
'availableAmount',
|
|
46
|
-
'amount',
|
|
47
|
-
'amt',
|
|
48
|
-
'balance',
|
|
49
|
-
'value',
|
|
50
|
-
]
|
|
51
|
-
|
|
52
|
-
export const DEFAULT_HOME_BALANCE_FIELDS: HomeBalanceFieldConfig[] = [
|
|
53
|
-
{
|
|
54
|
-
id: 'rmb',
|
|
55
|
-
title: '人民币',
|
|
56
|
-
unit: 'CNY',
|
|
57
|
-
currencyCodes: ['CNY', 'RMB', '人民币'],
|
|
58
|
-
keys: [
|
|
59
|
-
'body.balanceAmount',
|
|
60
|
-
'body.availableBalance',
|
|
61
|
-
'balanceAmount',
|
|
62
|
-
'availableBalance',
|
|
63
|
-
'rmbAmount',
|
|
64
|
-
'rmbBalance',
|
|
65
|
-
'cnyAmount',
|
|
66
|
-
'cnyBalance',
|
|
67
|
-
],
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
id: 'usd',
|
|
71
|
-
title: '美元',
|
|
72
|
-
unit: 'USD',
|
|
73
|
-
currencyCodes: ['USD', '美元'],
|
|
74
|
-
keys: ['usdAmount', 'usdBalance', 'usdAvailableBalance', 'usdAvailableAmt'],
|
|
75
|
-
},
|
|
76
|
-
{
|
|
77
|
-
id: 'clearing',
|
|
78
|
-
title: '城银清',
|
|
79
|
-
unit: 'CNY',
|
|
80
|
-
currencyCodes: ['CLEARING', '城银清'],
|
|
81
|
-
keys: ['clearingAmount', 'clearingBalance', 'settleAmount', 'settleAccount'],
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
id: 'eur',
|
|
85
|
-
title: '欧元',
|
|
86
|
-
unit: 'EUR',
|
|
87
|
-
currencyCodes: ['EUR', '欧元'],
|
|
88
|
-
keys: ['eurAmount', 'eurBalance', 'eurAvailableBalance', 'eurAvailableAmt'],
|
|
89
|
-
},
|
|
90
|
-
{
|
|
91
|
-
id: 'cross-border-rmb',
|
|
92
|
-
title: '跨境人民币',
|
|
93
|
-
unit: 'CNY',
|
|
94
|
-
currencyCodes: ['CROSS_BORDER_RMB', '跨境人民币'],
|
|
95
|
-
keys: [
|
|
96
|
-
'crossBorderRmbAmount',
|
|
97
|
-
'crossBorderRmbBalance',
|
|
98
|
-
'crossBorderAmount',
|
|
99
|
-
'crossBorderBalance',
|
|
100
|
-
],
|
|
101
|
-
},
|
|
102
|
-
{
|
|
103
|
-
id: 'hkd',
|
|
104
|
-
title: '港币',
|
|
105
|
-
unit: 'HKD',
|
|
106
|
-
currencyCodes: ['HKD', '港币'],
|
|
107
|
-
keys: ['hkdAmount', 'hkdBalance', 'hkdAvailableBalance', 'hkdAvailableAmt'],
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
id: 'digital-currency',
|
|
111
|
-
title: '数字货币',
|
|
112
|
-
unit: 'CNY',
|
|
113
|
-
currencyCodes: ['DCCY', 'DCNY', '数字货币'],
|
|
114
|
-
keys: [
|
|
115
|
-
'dccyAvailableAmt',
|
|
116
|
-
'dccyAvailableAmount',
|
|
117
|
-
'digitalCurrencyAmount',
|
|
118
|
-
'digitalCurrencyBalance',
|
|
119
|
-
],
|
|
120
|
-
},
|
|
121
|
-
{
|
|
122
|
-
id: 'jpy',
|
|
123
|
-
title: '日元',
|
|
124
|
-
unit: 'JPY',
|
|
125
|
-
currencyCodes: ['JPY', '日元'],
|
|
126
|
-
keys: ['jpyAmount', 'jpyBalance', 'jpyAvailableBalance', 'jpyAvailableAmt'],
|
|
127
|
-
},
|
|
128
|
-
]
|
|
129
|
-
|
|
130
|
-
export function normalizeHomeBalanceResponse(
|
|
131
|
-
payload: unknown,
|
|
132
|
-
options: NormalizeHomeBalanceOptions = {},
|
|
133
|
-
): NormalizedHomeBalance[] {
|
|
134
|
-
const fields = options.fields ?? DEFAULT_HOME_BALANCE_FIELDS
|
|
135
|
-
const fractionDigits = options.fractionDigits ?? 2
|
|
136
|
-
const objects = collectObjects(payload)
|
|
6
|
+
export type HomeBalanceData = Partial<Record<string, HomeBalanceAmount>>
|
|
137
7
|
|
|
138
|
-
|
|
139
|
-
const foundValue =
|
|
140
|
-
findValueByCurrencyRecord(objects, field) ??
|
|
141
|
-
findValueByKeys(payload, objects, field.keys)
|
|
142
|
-
const formatted = formatAmountParts(foundValue?.value, fractionDigits)
|
|
8
|
+
type PlainObject = Record<string, unknown>
|
|
143
9
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
decimal: formatted.decimal,
|
|
150
|
-
rawValue: foundValue?.value,
|
|
151
|
-
sourceKey: foundValue?.sourceKey,
|
|
152
|
-
found: foundValue !== undefined,
|
|
153
|
-
}
|
|
154
|
-
})
|
|
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'],
|
|
155
15
|
}
|
|
156
16
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const normalized = normalizeHomeBalanceResponse(payload, options)
|
|
164
|
-
const byId = new Map(normalized.map((item) => [normalizeKey(item.id), item]))
|
|
17
|
+
const FOREIGN_CARD_ID: Record<string, string> = {
|
|
18
|
+
USD: 'usd',
|
|
19
|
+
EUR: 'eur',
|
|
20
|
+
HKD: 'hkd',
|
|
21
|
+
JPY: 'jpy',
|
|
22
|
+
}
|
|
165
23
|
|
|
166
|
-
|
|
167
|
-
|
|
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 = {}
|
|
168
34
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
35
|
+
Object.entries(DIRECT_FIELDS).forEach(([cardId, fields]) => {
|
|
36
|
+
const value = pickValue(body, fields)
|
|
172
37
|
|
|
173
|
-
if (
|
|
174
|
-
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return {
|
|
178
|
-
...card,
|
|
179
|
-
amount: normalizedCard.amount,
|
|
180
|
-
decimal: normalizedCard.decimal,
|
|
181
|
-
unit: normalizedCard.unit || card.unit,
|
|
38
|
+
if (value !== undefined) {
|
|
39
|
+
result[cardId] = formatAmount(value)
|
|
182
40
|
}
|
|
183
41
|
})
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function formatAmountParts(
|
|
187
|
-
value: unknown,
|
|
188
|
-
fractionDigits = 2,
|
|
189
|
-
): { amount: string; decimal: string } {
|
|
190
|
-
const numericText = normalizeNumericText(value)
|
|
191
|
-
|
|
192
|
-
if (!numericText) {
|
|
193
|
-
return {
|
|
194
|
-
amount: '0',
|
|
195
|
-
decimal: fractionDigits > 0 ? `.${'0'.repeat(fractionDigits)}` : '',
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
42
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const [integer = '0', ...decimalParts] = unsignedText.split('.')
|
|
203
|
-
const normalizedInteger = integer.replace(/^0+(?=\d)/, '') || '0'
|
|
204
|
-
const decimalText = decimalParts.join('')
|
|
205
|
-
const decimal = fractionDigits > 0
|
|
206
|
-
? `.${decimalText.padEnd(fractionDigits, '0').slice(0, fractionDigits)}`
|
|
207
|
-
: ''
|
|
43
|
+
Object.entries(collectForeignAmounts(body)).forEach(([cardId, amount]) => {
|
|
44
|
+
result[cardId] = formatAmount(amount)
|
|
45
|
+
})
|
|
208
46
|
|
|
209
|
-
return
|
|
210
|
-
amount: `${numericText.startsWith('-') ? '-' : ''}${groupInteger(normalizedInteger)}`,
|
|
211
|
-
decimal,
|
|
212
|
-
}
|
|
47
|
+
return result
|
|
213
48
|
}
|
|
214
49
|
|
|
215
|
-
function
|
|
216
|
-
payload
|
|
217
|
-
objects: readonly Record<string, unknown>[],
|
|
218
|
-
keys: readonly string[],
|
|
219
|
-
): { value: unknown; sourceKey: string } | undefined {
|
|
220
|
-
for (const key of keys) {
|
|
221
|
-
if (key.includes('.')) {
|
|
222
|
-
const pathValue = readPath(payload, key)
|
|
223
|
-
|
|
224
|
-
if (isUsableValue(pathValue)) {
|
|
225
|
-
return { value: pathValue, sourceKey: key }
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
const normalizedKey = normalizeKey(key)
|
|
230
|
-
|
|
231
|
-
for (const object of objects) {
|
|
232
|
-
const entry = Object.entries(object).find(
|
|
233
|
-
([objectKey]) => normalizeKey(objectKey) === normalizedKey,
|
|
234
|
-
)
|
|
50
|
+
function getBody(payload: unknown) {
|
|
51
|
+
const root = toObject(payload)
|
|
235
52
|
|
|
236
|
-
|
|
237
|
-
return { value: entry[1], sourceKey: entry[0] }
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
return undefined
|
|
53
|
+
return toObject(root?.body) ?? root ?? {}
|
|
243
54
|
}
|
|
244
55
|
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
): { value: unknown; sourceKey: string } | undefined {
|
|
249
|
-
const shouldUseUnitAsAlias = normalizeKey(field.unit) !== 'cny'
|
|
250
|
-
const currencyCodes = new Set(
|
|
251
|
-
[
|
|
252
|
-
field.id,
|
|
253
|
-
field.title,
|
|
254
|
-
...(shouldUseUnitAsAlias ? [field.unit] : []),
|
|
255
|
-
...(field.currencyCodes ?? []),
|
|
256
|
-
]
|
|
257
|
-
.filter((item): item is string => Boolean(item))
|
|
258
|
-
.map(normalizeKey),
|
|
259
|
-
)
|
|
260
|
-
|
|
261
|
-
const matches: Array<{ value: unknown; sourceKey: string }> = []
|
|
56
|
+
function collectForeignAmounts(body: PlainObject) {
|
|
57
|
+
const rows = Array.isArray(body.resultInfos) ? body.resultInfos : []
|
|
58
|
+
const totals: Record<string, number> = {}
|
|
262
59
|
|
|
263
|
-
|
|
264
|
-
const
|
|
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)
|
|
265
65
|
|
|
266
|
-
if (!
|
|
267
|
-
|
|
66
|
+
if (!cardId || !Number.isFinite(amount)) {
|
|
67
|
+
return
|
|
268
68
|
}
|
|
269
69
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
if (amountValue) {
|
|
274
|
-
matches.push(amountValue)
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
if (!matches.length) {
|
|
279
|
-
return undefined
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (matches.length === 1) {
|
|
283
|
-
return matches[0]
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
const numericValues = matches
|
|
287
|
-
.map((match) => parseAmountValue(match.value))
|
|
288
|
-
.filter((value): value is number => Number.isFinite(value))
|
|
289
|
-
|
|
290
|
-
if (!numericValues.length) {
|
|
291
|
-
return matches[0]
|
|
292
|
-
}
|
|
70
|
+
totals[cardId] = (totals[cardId] ?? 0) + amount
|
|
71
|
+
})
|
|
293
72
|
|
|
294
|
-
return
|
|
295
|
-
value: numericValues.reduce((total, value) => total + value, 0),
|
|
296
|
-
sourceKey: Array.from(new Set(matches.map((match) => match.sourceKey))).join('+'),
|
|
297
|
-
}
|
|
73
|
+
return totals
|
|
298
74
|
}
|
|
299
75
|
|
|
300
|
-
function
|
|
301
|
-
const
|
|
302
|
-
|
|
303
|
-
'currencyCode',
|
|
304
|
-
'currencyType',
|
|
305
|
-
'currencyName',
|
|
306
|
-
'ccy',
|
|
307
|
-
'ccyCode',
|
|
308
|
-
'curr',
|
|
309
|
-
'currCode',
|
|
310
|
-
'unit',
|
|
311
|
-
]
|
|
312
|
-
|
|
313
|
-
for (const key of currencyKeys) {
|
|
314
|
-
const value = findValueByKeys(object, [object], [key])?.value
|
|
76
|
+
function pickValue(source: PlainObject, fields: string[]) {
|
|
77
|
+
for (const field of fields) {
|
|
78
|
+
const value = source[field]
|
|
315
79
|
|
|
316
|
-
if (
|
|
317
|
-
return value
|
|
80
|
+
if (value !== null && value !== undefined && value !== '') {
|
|
81
|
+
return value
|
|
318
82
|
}
|
|
319
83
|
}
|
|
320
84
|
|
|
321
85
|
return undefined
|
|
322
86
|
}
|
|
323
87
|
|
|
324
|
-
function
|
|
325
|
-
value
|
|
326
|
-
depth = 0,
|
|
327
|
-
seen = new Set<object>(),
|
|
328
|
-
): Record<string, unknown>[] {
|
|
329
|
-
if (!isPlainObject(value) && !Array.isArray(value)) {
|
|
330
|
-
return []
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (typeof value === 'object' && value !== null) {
|
|
334
|
-
if (seen.has(value)) {
|
|
335
|
-
return []
|
|
336
|
-
}
|
|
88
|
+
function formatAmount(value: unknown): HomeBalanceAmount {
|
|
89
|
+
const text = normalizeNumberText(value)
|
|
337
90
|
|
|
338
|
-
|
|
91
|
+
if (!text) {
|
|
92
|
+
return { amount: '0', decimal: '.00' }
|
|
339
93
|
}
|
|
340
94
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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'
|
|
344
99
|
|
|
345
|
-
|
|
346
|
-
|
|
100
|
+
return {
|
|
101
|
+
amount: `${isNegative ? '-' : ''}${addThousands(normalizedInteger)}`,
|
|
102
|
+
decimal: `.${decimal.padEnd(2, '0').slice(0, 2)}`,
|
|
347
103
|
}
|
|
348
|
-
|
|
349
|
-
const object = value as Record<string, unknown>
|
|
350
|
-
const children = Object.entries(object).flatMap(([, child]) =>
|
|
351
|
-
collectObjects(child, depth + 1, seen),
|
|
352
|
-
)
|
|
353
|
-
|
|
354
|
-
return [object, ...children]
|
|
355
104
|
}
|
|
356
105
|
|
|
357
|
-
function
|
|
358
|
-
|
|
359
|
-
if (!isPlainObject(current) && !Array.isArray(current)) {
|
|
360
|
-
return undefined
|
|
361
|
-
}
|
|
106
|
+
function toNumber(value: unknown) {
|
|
107
|
+
const text = normalizeNumberText(value)
|
|
362
108
|
|
|
363
|
-
|
|
364
|
-
}, value)
|
|
109
|
+
return text ? Number(text) : Number.NaN
|
|
365
110
|
}
|
|
366
111
|
|
|
367
|
-
function
|
|
368
|
-
|
|
369
|
-
return ''
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
const raw = String(value).trim()
|
|
112
|
+
function normalizeNumberText(value: unknown) {
|
|
113
|
+
const raw = String(value ?? '').trim()
|
|
373
114
|
|
|
374
115
|
if (!raw || raw === '-' || raw === '--' || raw === '—') {
|
|
375
116
|
return ''
|
|
@@ -378,38 +119,15 @@ function normalizeNumericText(value: unknown) {
|
|
|
378
119
|
const isNegative = raw.startsWith('-') || /^\(.+\)$/.test(raw)
|
|
379
120
|
const text = raw.replace(/,/g, '').replace(/[^\d.]/g, '')
|
|
380
121
|
|
|
381
|
-
|
|
382
|
-
return ''
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
const [integer = '0', ...decimalParts] = text.split('.')
|
|
386
|
-
const decimal = decimalParts.length ? `.${decimalParts.join('')}` : ''
|
|
387
|
-
|
|
388
|
-
return `${isNegative ? '-' : ''}${integer || '0'}${decimal}`
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
function parseAmountValue(value: unknown) {
|
|
392
|
-
const text = normalizeNumericText(value)
|
|
393
|
-
|
|
394
|
-
if (!text) {
|
|
395
|
-
return Number.NaN
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
return Number(text)
|
|
122
|
+
return /\d/.test(text) ? `${isNegative ? '-' : ''}${text}` : ''
|
|
399
123
|
}
|
|
400
124
|
|
|
401
|
-
function
|
|
125
|
+
function addThousands(value: string) {
|
|
402
126
|
return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
|
403
127
|
}
|
|
404
128
|
|
|
405
|
-
function
|
|
406
|
-
return value.toLowerCase().replace(/[\s_\-./]/g, '')
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
function isUsableValue(value: unknown) {
|
|
410
|
-
return value !== null && value !== undefined && value !== ''
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
function isPlainObject(value: unknown): value is Record<string, unknown> {
|
|
129
|
+
function toObject(value: unknown): PlainObject | undefined {
|
|
414
130
|
return Object.prototype.toString.call(value) === '[object Object]'
|
|
131
|
+
? value as PlainObject
|
|
132
|
+
: undefined
|
|
415
133
|
}
|
package/src/views/HomeView.vue
CHANGED
|
@@ -23,8 +23,16 @@ 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 {
|
|
27
|
-
|
|
26
|
+
import { transformHomeBalanceData } from '@/utils/homeBalance'
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 首页余额卡片的渲染模型。
|
|
30
|
+
*
|
|
31
|
+
* 注意:
|
|
32
|
+
* - id 会和 src/utils/homeBalance.ts 转换出的字段对应,接口转换后按 id 回填金额。
|
|
33
|
+
* - amount / decimal 分开存放,是为了让整数位和小数位在视觉上使用不同字号。
|
|
34
|
+
* - background / accent 系列字段只负责视觉,不参与接口转换。
|
|
35
|
+
*/
|
|
28
36
|
type BalanceCard = {
|
|
29
37
|
id: string
|
|
30
38
|
title: string
|
|
@@ -42,6 +50,7 @@ type BalanceCard = {
|
|
|
42
50
|
glow: string
|
|
43
51
|
}
|
|
44
52
|
|
|
53
|
+
/** 首页右侧快捷菜单项,仅负责本页快捷入口展示和路由跳转。 */
|
|
45
54
|
type HomeMenuItem = {
|
|
46
55
|
label: string
|
|
47
56
|
route: string
|
|
@@ -49,9 +58,16 @@ type HomeMenuItem = {
|
|
|
49
58
|
active?: boolean
|
|
50
59
|
}
|
|
51
60
|
|
|
61
|
+
/** 页面初次渲染时显示当前时间;接口数据刷新后也会同步更新。 */
|
|
52
62
|
const updatedAt = ref(formatDateTime(new Date()))
|
|
53
63
|
const router = useRouter()
|
|
54
64
|
|
|
65
|
+
/**
|
|
66
|
+
* 首页余额卡片的默认展示数据。
|
|
67
|
+
*
|
|
68
|
+
* 后续对接接口时不用直接改这个数组结构,只需要把接口结果传给
|
|
69
|
+
* updateBalanceCardsFromApi(payload),转换工具只会按 id 返回 amount / decimal。
|
|
70
|
+
*/
|
|
55
71
|
const balanceCards = ref<BalanceCard[]>([
|
|
56
72
|
{
|
|
57
73
|
id: 'rmb',
|
|
@@ -175,18 +191,39 @@ const menuItems: HomeMenuItem[] = [
|
|
|
175
191
|
{ label: '公告', route: '/notice-announcement', icon: Bell },
|
|
176
192
|
]
|
|
177
193
|
|
|
194
|
+
/** 右侧快捷菜单跳转;当前首页项不重复 push,避免无意义路由刷新。 */
|
|
178
195
|
function openMenu(item: HomeMenuItem) {
|
|
179
196
|
if (item.route !== '/') {
|
|
180
197
|
router.push(item.route)
|
|
181
198
|
}
|
|
182
199
|
}
|
|
183
200
|
|
|
201
|
+
/**
|
|
202
|
+
* 长金额卡片使用更小字号,避免 JPY 等位数较长的币种遮挡单位。
|
|
203
|
+
* 这里按最终展示文本长度判断,而不是按原始数值判断,能覆盖接口返回字符串的情况。
|
|
204
|
+
*/
|
|
184
205
|
function isLongAmount(card: BalanceCard) {
|
|
185
206
|
return `${card.amount}${card.decimal}`.length >= 16
|
|
186
207
|
}
|
|
187
208
|
|
|
209
|
+
/**
|
|
210
|
+
* 首页接口接入点。
|
|
211
|
+
*
|
|
212
|
+
* 用法示例:
|
|
213
|
+
* const res = await fetchHomeBalance()
|
|
214
|
+
* updateBalanceCardsFromApi(res)
|
|
215
|
+
*
|
|
216
|
+
* 该方法只负责把转换后的金额更新到静态卡片;
|
|
217
|
+
* 请求、错误提示、loading 状态可以在调用方自行处理。
|
|
218
|
+
*/
|
|
188
219
|
function updateBalanceCardsFromApi(payload: unknown) {
|
|
189
|
-
|
|
220
|
+
const nextBalance = transformHomeBalanceData(payload)
|
|
221
|
+
|
|
222
|
+
balanceCards.value = balanceCards.value.map((card) => {
|
|
223
|
+
const amount = nextBalance[card.id]
|
|
224
|
+
|
|
225
|
+
return amount ? { ...card, ...amount } : card
|
|
226
|
+
})
|
|
190
227
|
updatedAt.value = formatDateTime(new Date())
|
|
191
228
|
}
|
|
192
229
|
|
|
@@ -293,6 +330,11 @@ function formatDateTime(date: Date) {
|
|
|
293
330
|
</template>
|
|
294
331
|
|
|
295
332
|
<style scoped>
|
|
333
|
+
/*
|
|
334
|
+
* 首页视觉说明:
|
|
335
|
+
* 这个页面现在运行在 App.vue 的 layout 容器内,不再独占整个 viewport。
|
|
336
|
+
* 因此根容器和内部布局高度都跟随父级 100%,避免 header/sidebar 出现后内容溢出。
|
|
337
|
+
*/
|
|
296
338
|
.balance-home {
|
|
297
339
|
--navy: #071a55;
|
|
298
340
|
--page-gap: clamp(0.55rem, 1.15vw, 1.35rem);
|
|
@@ -326,6 +368,7 @@ function formatDateTime(date: Date) {
|
|
|
326
368
|
min-height: 0;
|
|
327
369
|
}
|
|
328
370
|
|
|
371
|
+
/* 外层主面板只保留一层外边框;内部余额项不再额外套描边,避免“卡片套卡片”。 */
|
|
329
372
|
.balance-panel {
|
|
330
373
|
position: relative;
|
|
331
374
|
display: grid;
|
|
@@ -346,6 +389,7 @@ function formatDateTime(date: Date) {
|
|
|
346
389
|
backdrop-filter: blur(2px);
|
|
347
390
|
}
|
|
348
391
|
|
|
392
|
+
/* 标题区使用较克制的 dashboard 标题尺寸,右侧更新时间绝对定位到同一行附近。 */
|
|
349
393
|
.panel-head {
|
|
350
394
|
position: relative;
|
|
351
395
|
z-index: 1;
|
|
@@ -436,6 +480,11 @@ function formatDateTime(date: Date) {
|
|
|
436
480
|
padding: 0 clamp(1.25rem, 3.75vw, 4rem) clamp(1.15rem, 3.65vh, 2.8rem);
|
|
437
481
|
}
|
|
438
482
|
|
|
483
|
+
/*
|
|
484
|
+
* 单个余额项。
|
|
485
|
+
* 三列分别是:币种徽章、币种名称、金额区。
|
|
486
|
+
* 前两列被刻意压窄,给金额列保留更多空间,避免长金额遮挡单位。
|
|
487
|
+
*/
|
|
439
488
|
.balance-card {
|
|
440
489
|
position: relative;
|
|
441
490
|
display: grid;
|
|
@@ -459,6 +508,7 @@ function formatDateTime(date: Date) {
|
|
|
459
508
|
-0.16rem 0 0 var(--accent) inset;
|
|
460
509
|
}
|
|
461
510
|
|
|
511
|
+
/* 左侧色条保留币种识别,但不使用完整边框,降低内部卡片感。 */
|
|
462
512
|
.balance-card::before {
|
|
463
513
|
position: absolute;
|
|
464
514
|
top: 11%;
|
|
@@ -471,6 +521,7 @@ function formatDateTime(date: Date) {
|
|
|
471
521
|
box-shadow: 0 0 clamp(0.45rem, 0.85vw, 1rem) var(--card-glow);
|
|
472
522
|
}
|
|
473
523
|
|
|
524
|
+
/* 柔光覆盖层让底图和金额文字有层次;不参与交互。 */
|
|
474
525
|
.balance-card::after {
|
|
475
526
|
position: absolute;
|
|
476
527
|
inset: 0;
|
|
@@ -571,6 +622,7 @@ function formatDateTime(date: Date) {
|
|
|
571
622
|
padding-top: clamp(0.2rem, 0.55vw, 0.6rem);
|
|
572
623
|
}
|
|
573
624
|
|
|
625
|
+
/* 金额整数和小数拆开排版:整数强调,decimal 使用较小字号贴齐右侧。 */
|
|
574
626
|
.amount-row {
|
|
575
627
|
display: flex;
|
|
576
628
|
max-width: 100%;
|