verce-vue-test 0.0.76 → 0.0.78

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.
@@ -1,18 +1,35 @@
1
1
  <script setup lang="ts">
2
+ /**
3
+ * 人民币头寸匡算页面。
4
+ *
5
+ * 主要职责:
6
+ * 1. 根据交易日期加载已保存的手工填入数据;
7
+ * 2. 收集以“亿元”为单位的页面输入,并转换为以“元”为单位的接口参数;
8
+ * 3. 展示接口返回的业务分类金额,并计算小计、日初可用资金和预计余额;
9
+ * 4. 管理查询、导出参数打印以及快速切换日期时的请求竞态。
10
+ */
2
11
  import { computed, onBeforeUnmount, reactive, ref } from 'vue'
3
- import { Search } from '@element-plus/icons-vue'
12
+ import { Download, Search } from '@element-plus/icons-vue'
4
13
  import { ElMessage } from 'element-plus'
14
+ import API from './api'
5
15
  import {
6
- requestRmbPositionEstimation,
16
+ rmbPositionAmountFields,
17
+ rmbPositionHistoryAmountFields,
18
+ rmbPositionHistoryRemarkFields,
7
19
  type ProtocolAmount,
8
20
  type RmbPositionAmountField,
9
21
  type RmbPositionEstimationRequestBody,
10
22
  type RmbPositionEstimationResponseBody,
11
- } from './rmb-position-estimation/api'
23
+ type RmbPositionHistoryResponseBody,
24
+ } from './types'
12
25
 
26
+ // 页面按“亿元”输入和展示,TAM 接口按“元”传输。
27
+ // 使用 BigInt 进行换算,避免大额资金经过 Number 浮点运算后产生精度误差。
13
28
  const YUAN_PER_YI = 100_000_000n
29
+ // 0.01 亿元 = 1,000,000 元,用于将展示金额四舍五入到两位小数。
14
30
  const YUAN_PER_YI_CENT = 1_000_000n
15
31
 
32
+ /** 页面中允许用户手工录入的金额字段。 */
16
33
  type ManualAmountKey =
17
34
  | 'overAmt'
18
35
  | 'fzAmtIn'
@@ -24,16 +41,21 @@ type ManualAmountKey =
24
41
  | 'ysAmtIn'
25
42
  | 'ysAmtOut'
26
43
 
44
+ /** 与手工金额行配套的备注字段。 */
27
45
  type RemarkKey = 'fzAmtRmk' | 'bepsAmtRmk' | 'othAmtRmk' | 'ysAmtRmk'
46
+ /** 表单内部统一保存字符串,以保留输入状态、千分位和小数点。 */
28
47
  type FormState = { tranDate: string } & Record<ManualAmountKey | RemarkKey, string>
48
+ /** TAM 返回字段的业务前缀,用于按命名规则生成收入、支出和轧差字段。 */
29
49
  type PairPrefix = 'hg' | 'zq' | 'pj' | 'tg' | 'ty' | 'fzh' | 'lc' | 'qt' | 'zj'
30
50
 
51
+ /** 一组收入、支出、轧差结果字段。 */
31
52
  type AmountCells = {
32
53
  income: RmbPositionAmountField
33
54
  expense: RmbPositionAmountField
34
55
  net: RmbPositionAmountField
35
56
  }
36
57
 
58
+ /** 同时包含“报备金额”和“未核销金额”的两行式业务分区。 */
37
59
  type PairSection = {
38
60
  key: PairPrefix
39
61
  label: string
@@ -42,6 +64,7 @@ type PairSection = {
42
64
  unverified: AmountCells
43
65
  }
44
66
 
67
+ /** 可编辑的手工填入行配置。 */
45
68
  type ManualRow = {
46
69
  key: string
47
70
  label: string
@@ -50,26 +73,81 @@ type ManualRow = {
50
73
  remarkKey: RemarkKey
51
74
  }
52
75
 
76
+ /** 只有一行接口结果、没有手工输入项的业务行配置。 */
53
77
  type SingleResultRow = {
54
78
  key: string
55
79
  label: string
56
80
  cells: AmountCells
57
81
  }
58
82
 
83
+ /** 可点击结果单元格对应的原表格位置及后续联查索引。 */
59
84
  type LinkedCell = {
60
85
  id: string
61
86
  index: number
62
87
  field: RmbPositionAmountField
63
88
  }
64
89
 
90
+ /**
91
+ * 校验匡算接口的原始 body,并收敛为页面可安全使用的结构。
92
+ * 匡算结果字段缺失或金额不是合法数字时直接抛错,避免用不完整数据继续汇总。
93
+ */
94
+ function normalizeEstimationResponseBody(
95
+ source: Record<string, unknown>,
96
+ ): RmbPositionEstimationResponseBody {
97
+ const normalized = {
98
+ fileName: String(source.fileName ?? ''),
99
+ } as RmbPositionEstimationResponseBody
100
+
101
+ rmbPositionAmountFields.forEach((field) => {
102
+ if (!Object.hasOwn(source, field)) {
103
+ throw new Error(`人民币头寸匡算接口缺少返回字段:${field}`)
104
+ }
105
+ const value = String(source[field] ?? '').trim()
106
+ if (!/^-?(?:\d+(?:\.\d+)?|\.\d+)$/.test(value)) {
107
+ throw new Error(`人民币头寸匡算接口金额字段格式不正确:${field}`)
108
+ }
109
+ normalized[field] = value
110
+ })
111
+
112
+ return normalized
113
+ }
114
+
115
+ /**
116
+ * 整理历史填入接口的原始 body。
117
+ * 历史接口允许返回空对象,代表所选日期尚未保存数据;存在的金额字段仍需逐项校验。
118
+ */
119
+ function normalizeHistoryResponseBody(
120
+ source: Record<string, unknown>,
121
+ ): RmbPositionHistoryResponseBody {
122
+ const normalized: RmbPositionHistoryResponseBody = {}
123
+
124
+ rmbPositionHistoryAmountFields.forEach((field) => {
125
+ if (!Object.hasOwn(source, field)) return
126
+ const value = String(source[field] ?? '').trim()
127
+ if (!/^-?(?:\d+(?:\.\d+)?|\.\d+)$/.test(value)) {
128
+ throw new Error(`人民币头寸历史查询接口金额字段格式不正确:${field}`)
129
+ }
130
+ normalized[field] = value
131
+ })
132
+
133
+ rmbPositionHistoryRemarkFields.forEach((field) => {
134
+ if (Object.hasOwn(source, field)) normalized[field] = String(source[field] ?? '')
135
+ })
136
+
137
+ return normalized
138
+ }
139
+
140
+ /** 将日期、时间片段补齐为两位。 */
65
141
  function pad(value: number) {
66
142
  return String(value).padStart(2, '0')
67
143
  }
68
144
 
145
+ /** 将 Date 转为 TAM 使用的 YYYYMMDD 紧凑日期。 */
69
146
  function compactDate(date: Date) {
70
147
  return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
71
148
  }
72
149
 
150
+ /** 同时校验格式和真实日历日期,排除 20260231 之类的无效配置。 */
73
151
  function isValidCompactDate(value: string) {
74
152
  if (!/^\d{8}$/.test(value)) return false
75
153
  const year = Number(value.slice(0, 4))
@@ -79,11 +157,16 @@ function isValidCompactDate(value: string) {
79
157
  return compactDate(date) === value
80
158
  }
81
159
 
160
+ /** 优先采用系统工作日配置,未配置或配置无效时回退到本机当天。 */
82
161
  function initialBusinessDate() {
83
162
  const configuredDate = String(import.meta.env.VITE_SYSTEM_WORK_DATE || '').trim()
84
163
  return isValidCompactDate(configuredDate) ? configuredDate : compactDate(new Date())
85
164
  }
86
165
 
166
+ /**
167
+ * 根据 TAM 字段命名约定生成一组结果字段:
168
+ * 例如 hg + Pred => hgPredAmtIn / hgPredAmtOut / hgPredAmtNet。
169
+ */
87
170
  function createAmountCells(prefix: PairPrefix, type: 'Pred' | 'Unverify'): AmountCells {
88
171
  return {
89
172
  income: `${prefix}${type}AmtIn` as RmbPositionAmountField,
@@ -92,6 +175,7 @@ function createAmountCells(prefix: PairPrefix, type: 'Pred' | 'Unverify'): Amoun
92
175
  }
93
176
  }
94
177
 
178
+ /** 创建模板可直接循环渲染的两行式业务分区配置。 */
95
179
  function createPairSection(
96
180
  key: PairPrefix,
97
181
  shortLabel: string,
@@ -106,6 +190,7 @@ function createPairSection(
106
190
  }
107
191
  }
108
192
 
193
+ // 主表上半部分的八类两行式业务分区,顺序必须与后端字段及原业务表格保持一致。
109
194
  const pairSections: PairSection[] = [
110
195
  createPairSection('hg', '回购', '回购(拆借)到期,CD发行、投资及到期'),
111
196
  createPairSection('zq', '债券', '债券承销'),
@@ -117,8 +202,10 @@ const pairSections: PairSection[] = [
117
202
  createPairSection('qt', '其他', '其他'),
118
203
  ]
119
204
 
205
+ // 表格底部的“资金”分区结构相同,但参与预计余额的位置不同,因此单独配置。
120
206
  const fundSection = createPairSection('zj', '资金', '今日资金交易新业务收付合计')
121
207
 
208
+ // 三类由用户手工填入收入、支出及备注的业务行。
122
209
  const manualRows: ManualRow[] = [
123
210
  {
124
211
  key: 'reserve',
@@ -143,6 +230,7 @@ const manualRows: ManualRow[] = [
143
230
  },
144
231
  ]
145
232
 
233
+ // 直接展示接口结果的三类单行数据,不包含可编辑金额。
146
234
  const singleResultRows: SingleResultRow[] = [
147
235
  {
148
236
  key: 'cash-message',
@@ -161,12 +249,14 @@ const singleResultRows: SingleResultRow[] = [
161
249
  },
162
250
  ]
163
251
 
252
+ // 建立“接口字段 -> 原表格坐标”的映射,为结果数字点击后的明细联查预留参数。
164
253
  const linkedCellMap = new Map<RmbPositionAmountField, LinkedCell>()
165
254
 
166
255
  function registerLinkedCell(field: RmbPositionAmountField, id: string, index: number) {
167
256
  linkedCellMap.set(field, { id, index, field })
168
257
  }
169
258
 
259
+ // 两行式分区每类注册四个可联查单元格:报备收入/支出、未核销收入/支出。
170
260
  pairSections.forEach((section, sectionIndex) => {
171
261
  const predictionRow = 5 + sectionIndex * 2
172
262
  const unverifiedRow = predictionRow + 1
@@ -178,6 +268,7 @@ pairSections.forEach((section, sectionIndex) => {
178
268
  registerLinkedCell(section.unverified.expense, `D${unverifiedRow}`, startIndex + 3)
179
269
  })
180
270
 
271
+ // 单行结果只为收入和支出注册联查,轧差由前两项计算或由接口直接展示。
181
272
  singleResultRows.forEach((row, rowIndex) => {
182
273
  const tableRow = 24 + rowIndex
183
274
  const startIndex = 32 + rowIndex * 2
@@ -191,6 +282,7 @@ registerLinkedCell(fundSection.prediction.expense, 'D31', 39)
191
282
  registerLinkedCell(fundSection.unverified.income, 'C32', 40)
192
283
  registerLinkedCell(fundSection.unverified.expense, 'D32', 41)
193
284
 
285
+ // 小计只汇总“报备金额”以及三类单行结果;未核销金额和底部资金分区不计入此处。
194
286
  const predictionIncomeFields = pairSections.map((section) => section.prediction.income)
195
287
  const predictionExpenseFields = pairSections.map((section) => section.prediction.expense)
196
288
  const subtotalResultIncomeFields: RmbPositionAmountField[] = [
@@ -206,6 +298,7 @@ const subtotalResultExpenseFields: RmbPositionAmountField[] = [
206
298
  'unVerifyAmtOut',
207
299
  ]
208
300
 
301
+ // 集中维护金额和备注键,供重置、校验、历史回填等公共流程复用。
209
302
  const manualAmountKeys: ManualAmountKey[] = [
210
303
  'overAmt',
211
304
  'fzAmtIn',
@@ -220,6 +313,7 @@ const manualAmountKeys: ManualAmountKey[] = [
220
313
 
221
314
  const remarkKeys: RemarkKey[] = ['fzAmtRmk', 'bepsAmtRmk', 'othAmtRmk', 'ysAmtRmk']
222
315
 
316
+ // 校验提示使用的中文名称,避免向用户暴露协议字段名。
223
317
  const amountFieldLabels: Record<ManualAmountKey, string> = {
224
318
  overAmt: '昨日超额备付余额',
225
319
  fzAmtIn: '法定准备金等收入',
@@ -232,6 +326,7 @@ const amountFieldLabels: Record<ManualAmountKey, string> = {
232
326
  ysAmtOut: '今日资金交易预计支出',
233
327
  }
234
328
 
329
+ // 以下每组收入、支出至少填写一项;另一项留空时按 0 处理。
235
330
  const requiredPairs: Array<[ManualAmountKey, ManualAmountKey]> = [
236
331
  ['fzAmtIn', 'fzAmtOut'],
237
332
  ['bepsAmtIn', 'bepsAmtOut'],
@@ -239,6 +334,7 @@ const requiredPairs: Array<[ManualAmountKey, ManualAmountKey]> = [
239
334
  ['ysAmtIn', 'ysAmtOut'],
240
335
  ]
241
336
 
337
+ // 表单金额始终保留为字符串:失焦时可包含千分位,聚焦时移除千分位便于编辑。
242
338
  const form = reactive<FormState>({
243
339
  tranDate: initialBusinessDate(),
244
340
  overAmt: '',
@@ -256,14 +352,22 @@ const form = reactive<FormState>({
256
352
  ysAmtRmk: '',
257
353
  })
258
354
 
355
+ // result 为 null 表示尚未完成匡算,此时计算结果区域显示为空而不是 0。
259
356
  const result = ref<RmbPositionEstimationResponseBody | null>(null)
260
357
  const loading = ref(false)
358
+ const loadingText = ref('正在进行头寸匡算…')
359
+ // 日期历史查询和匡算查询共用控制器;新请求启动前会取消旧请求,防止旧响应覆盖新状态。
261
360
  let requestController: AbortController | null = null
262
361
 
362
+ /** 移除展示态千分位,得到可参与校验和换算的普通数字文本。 */
263
363
  function stripGrouping(value: string) {
264
364
  return value.trim().replaceAll(',', '')
265
365
  }
266
366
 
367
+ /**
368
+ * 校验以“亿元”为单位的用户输入。
369
+ * 最多允许 8 位小数,因为 0.00000001 亿元恰好等于 1 元,再多位数无法精确映射到人民币元。
370
+ */
267
371
  function isValidYiAmount(value: string) {
268
372
  const original = value.trim()
269
373
  if (!/^-?(?:(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d*)?|\.\d+)$/.test(original)) return false
@@ -272,6 +376,10 @@ function isValidYiAmount(value: string) {
272
376
  return decimalLength <= 8
273
377
  }
274
378
 
379
+ /**
380
+ * 将“亿元”字符串精确转换为“元”BigInt。
381
+ * 通过拆分整数和小数完成换算,不使用 parseFloat,确保大额及小数金额不丢精度。
382
+ */
275
383
  function yiTextToYuan(value: string) {
276
384
  const normalized = stripGrouping(value)
277
385
  if (!normalized) return 0n
@@ -285,6 +393,10 @@ function yiTextToYuan(value: string) {
285
393
  return negative ? -yuan : yuan
286
394
  }
287
395
 
396
+ /**
397
+ * 将接口返回的“元”文本转为 BigInt。
398
+ * 若后端意外返回元以下小数,则按第一位小数执行四舍五入,保证后续只在整数元上计算。
399
+ */
288
400
  function yuanTextToBigInt(value: unknown) {
289
401
  const normalized = String(value ?? '0').trim().replaceAll(',', '')
290
402
  if (/^-?\d+$/.test(normalized)) return BigInt(normalized)
@@ -299,10 +411,12 @@ function yuanTextToBigInt(value: unknown) {
299
411
  return match[1] === '-' ? -roundedAbsolute : roundedAbsolute
300
412
  }
301
413
 
414
+ /** 为整数部分增加千分位分隔符。 */
302
415
  function groupInteger(value: string) {
303
416
  return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
304
417
  }
305
418
 
419
+ /** 对正负 BigInt 执行传统的四舍五入除法。 */
306
420
  function divideAndRoundHalfUp(value: bigint, divisor: bigint) {
307
421
  const negative = value < 0n
308
422
  const absolute = negative ? -value : value
@@ -311,10 +425,12 @@ function divideAndRoundHalfUp(value: bigint, divisor: bigint) {
311
425
  return negative ? -rounded : rounded
312
426
  }
313
427
 
428
+ /** 将元金额四舍五入到 0.01 亿元对应的整数元刻度。 */
314
429
  function roundYuanToYiCent(value: bigint) {
315
430
  return divideAndRoundHalfUp(value, YUAN_PER_YI_CENT) * YUAN_PER_YI_CENT
316
431
  }
317
432
 
433
+ /** 将接口单位“元”格式化为页面单位“亿元”,固定两位小数并带千分位。 */
318
434
  function formatYuanAsYi(value: bigint | string) {
319
435
  const yuan = typeof value === 'bigint' ? value : yuanTextToBigInt(value)
320
436
  const roundedYuan = roundYuanToYiCent(yuan)
@@ -328,6 +444,7 @@ function formatYuanAsYi(value: bigint | string) {
328
444
  return `${sign}${groupInteger(String(integerPart))}.${String(decimalPart).padStart(2, '0')}`
329
445
  }
330
446
 
447
+ /** 获取单个接口结果的展示文本;接口已返回空值时按 0.00 展示。 */
331
448
  function displayResultValue(field: RmbPositionAmountField) {
332
449
  if (!result.value) return ''
333
450
 
@@ -337,16 +454,19 @@ function displayResultValue(field: RmbPositionAmountField) {
337
454
  return formatYuanAsYi(value)
338
455
  }
339
456
 
457
+ /** 手工行轧差 = 收入 - 支出,仅在已有匡算结果时显示。 */
340
458
  function displayManualNet(incomeKey: ManualAmountKey, expenseKey: ManualAmountKey) {
341
459
  if (!result.value) return ''
342
460
  return formatYuanAsYi(yiTextToYuan(form[incomeKey]) - yiTextToYuan(form[expenseKey]))
343
461
  }
344
462
 
463
+ /** 按字段列表汇总接口返回值,内部始终使用“元”BigInt。 */
345
464
  function sumResultFields(fields: RmbPositionAmountField[]) {
346
465
  if (!result.value) return 0n
347
466
  return fields.reduce((sum, field) => sum + yuanTextToBigInt(result.value?.[field]), 0n)
348
467
  }
349
468
 
469
+ // 收入小计 = 接口报备类收入 + 现金/未核销单行收入 + 三类手工收入。
350
470
  const subtotalIncomeYuan = computed<bigint | null>(() => {
351
471
  if (!result.value) return null
352
472
  return sumResultFields(subtotalResultIncomeFields)
@@ -355,6 +475,7 @@ const subtotalIncomeYuan = computed<bigint | null>(() => {
355
475
  + yiTextToYuan(form.othAmtIn)
356
476
  })
357
477
 
478
+ // 支出小计与收入小计采用完全对称的字段范围。
358
479
  const subtotalExpenseYuan = computed<bigint | null>(() => {
359
480
  if (!result.value) return null
360
481
  return sumResultFields(subtotalResultExpenseFields)
@@ -363,34 +484,47 @@ const subtotalExpenseYuan = computed<bigint | null>(() => {
363
484
  + yiTextToYuan(form.othAmtOut)
364
485
  })
365
486
 
487
+ // 小计轧差 = 收入小计 - 支出小计。
366
488
  const subtotalNetYuan = computed<bigint | null>(() => {
367
489
  if (subtotalIncomeYuan.value === null || subtotalExpenseYuan.value === null) return null
368
490
  return subtotalIncomeYuan.value - subtotalExpenseYuan.value
369
491
  })
370
492
 
493
+ // 日初可用资金 = 昨日超额备付余额 + 当前小计轧差。
371
494
  const openingAvailableYuan = computed<bigint | null>(() => {
372
495
  if (subtotalNetYuan.value === null) return null
373
496
  return yiTextToYuan(form.overAmt) + subtotalNetYuan.value
374
497
  })
375
498
 
499
+ // 今日预计余额 = 日初可用资金 + 今日资金交易预计收入 - 今日资金交易预计支出。
376
500
  const estimatedBalanceYuan = computed<bigint | null>(() => {
377
501
  if (openingAvailableYuan.value === null) return null
378
502
  return openingAvailableYuan.value + yiTextToYuan(form.ysAmtIn) - yiTextToYuan(form.ysAmtOut)
379
503
  })
380
504
 
505
+ /** 汇总结果尚不可计算时返回空文本,否则统一格式化。 */
381
506
  function displaySummary(value: bigint | null) {
382
507
  return value === null ? '' : formatYuanAsYi(value)
383
508
  }
384
509
 
510
+ /** 任一输入发生变化后清空旧匡算结果,避免页面展示与当前参数不一致的数据。 */
385
511
  function clearResult() {
386
512
  result.value = null
387
513
  }
388
514
 
515
+ /** 金额失焦时执行四舍五入,固定两位小数并添加千分位。 */
389
516
  function normalizeAmountField(key: ManualAmountKey) {
390
517
  const original = form[key]
391
- if (isValidYiAmount(original)) form[key] = stripGrouping(original)
518
+ if (!isValidYiAmount(original)) return
519
+ form[key] = formatYuanAsYi(yiTextToYuan(original))
520
+ }
521
+
522
+ /** 金额获得焦点时去除千分位,恢复便于继续编辑的普通数字。 */
523
+ function activateAmountField(key: ManualAmountKey) {
524
+ form[key] = stripGrouping(form[key])
392
525
  }
393
526
 
527
+ /** 切换交易日期前清空上一日期的手工金额和备注。 */
394
528
  function resetManualInputs() {
395
529
  manualAmountKeys.forEach((key) => {
396
530
  form[key] = ''
@@ -400,14 +534,63 @@ function resetManualInputs() {
400
534
  })
401
535
  }
402
536
 
403
- function handleDateChange() {
537
+ /**
538
+ * 将历史接口返回的“元”金额回填为页面使用的“亿元”展示文本。
539
+ * body 为空或某字段不存在时保持空输入,备注不做数值转换。
540
+ */
541
+ function fillHistoryInputs(history: RmbPositionHistoryResponseBody) {
542
+ manualAmountKeys.forEach((key) => {
543
+ const value = history[key]
544
+ form[key] = value === undefined || value.trim() === ''
545
+ ? ''
546
+ : formatYuanAsYi(value)
547
+ })
548
+ remarkKeys.forEach((key) => {
549
+ form[key] = history[key] ?? ''
550
+ })
551
+ }
552
+
553
+ /**
554
+ * 日期切换后查询历史填入数据。
555
+ * 每次切换都会先取消前一请求;只有当前控制器对应的响应才允许回填和结束 loading。
556
+ */
557
+ async function handleDateChange() {
404
558
  requestController?.abort()
405
- requestController = null
406
- loading.value = false
407
559
  resetManualInputs()
408
560
  clearResult()
561
+
562
+ if (!form.tranDate) {
563
+ requestController = null
564
+ loading.value = false
565
+ return
566
+ }
567
+
568
+ const controller = new AbortController()
569
+ requestController = controller
570
+ loadingText.value = '正在查询历史数据…'
571
+ loading.value = true
572
+
573
+ try {
574
+ const response = await API.historyAPI({ tranDate: form.tranDate }, {
575
+ signal: controller.signal,
576
+ })
577
+ if (controller.signal.aborted || requestController !== controller) return
578
+ fillHistoryInputs(normalizeHistoryResponseBody(response.body))
579
+ } catch (error) {
580
+ if (!isAbortError(error)) {
581
+ ElMessage.error(error instanceof Error ? error.message : '人民币头寸历史查询失败')
582
+ }
583
+ } finally {
584
+ if (requestController === controller) {
585
+ loading.value = false
586
+ requestController = null
587
+ }
588
+ }
409
589
  }
410
590
 
591
+ /**
592
+ * 结果数字点击入口。目前仅打印联查参数;后续接入明细页时可在此统一跳转或打开弹窗。
593
+ */
411
594
  function openLink(field: RmbPositionAmountField) {
412
595
  const cell = linkedCellMap.get(field)
413
596
  if (!cell) return
@@ -418,6 +601,10 @@ function openLink(field: RmbPositionAmountField) {
418
601
  })
419
602
  }
420
603
 
604
+ /**
605
+ * 将页面的“亿元”输入转换为接口的“元”金额。
606
+ * 接口历史约定零值使用字符串 '0',非零值使用安全整数 Number。
607
+ */
421
608
  function toProtocolAmount(key: ManualAmountKey): ProtocolAmount {
422
609
  const yuan = yiTextToYuan(form[key])
423
610
  if (yuan === 0n) return '0'
@@ -429,6 +616,10 @@ function toProtocolAmount(key: ManualAmountKey): ProtocolAmount {
429
616
  return amount
430
617
  }
431
618
 
619
+ /**
620
+ * 查询和导出共用的提交前校验:日期、必填项、成对金额、格式和安全整数范围。
621
+ * 该函数只负责提示并返回布尔值,不修改表单数据。
622
+ */
432
623
  function validateForm() {
433
624
  if (!form.tranDate) {
434
625
  ElMessage.warning('请选择交易日期')
@@ -465,8 +656,9 @@ function validateForm() {
465
656
  return true
466
657
  }
467
658
 
468
- function buildRequestBody(): RmbPositionEstimationRequestBody {
469
- return {
659
+ // 查询和导出共享同一份计算参数;只有真正触发操作时才读取 value 并完成单位换算。
660
+ const queryParams = computed<RmbPositionEstimationRequestBody>(() => (
661
+ {
470
662
  overAmt: toProtocolAmount('overAmt'),
471
663
  tranDate: form.tranDate,
472
664
  fzAmtIn: toProtocolAmount('fzAmtIn'),
@@ -482,27 +674,40 @@ function buildRequestBody(): RmbPositionEstimationRequestBody {
482
674
  ysAmtOut: toProtocolAmount('ysAmtOut'),
483
675
  ysAmtRmk: form.ysAmtRmk.trim(),
484
676
  }
677
+ ))
678
+
679
+ /** 导出功能暂未接入接口,仅在查询参数基础上追加操作类型并打印。 */
680
+ function exportEstimation() {
681
+ if (!validateForm()) return
682
+
683
+ console.log('人民币头寸匡算导出参数:', {
684
+ ...queryParams.value,
685
+ opType: 'export',
686
+ })
485
687
  }
486
688
 
689
+ /** 主动取消请求属于正常交互,不向用户显示错误消息。 */
487
690
  function isAbortError(error: unknown) {
488
691
  return error instanceof DOMException && error.name === 'AbortError'
489
692
  }
490
693
 
694
+ /** 执行头寸匡算,并将经过完整性校验的接口结果写入页面状态。 */
491
695
  async function queryEstimation() {
492
696
  if (!validateForm()) return
493
697
 
494
698
  requestController?.abort()
495
699
  const controller = new AbortController()
496
700
  requestController = controller
701
+ loadingText.value = '正在进行头寸匡算…'
497
702
  loading.value = true
498
703
  clearResult()
499
704
 
500
705
  try {
501
- const response = await requestRmbPositionEstimation(buildRequestBody(), {
706
+ const response = await API.queryAPI(queryParams.value, {
502
707
  signal: controller.signal,
503
708
  })
504
709
  if (controller.signal.aborted || requestController !== controller) return
505
- result.value = response.body
710
+ result.value = normalizeEstimationResponseBody(response.body)
506
711
  } catch (error) {
507
712
  if (!isAbortError(error)) {
508
713
  ElMessage.error(error instanceof Error ? error.message : '人民币头寸匡算失败')
@@ -515,6 +720,7 @@ async function queryEstimation() {
515
720
  }
516
721
  }
517
722
 
723
+ // 离开页面时终止未完成请求,避免卸载后的组件继续更新状态。
518
724
  onBeforeUnmount(() => {
519
725
  requestController?.abort()
520
726
  })
@@ -522,6 +728,7 @@ onBeforeUnmount(() => {
522
728
 
523
729
  <template>
524
730
  <div class="rmb-position-estimation-page">
731
+ <!-- 顶部操作区:日期切换负责历史回填,查询和导出共享下方计算参数。 -->
525
732
  <div class="query-section">
526
733
  <el-form
527
734
  :model="form"
@@ -550,14 +757,23 @@ onBeforeUnmount(() => {
550
757
  >
551
758
  查询
552
759
  </el-button>
760
+ <el-button
761
+ native-type="button"
762
+ :icon="Download"
763
+ :disabled="loading"
764
+ @click="exportEstimation"
765
+ >
766
+ 导出
767
+ </el-button>
553
768
  </el-form-item>
554
769
  </el-form>
555
770
  </div>
556
771
 
772
+ <!-- 主表加载遮罩同时覆盖历史查询和匡算查询,提示文字由当前操作动态切换。 -->
557
773
  <div
558
774
  id="mainDiv"
559
775
  v-loading="loading"
560
- element-loading-text="正在进行头寸匡算…"
776
+ :element-loading-text="loadingText"
561
777
  >
562
778
  <table class="tab">
563
779
  <colgroup>
@@ -569,6 +785,7 @@ onBeforeUnmount(() => {
569
785
  <col class="col-remark" />
570
786
  </colgroup>
571
787
  <tbody>
788
+ <!-- 表头第一行同时承载昨日余额输入、金额单位和备注跨行标题。 -->
572
789
  <tr class="head-row">
573
790
  <td colspan="2">昨日超额备付余额</td>
574
791
  <td>
@@ -580,6 +797,7 @@ onBeforeUnmount(() => {
580
797
  :disabled="loading"
581
798
  aria-label="昨日超额备付余额,单位亿元"
582
799
  @input="clearResult"
800
+ @focus="activateAmountField('overAmt')"
583
801
  @blur="normalizeAmountField('overAmt')"
584
802
  />
585
803
  </td>
@@ -594,6 +812,7 @@ onBeforeUnmount(() => {
594
812
  <td>轧差</td>
595
813
  </tr>
596
814
 
815
+ <!-- 八类业务均按“报备金额 + 未核销金额”两行渲染。蓝色金额可触发明细联查。 -->
597
816
  <template v-for="section in pairSections" :key="section.key">
598
817
  <tr>
599
818
  <td rowspan="2" class="section-name">{{ section.label }}</td>
@@ -632,6 +851,7 @@ onBeforeUnmount(() => {
632
851
  </tr>
633
852
  </template>
634
853
 
854
+ <!-- 手工填入区:收入和支出以亿元录入,轧差由页面实时计算,备注保留原始文本。 -->
635
855
  <tr v-for="row in manualRows" :key="row.key">
636
856
  <td colspan="2">{{ row.label }}</td>
637
857
  <td>
@@ -643,6 +863,7 @@ onBeforeUnmount(() => {
643
863
  :disabled="loading"
644
864
  :aria-label="row.label + '收入,单位亿元'"
645
865
  @input="clearResult"
866
+ @focus="activateAmountField(row.incomeKey)"
646
867
  @blur="normalizeAmountField(row.incomeKey)"
647
868
  />
648
869
  </td>
@@ -655,6 +876,7 @@ onBeforeUnmount(() => {
655
876
  :disabled="loading"
656
877
  :aria-label="row.label + '支出,单位亿元'"
657
878
  @input="clearResult"
879
+ @focus="activateAmountField(row.expenseKey)"
658
880
  @blur="normalizeAmountField(row.expenseKey)"
659
881
  />
660
882
  </td>
@@ -672,6 +894,7 @@ onBeforeUnmount(() => {
672
894
  </td>
673
895
  </tr>
674
896
 
897
+ <!-- 现金报文及两档未核销流水完全来自匡算接口,不允许手工修改。 -->
675
898
  <tr v-for="row in singleResultRows" :key="row.key">
676
899
  <td colspan="2">{{ row.label }}</td>
677
900
  <td align="right" class="money-cell even">
@@ -690,6 +913,7 @@ onBeforeUnmount(() => {
690
913
  <td class="even"></td>
691
914
  </tr>
692
915
 
916
+ <!-- 第一阶段汇总:小计以及在昨日余额基础上计算出的日初可用资金。 -->
693
917
  <tr class="summary-row">
694
918
  <td colspan="2" class="red">小计</td>
695
919
  <td align="right" class="money-cell strong-value">
@@ -714,6 +938,7 @@ onBeforeUnmount(() => {
714
938
  <td colspan="6"></td>
715
939
  </tr>
716
940
 
941
+ <!-- 第二阶段手工输入:当天资金交易的预计收入、支出和备注。 -->
717
942
  <tr>
718
943
  <td colspan="2" class="red">今日资金交易预计收付额</td>
719
944
  <td>
@@ -725,6 +950,7 @@ onBeforeUnmount(() => {
725
950
  :disabled="loading"
726
951
  aria-label="今日资金交易预计收入,单位亿元"
727
952
  @input="clearResult"
953
+ @focus="activateAmountField('ysAmtIn')"
728
954
  @blur="normalizeAmountField('ysAmtIn')"
729
955
  />
730
956
  </td>
@@ -737,6 +963,7 @@ onBeforeUnmount(() => {
737
963
  :disabled="loading"
738
964
  aria-label="今日资金交易预计支出,单位亿元"
739
965
  @input="clearResult"
966
+ @focus="activateAmountField('ysAmtOut')"
740
967
  @blur="normalizeAmountField('ysAmtOut')"
741
968
  />
742
969
  </td>
@@ -754,6 +981,7 @@ onBeforeUnmount(() => {
754
981
  </td>
755
982
  </tr>
756
983
 
984
+ <!-- 资金新业务仍按报备/未核销两行展示,最终汇入今日预计余额。 -->
757
985
  <tr>
758
986
  <td rowspan="2" class="section-name">{{ fundSection.label }}</td>
759
987
  <td>报备金额</td>
@@ -789,6 +1017,7 @@ onBeforeUnmount(() => {
789
1017
  </td>
790
1018
  <td></td>
791
1019
  </tr>
1020
+ <!-- 最终结果 = 日初可用资金 + 今日资金交易预计收付轧差。 -->
792
1021
  <tr class="total-row">
793
1022
  <td colspan="2" class="bold red">今日超额备付金预计余额</td>
794
1023
  <td colspan="3" class="bold red">
@@ -803,6 +1032,7 @@ onBeforeUnmount(() => {
803
1032
  </template>
804
1033
 
805
1034
  <style scoped>
1035
+ /* 页面保持紧凑的业务报表形态,外层卡片负责与应用背景分离。 */
806
1036
  .rmb-position-estimation-page {
807
1037
  width: calc(100% - 20px);
808
1038
  margin: 10px;
@@ -813,6 +1043,7 @@ onBeforeUnmount(() => {
813
1043
  box-sizing: border-box;
814
1044
  }
815
1045
 
1046
+ /* 表格高度超过可视区域时在容器内部滚动,避免整页操作栏被卷走。 */
816
1047
  #mainDiv {
817
1048
  width: 100%;
818
1049
  max-height: 760px;
@@ -822,6 +1053,7 @@ onBeforeUnmount(() => {
822
1053
  box-sizing: border-box;
823
1054
  }
824
1055
 
1056
+ /* 固定列宽保证复杂表头和金额列始终对齐;窄屏通过横向滚动完整查看。 */
825
1057
  .tab {
826
1058
  width: 100%;
827
1059
  min-width: 1180px;
@@ -894,6 +1126,7 @@ onBeforeUnmount(() => {
894
1126
  background: #f1f5f9;
895
1127
  }
896
1128
 
1129
+ /* 蓝色结果表示该金额可以点击联查,与普通不可点击的轧差值形成区分。 */
897
1130
  .result-value {
898
1131
  display: inline-block;
899
1132
  min-width: 44px;
@@ -914,6 +1147,7 @@ onBeforeUnmount(() => {
914
1147
  font-weight: 700;
915
1148
  }
916
1149
 
1150
+ /* 小计和关键余额采用暖色背景,强调其业务优先级。 */
917
1151
  .red {
918
1152
  color: #dc2626;
919
1153
  background: #fff7ed !important;
@@ -939,29 +1173,55 @@ onBeforeUnmount(() => {
939
1173
  background: #fff;
940
1174
  }
941
1175
 
1176
+ /* 表格内输入框统一铺满单元格,以下样式仅作用于金额及备注编辑控件。 */
942
1177
  .intStyle {
943
1178
  width: 100%;
944
1179
  }
945
1180
 
1181
+ /* 常态保留蓝青色发光边框,让可编辑单元格在密集报表中易于识别。 */
946
1182
  .intStyle :deep(.el-input__wrapper) {
947
1183
  height: 18px;
948
1184
  min-height: 18px;
949
1185
  padding: 0;
950
1186
  border-radius: 4px;
951
- background: transparent;
952
- box-shadow: none;
1187
+ background: #fff;
1188
+ box-shadow:
1189
+ 0 0 0 1px rgba(59, 130, 246, 0.78),
1190
+ 0 0 7px rgba(56, 189, 248, 0.42),
1191
+ inset 0 0 5px rgba(147, 197, 253, 0.12);
1192
+ transition: box-shadow 180ms ease, background-color 180ms ease;
1193
+ }
1194
+
1195
+ /* 悬停增强光晕,反馈当前可交互区域。 */
1196
+ .intStyle :deep(.el-input__wrapper:hover) {
1197
+ box-shadow:
1198
+ 0 0 0 1px #38bdf8,
1199
+ 0 0 10px rgba(14, 165, 233, 0.58),
1200
+ inset 0 0 6px rgba(125, 211, 252, 0.18) !important;
953
1201
  }
954
1202
 
955
- .intStyle :deep(.el-input__wrapper:hover),
1203
+ /* 聚焦态使用更强的双层光晕,同时略微提亮输入背景。 */
956
1204
  .intStyle :deep(.el-input__wrapper.is-focus) {
957
- box-shadow: none !important;
1205
+ background: #fafdff;
1206
+ box-shadow:
1207
+ 0 0 0 1px #2563eb,
1208
+ 0 0 12px rgba(37, 99, 235, 0.68),
1209
+ 0 0 20px rgba(56, 189, 248, 0.24),
1210
+ inset 0 0 6px rgba(96, 165, 250, 0.16) !important;
1211
+ }
1212
+
1213
+ /* 请求期间控件禁用,将光效降为灰色以表达不可编辑状态。 */
1214
+ .intStyle.is-disabled :deep(.el-input__wrapper) {
1215
+ box-shadow:
1216
+ 0 0 0 1px rgba(148, 163, 184, 0.52),
1217
+ 0 0 4px rgba(148, 163, 184, 0.2);
958
1218
  }
959
1219
 
960
1220
  .intStyle :deep(.el-input__inner) {
961
1221
  width: 100%;
962
1222
  height: 18px;
963
1223
  padding: 0 5px;
964
- border: 1px solid #cbd5e1;
1224
+ border: 0;
965
1225
  border-radius: 4px;
966
1226
  color: #111827;
967
1227
  font-size: 11px;
@@ -973,15 +1233,16 @@ onBeforeUnmount(() => {
973
1233
  }
974
1234
 
975
1235
  .intStyle :deep(.el-input__inner:focus) {
976
- border-color: #2563eb;
977
- box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.12);
1236
+ box-shadow: none;
978
1237
  }
979
1238
 
1239
+ /* 金额默认右对齐,备注作为自然语言单独恢复左对齐和常规字重。 */
980
1240
  .remark-input :deep(.el-input__inner) {
981
1241
  font-weight: 400;
982
1242
  text-align: left;
983
1243
  }
984
1244
 
1245
+ /* 小于表格最小宽度时只滚动报表区域,不压缩金额列。 */
985
1246
  @media screen and (max-width: 1600px) {
986
1247
  #mainDiv {
987
1248
  overflow-x: auto;