verce-vue-test 0.0.77 → 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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verce-vue-test",
3
- "version": "0.0.77",
3
+ "version": "0.0.78",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -7,8 +7,25 @@ import type {
7
7
  RmbPositionHistoryRequestBody,
8
8
  } from './types'
9
9
 
10
+ /**
11
+ * 人民币头寸匡算页面的接口入口。
12
+ *
13
+ * 本文件只描述“调用哪个接口、传入什么业务参数”,不在这里拼装 TAM 公共报文头,
14
+ * 也不负责校验或转换返回字段。`baseHttpClient` 会识别 `/TAM/` 路径,并自动将
15
+ * `params` 包装到 TAM 请求报文的 `body` 中,同时补齐 `appHead` 和 `head`。
16
+ *
17
+ * 两个方法返回的都是未经页面整理的 TAM 原始响应:`{ head, body }`。其中 `head`
18
+ * 是交易状态等公共信息,`body` 是接口业务数据;具体业务字段由页面在使用前校验。
19
+ */
10
20
  const API = {
11
- // 匡算查询
21
+ /**
22
+ * 按交易日期及页面填写数据执行人民币头寸匡算。
23
+ *
24
+ * `params` 中的金额已经由页面从“亿元”换算为协议要求的“元”;这里直接透传,
25
+ * 不再做单位换算。可通过 `options` 传递 fetch 请求选项,例如传入
26
+ * `{ signal: controller.signal }`,在日期切换、重复查询或组件卸载时取消旧请求,
27
+ * 避免较早返回的结果覆盖当前页面数据。
28
+ */
12
29
  queryAPI: (params: RmbPositionEstimationRequestBody, options?: HttpRequestOptions) => {
13
30
  return baseHttpClient.post<TamResponse<Record<string, unknown>>>(
14
31
  '/TAM/0001/140103006',
@@ -16,7 +33,16 @@ const API = {
16
33
  options,
17
34
  )
18
35
  },
19
- // 查询历史填入数据
36
+
37
+ /**
38
+ * 按交易日期查询此前保存的页面填入数据,用于切换日期后的历史回填。
39
+ *
40
+ * 返回 `body` 的金额仍以“元”为单位,页面负责转换为“亿元”后展示。若该日期
41
+ * 没有历史记录,服务端会正常返回成功报文和空对象 `body: {}`;空对象表示
42
+ * “无可回填数据”,不属于接口异常。
43
+ *
44
+ * `options` 与 `queryAPI` 相同,可传入 `AbortSignal` 取消已经失效的历史查询。
45
+ */
20
46
  historyAPI: (params: RmbPositionHistoryRequestBody, options?: HttpRequestOptions) => {
21
47
  return baseHttpClient.post<TamResponse<Record<string, unknown>>>(
22
48
  '/TAM/0001/140103005',
@@ -1,4 +1,13 @@
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
12
  import { Download, Search } from '@element-plus/icons-vue'
4
13
  import { ElMessage } from 'element-plus'
@@ -14,9 +23,13 @@ import {
14
23
  type RmbPositionHistoryResponseBody,
15
24
  } from './types'
16
25
 
26
+ // 页面按“亿元”输入和展示,TAM 接口按“元”传输。
27
+ // 使用 BigInt 进行换算,避免大额资金经过 Number 浮点运算后产生精度误差。
17
28
  const YUAN_PER_YI = 100_000_000n
29
+ // 0.01 亿元 = 1,000,000 元,用于将展示金额四舍五入到两位小数。
18
30
  const YUAN_PER_YI_CENT = 1_000_000n
19
31
 
32
+ /** 页面中允许用户手工录入的金额字段。 */
20
33
  type ManualAmountKey =
21
34
  | 'overAmt'
22
35
  | 'fzAmtIn'
@@ -28,16 +41,21 @@ type ManualAmountKey =
28
41
  | 'ysAmtIn'
29
42
  | 'ysAmtOut'
30
43
 
44
+ /** 与手工金额行配套的备注字段。 */
31
45
  type RemarkKey = 'fzAmtRmk' | 'bepsAmtRmk' | 'othAmtRmk' | 'ysAmtRmk'
46
+ /** 表单内部统一保存字符串,以保留输入状态、千分位和小数点。 */
32
47
  type FormState = { tranDate: string } & Record<ManualAmountKey | RemarkKey, string>
48
+ /** TAM 返回字段的业务前缀,用于按命名规则生成收入、支出和轧差字段。 */
33
49
  type PairPrefix = 'hg' | 'zq' | 'pj' | 'tg' | 'ty' | 'fzh' | 'lc' | 'qt' | 'zj'
34
50
 
51
+ /** 一组收入、支出、轧差结果字段。 */
35
52
  type AmountCells = {
36
53
  income: RmbPositionAmountField
37
54
  expense: RmbPositionAmountField
38
55
  net: RmbPositionAmountField
39
56
  }
40
57
 
58
+ /** 同时包含“报备金额”和“未核销金额”的两行式业务分区。 */
41
59
  type PairSection = {
42
60
  key: PairPrefix
43
61
  label: string
@@ -46,6 +64,7 @@ type PairSection = {
46
64
  unverified: AmountCells
47
65
  }
48
66
 
67
+ /** 可编辑的手工填入行配置。 */
49
68
  type ManualRow = {
50
69
  key: string
51
70
  label: string
@@ -54,18 +73,24 @@ type ManualRow = {
54
73
  remarkKey: RemarkKey
55
74
  }
56
75
 
76
+ /** 只有一行接口结果、没有手工输入项的业务行配置。 */
57
77
  type SingleResultRow = {
58
78
  key: string
59
79
  label: string
60
80
  cells: AmountCells
61
81
  }
62
82
 
83
+ /** 可点击结果单元格对应的原表格位置及后续联查索引。 */
63
84
  type LinkedCell = {
64
85
  id: string
65
86
  index: number
66
87
  field: RmbPositionAmountField
67
88
  }
68
89
 
90
+ /**
91
+ * 校验匡算接口的原始 body,并收敛为页面可安全使用的结构。
92
+ * 匡算结果字段缺失或金额不是合法数字时直接抛错,避免用不完整数据继续汇总。
93
+ */
69
94
  function normalizeEstimationResponseBody(
70
95
  source: Record<string, unknown>,
71
96
  ): RmbPositionEstimationResponseBody {
@@ -87,6 +112,10 @@ function normalizeEstimationResponseBody(
87
112
  return normalized
88
113
  }
89
114
 
115
+ /**
116
+ * 整理历史填入接口的原始 body。
117
+ * 历史接口允许返回空对象,代表所选日期尚未保存数据;存在的金额字段仍需逐项校验。
118
+ */
90
119
  function normalizeHistoryResponseBody(
91
120
  source: Record<string, unknown>,
92
121
  ): RmbPositionHistoryResponseBody {
@@ -108,14 +137,17 @@ function normalizeHistoryResponseBody(
108
137
  return normalized
109
138
  }
110
139
 
140
+ /** 将日期、时间片段补齐为两位。 */
111
141
  function pad(value: number) {
112
142
  return String(value).padStart(2, '0')
113
143
  }
114
144
 
145
+ /** 将 Date 转为 TAM 使用的 YYYYMMDD 紧凑日期。 */
115
146
  function compactDate(date: Date) {
116
147
  return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
117
148
  }
118
149
 
150
+ /** 同时校验格式和真实日历日期,排除 20260231 之类的无效配置。 */
119
151
  function isValidCompactDate(value: string) {
120
152
  if (!/^\d{8}$/.test(value)) return false
121
153
  const year = Number(value.slice(0, 4))
@@ -125,11 +157,16 @@ function isValidCompactDate(value: string) {
125
157
  return compactDate(date) === value
126
158
  }
127
159
 
160
+ /** 优先采用系统工作日配置,未配置或配置无效时回退到本机当天。 */
128
161
  function initialBusinessDate() {
129
162
  const configuredDate = String(import.meta.env.VITE_SYSTEM_WORK_DATE || '').trim()
130
163
  return isValidCompactDate(configuredDate) ? configuredDate : compactDate(new Date())
131
164
  }
132
165
 
166
+ /**
167
+ * 根据 TAM 字段命名约定生成一组结果字段:
168
+ * 例如 hg + Pred => hgPredAmtIn / hgPredAmtOut / hgPredAmtNet。
169
+ */
133
170
  function createAmountCells(prefix: PairPrefix, type: 'Pred' | 'Unverify'): AmountCells {
134
171
  return {
135
172
  income: `${prefix}${type}AmtIn` as RmbPositionAmountField,
@@ -138,6 +175,7 @@ function createAmountCells(prefix: PairPrefix, type: 'Pred' | 'Unverify'): Amoun
138
175
  }
139
176
  }
140
177
 
178
+ /** 创建模板可直接循环渲染的两行式业务分区配置。 */
141
179
  function createPairSection(
142
180
  key: PairPrefix,
143
181
  shortLabel: string,
@@ -152,6 +190,7 @@ function createPairSection(
152
190
  }
153
191
  }
154
192
 
193
+ // 主表上半部分的八类两行式业务分区,顺序必须与后端字段及原业务表格保持一致。
155
194
  const pairSections: PairSection[] = [
156
195
  createPairSection('hg', '回购', '回购(拆借)到期,CD发行、投资及到期'),
157
196
  createPairSection('zq', '债券', '债券承销'),
@@ -163,8 +202,10 @@ const pairSections: PairSection[] = [
163
202
  createPairSection('qt', '其他', '其他'),
164
203
  ]
165
204
 
205
+ // 表格底部的“资金”分区结构相同,但参与预计余额的位置不同,因此单独配置。
166
206
  const fundSection = createPairSection('zj', '资金', '今日资金交易新业务收付合计')
167
207
 
208
+ // 三类由用户手工填入收入、支出及备注的业务行。
168
209
  const manualRows: ManualRow[] = [
169
210
  {
170
211
  key: 'reserve',
@@ -189,6 +230,7 @@ const manualRows: ManualRow[] = [
189
230
  },
190
231
  ]
191
232
 
233
+ // 直接展示接口结果的三类单行数据,不包含可编辑金额。
192
234
  const singleResultRows: SingleResultRow[] = [
193
235
  {
194
236
  key: 'cash-message',
@@ -207,12 +249,14 @@ const singleResultRows: SingleResultRow[] = [
207
249
  },
208
250
  ]
209
251
 
252
+ // 建立“接口字段 -> 原表格坐标”的映射,为结果数字点击后的明细联查预留参数。
210
253
  const linkedCellMap = new Map<RmbPositionAmountField, LinkedCell>()
211
254
 
212
255
  function registerLinkedCell(field: RmbPositionAmountField, id: string, index: number) {
213
256
  linkedCellMap.set(field, { id, index, field })
214
257
  }
215
258
 
259
+ // 两行式分区每类注册四个可联查单元格:报备收入/支出、未核销收入/支出。
216
260
  pairSections.forEach((section, sectionIndex) => {
217
261
  const predictionRow = 5 + sectionIndex * 2
218
262
  const unverifiedRow = predictionRow + 1
@@ -224,6 +268,7 @@ pairSections.forEach((section, sectionIndex) => {
224
268
  registerLinkedCell(section.unverified.expense, `D${unverifiedRow}`, startIndex + 3)
225
269
  })
226
270
 
271
+ // 单行结果只为收入和支出注册联查,轧差由前两项计算或由接口直接展示。
227
272
  singleResultRows.forEach((row, rowIndex) => {
228
273
  const tableRow = 24 + rowIndex
229
274
  const startIndex = 32 + rowIndex * 2
@@ -237,6 +282,7 @@ registerLinkedCell(fundSection.prediction.expense, 'D31', 39)
237
282
  registerLinkedCell(fundSection.unverified.income, 'C32', 40)
238
283
  registerLinkedCell(fundSection.unverified.expense, 'D32', 41)
239
284
 
285
+ // 小计只汇总“报备金额”以及三类单行结果;未核销金额和底部资金分区不计入此处。
240
286
  const predictionIncomeFields = pairSections.map((section) => section.prediction.income)
241
287
  const predictionExpenseFields = pairSections.map((section) => section.prediction.expense)
242
288
  const subtotalResultIncomeFields: RmbPositionAmountField[] = [
@@ -252,6 +298,7 @@ const subtotalResultExpenseFields: RmbPositionAmountField[] = [
252
298
  'unVerifyAmtOut',
253
299
  ]
254
300
 
301
+ // 集中维护金额和备注键,供重置、校验、历史回填等公共流程复用。
255
302
  const manualAmountKeys: ManualAmountKey[] = [
256
303
  'overAmt',
257
304
  'fzAmtIn',
@@ -266,6 +313,7 @@ const manualAmountKeys: ManualAmountKey[] = [
266
313
 
267
314
  const remarkKeys: RemarkKey[] = ['fzAmtRmk', 'bepsAmtRmk', 'othAmtRmk', 'ysAmtRmk']
268
315
 
316
+ // 校验提示使用的中文名称,避免向用户暴露协议字段名。
269
317
  const amountFieldLabels: Record<ManualAmountKey, string> = {
270
318
  overAmt: '昨日超额备付余额',
271
319
  fzAmtIn: '法定准备金等收入',
@@ -278,6 +326,7 @@ const amountFieldLabels: Record<ManualAmountKey, string> = {
278
326
  ysAmtOut: '今日资金交易预计支出',
279
327
  }
280
328
 
329
+ // 以下每组收入、支出至少填写一项;另一项留空时按 0 处理。
281
330
  const requiredPairs: Array<[ManualAmountKey, ManualAmountKey]> = [
282
331
  ['fzAmtIn', 'fzAmtOut'],
283
332
  ['bepsAmtIn', 'bepsAmtOut'],
@@ -285,6 +334,7 @@ const requiredPairs: Array<[ManualAmountKey, ManualAmountKey]> = [
285
334
  ['ysAmtIn', 'ysAmtOut'],
286
335
  ]
287
336
 
337
+ // 表单金额始终保留为字符串:失焦时可包含千分位,聚焦时移除千分位便于编辑。
288
338
  const form = reactive<FormState>({
289
339
  tranDate: initialBusinessDate(),
290
340
  overAmt: '',
@@ -302,15 +352,22 @@ const form = reactive<FormState>({
302
352
  ysAmtRmk: '',
303
353
  })
304
354
 
355
+ // result 为 null 表示尚未完成匡算,此时计算结果区域显示为空而不是 0。
305
356
  const result = ref<RmbPositionEstimationResponseBody | null>(null)
306
357
  const loading = ref(false)
307
358
  const loadingText = ref('正在进行头寸匡算…')
359
+ // 日期历史查询和匡算查询共用控制器;新请求启动前会取消旧请求,防止旧响应覆盖新状态。
308
360
  let requestController: AbortController | null = null
309
361
 
362
+ /** 移除展示态千分位,得到可参与校验和换算的普通数字文本。 */
310
363
  function stripGrouping(value: string) {
311
364
  return value.trim().replaceAll(',', '')
312
365
  }
313
366
 
367
+ /**
368
+ * 校验以“亿元”为单位的用户输入。
369
+ * 最多允许 8 位小数,因为 0.00000001 亿元恰好等于 1 元,再多位数无法精确映射到人民币元。
370
+ */
314
371
  function isValidYiAmount(value: string) {
315
372
  const original = value.trim()
316
373
  if (!/^-?(?:(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d*)?|\.\d+)$/.test(original)) return false
@@ -319,6 +376,10 @@ function isValidYiAmount(value: string) {
319
376
  return decimalLength <= 8
320
377
  }
321
378
 
379
+ /**
380
+ * 将“亿元”字符串精确转换为“元”BigInt。
381
+ * 通过拆分整数和小数完成换算,不使用 parseFloat,确保大额及小数金额不丢精度。
382
+ */
322
383
  function yiTextToYuan(value: string) {
323
384
  const normalized = stripGrouping(value)
324
385
  if (!normalized) return 0n
@@ -332,6 +393,10 @@ function yiTextToYuan(value: string) {
332
393
  return negative ? -yuan : yuan
333
394
  }
334
395
 
396
+ /**
397
+ * 将接口返回的“元”文本转为 BigInt。
398
+ * 若后端意外返回元以下小数,则按第一位小数执行四舍五入,保证后续只在整数元上计算。
399
+ */
335
400
  function yuanTextToBigInt(value: unknown) {
336
401
  const normalized = String(value ?? '0').trim().replaceAll(',', '')
337
402
  if (/^-?\d+$/.test(normalized)) return BigInt(normalized)
@@ -346,10 +411,12 @@ function yuanTextToBigInt(value: unknown) {
346
411
  return match[1] === '-' ? -roundedAbsolute : roundedAbsolute
347
412
  }
348
413
 
414
+ /** 为整数部分增加千分位分隔符。 */
349
415
  function groupInteger(value: string) {
350
416
  return value.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
351
417
  }
352
418
 
419
+ /** 对正负 BigInt 执行传统的四舍五入除法。 */
353
420
  function divideAndRoundHalfUp(value: bigint, divisor: bigint) {
354
421
  const negative = value < 0n
355
422
  const absolute = negative ? -value : value
@@ -358,10 +425,12 @@ function divideAndRoundHalfUp(value: bigint, divisor: bigint) {
358
425
  return negative ? -rounded : rounded
359
426
  }
360
427
 
428
+ /** 将元金额四舍五入到 0.01 亿元对应的整数元刻度。 */
361
429
  function roundYuanToYiCent(value: bigint) {
362
430
  return divideAndRoundHalfUp(value, YUAN_PER_YI_CENT) * YUAN_PER_YI_CENT
363
431
  }
364
432
 
433
+ /** 将接口单位“元”格式化为页面单位“亿元”,固定两位小数并带千分位。 */
365
434
  function formatYuanAsYi(value: bigint | string) {
366
435
  const yuan = typeof value === 'bigint' ? value : yuanTextToBigInt(value)
367
436
  const roundedYuan = roundYuanToYiCent(yuan)
@@ -375,6 +444,7 @@ function formatYuanAsYi(value: bigint | string) {
375
444
  return `${sign}${groupInteger(String(integerPart))}.${String(decimalPart).padStart(2, '0')}`
376
445
  }
377
446
 
447
+ /** 获取单个接口结果的展示文本;接口已返回空值时按 0.00 展示。 */
378
448
  function displayResultValue(field: RmbPositionAmountField) {
379
449
  if (!result.value) return ''
380
450
 
@@ -384,16 +454,19 @@ function displayResultValue(field: RmbPositionAmountField) {
384
454
  return formatYuanAsYi(value)
385
455
  }
386
456
 
457
+ /** 手工行轧差 = 收入 - 支出,仅在已有匡算结果时显示。 */
387
458
  function displayManualNet(incomeKey: ManualAmountKey, expenseKey: ManualAmountKey) {
388
459
  if (!result.value) return ''
389
460
  return formatYuanAsYi(yiTextToYuan(form[incomeKey]) - yiTextToYuan(form[expenseKey]))
390
461
  }
391
462
 
463
+ /** 按字段列表汇总接口返回值,内部始终使用“元”BigInt。 */
392
464
  function sumResultFields(fields: RmbPositionAmountField[]) {
393
465
  if (!result.value) return 0n
394
466
  return fields.reduce((sum, field) => sum + yuanTextToBigInt(result.value?.[field]), 0n)
395
467
  }
396
468
 
469
+ // 收入小计 = 接口报备类收入 + 现金/未核销单行收入 + 三类手工收入。
397
470
  const subtotalIncomeYuan = computed<bigint | null>(() => {
398
471
  if (!result.value) return null
399
472
  return sumResultFields(subtotalResultIncomeFields)
@@ -402,6 +475,7 @@ const subtotalIncomeYuan = computed<bigint | null>(() => {
402
475
  + yiTextToYuan(form.othAmtIn)
403
476
  })
404
477
 
478
+ // 支出小计与收入小计采用完全对称的字段范围。
405
479
  const subtotalExpenseYuan = computed<bigint | null>(() => {
406
480
  if (!result.value) return null
407
481
  return sumResultFields(subtotalResultExpenseFields)
@@ -410,39 +484,47 @@ const subtotalExpenseYuan = computed<bigint | null>(() => {
410
484
  + yiTextToYuan(form.othAmtOut)
411
485
  })
412
486
 
487
+ // 小计轧差 = 收入小计 - 支出小计。
413
488
  const subtotalNetYuan = computed<bigint | null>(() => {
414
489
  if (subtotalIncomeYuan.value === null || subtotalExpenseYuan.value === null) return null
415
490
  return subtotalIncomeYuan.value - subtotalExpenseYuan.value
416
491
  })
417
492
 
493
+ // 日初可用资金 = 昨日超额备付余额 + 当前小计轧差。
418
494
  const openingAvailableYuan = computed<bigint | null>(() => {
419
495
  if (subtotalNetYuan.value === null) return null
420
496
  return yiTextToYuan(form.overAmt) + subtotalNetYuan.value
421
497
  })
422
498
 
499
+ // 今日预计余额 = 日初可用资金 + 今日资金交易预计收入 - 今日资金交易预计支出。
423
500
  const estimatedBalanceYuan = computed<bigint | null>(() => {
424
501
  if (openingAvailableYuan.value === null) return null
425
502
  return openingAvailableYuan.value + yiTextToYuan(form.ysAmtIn) - yiTextToYuan(form.ysAmtOut)
426
503
  })
427
504
 
505
+ /** 汇总结果尚不可计算时返回空文本,否则统一格式化。 */
428
506
  function displaySummary(value: bigint | null) {
429
507
  return value === null ? '' : formatYuanAsYi(value)
430
508
  }
431
509
 
510
+ /** 任一输入发生变化后清空旧匡算结果,避免页面展示与当前参数不一致的数据。 */
432
511
  function clearResult() {
433
512
  result.value = null
434
513
  }
435
514
 
515
+ /** 金额失焦时执行四舍五入,固定两位小数并添加千分位。 */
436
516
  function normalizeAmountField(key: ManualAmountKey) {
437
517
  const original = form[key]
438
518
  if (!isValidYiAmount(original)) return
439
519
  form[key] = formatYuanAsYi(yiTextToYuan(original))
440
520
  }
441
521
 
522
+ /** 金额获得焦点时去除千分位,恢复便于继续编辑的普通数字。 */
442
523
  function activateAmountField(key: ManualAmountKey) {
443
524
  form[key] = stripGrouping(form[key])
444
525
  }
445
526
 
527
+ /** 切换交易日期前清空上一日期的手工金额和备注。 */
446
528
  function resetManualInputs() {
447
529
  manualAmountKeys.forEach((key) => {
448
530
  form[key] = ''
@@ -452,6 +534,10 @@ function resetManualInputs() {
452
534
  })
453
535
  }
454
536
 
537
+ /**
538
+ * 将历史接口返回的“元”金额回填为页面使用的“亿元”展示文本。
539
+ * body 为空或某字段不存在时保持空输入,备注不做数值转换。
540
+ */
455
541
  function fillHistoryInputs(history: RmbPositionHistoryResponseBody) {
456
542
  manualAmountKeys.forEach((key) => {
457
543
  const value = history[key]
@@ -464,6 +550,10 @@ function fillHistoryInputs(history: RmbPositionHistoryResponseBody) {
464
550
  })
465
551
  }
466
552
 
553
+ /**
554
+ * 日期切换后查询历史填入数据。
555
+ * 每次切换都会先取消前一请求;只有当前控制器对应的响应才允许回填和结束 loading。
556
+ */
467
557
  async function handleDateChange() {
468
558
  requestController?.abort()
469
559
  resetManualInputs()
@@ -498,6 +588,9 @@ async function handleDateChange() {
498
588
  }
499
589
  }
500
590
 
591
+ /**
592
+ * 结果数字点击入口。目前仅打印联查参数;后续接入明细页时可在此统一跳转或打开弹窗。
593
+ */
501
594
  function openLink(field: RmbPositionAmountField) {
502
595
  const cell = linkedCellMap.get(field)
503
596
  if (!cell) return
@@ -508,6 +601,10 @@ function openLink(field: RmbPositionAmountField) {
508
601
  })
509
602
  }
510
603
 
604
+ /**
605
+ * 将页面的“亿元”输入转换为接口的“元”金额。
606
+ * 接口历史约定零值使用字符串 '0',非零值使用安全整数 Number。
607
+ */
511
608
  function toProtocolAmount(key: ManualAmountKey): ProtocolAmount {
512
609
  const yuan = yiTextToYuan(form[key])
513
610
  if (yuan === 0n) return '0'
@@ -519,6 +616,10 @@ function toProtocolAmount(key: ManualAmountKey): ProtocolAmount {
519
616
  return amount
520
617
  }
521
618
 
619
+ /**
620
+ * 查询和导出共用的提交前校验:日期、必填项、成对金额、格式和安全整数范围。
621
+ * 该函数只负责提示并返回布尔值,不修改表单数据。
622
+ */
522
623
  function validateForm() {
523
624
  if (!form.tranDate) {
524
625
  ElMessage.warning('请选择交易日期')
@@ -555,6 +656,7 @@ function validateForm() {
555
656
  return true
556
657
  }
557
658
 
659
+ // 查询和导出共享同一份计算参数;只有真正触发操作时才读取 value 并完成单位换算。
558
660
  const queryParams = computed<RmbPositionEstimationRequestBody>(() => (
559
661
  {
560
662
  overAmt: toProtocolAmount('overAmt'),
@@ -574,6 +676,7 @@ const queryParams = computed<RmbPositionEstimationRequestBody>(() => (
574
676
  }
575
677
  ))
576
678
 
679
+ /** 导出功能暂未接入接口,仅在查询参数基础上追加操作类型并打印。 */
577
680
  function exportEstimation() {
578
681
  if (!validateForm()) return
579
682
 
@@ -583,10 +686,12 @@ function exportEstimation() {
583
686
  })
584
687
  }
585
688
 
689
+ /** 主动取消请求属于正常交互,不向用户显示错误消息。 */
586
690
  function isAbortError(error: unknown) {
587
691
  return error instanceof DOMException && error.name === 'AbortError'
588
692
  }
589
693
 
694
+ /** 执行头寸匡算,并将经过完整性校验的接口结果写入页面状态。 */
590
695
  async function queryEstimation() {
591
696
  if (!validateForm()) return
592
697
 
@@ -615,6 +720,7 @@ async function queryEstimation() {
615
720
  }
616
721
  }
617
722
 
723
+ // 离开页面时终止未完成请求,避免卸载后的组件继续更新状态。
618
724
  onBeforeUnmount(() => {
619
725
  requestController?.abort()
620
726
  })
@@ -622,6 +728,7 @@ onBeforeUnmount(() => {
622
728
 
623
729
  <template>
624
730
  <div class="rmb-position-estimation-page">
731
+ <!-- 顶部操作区:日期切换负责历史回填,查询和导出共享下方计算参数。 -->
625
732
  <div class="query-section">
626
733
  <el-form
627
734
  :model="form"
@@ -662,6 +769,7 @@ onBeforeUnmount(() => {
662
769
  </el-form>
663
770
  </div>
664
771
 
772
+ <!-- 主表加载遮罩同时覆盖历史查询和匡算查询,提示文字由当前操作动态切换。 -->
665
773
  <div
666
774
  id="mainDiv"
667
775
  v-loading="loading"
@@ -677,6 +785,7 @@ onBeforeUnmount(() => {
677
785
  <col class="col-remark" />
678
786
  </colgroup>
679
787
  <tbody>
788
+ <!-- 表头第一行同时承载昨日余额输入、金额单位和备注跨行标题。 -->
680
789
  <tr class="head-row">
681
790
  <td colspan="2">昨日超额备付余额</td>
682
791
  <td>
@@ -703,6 +812,7 @@ onBeforeUnmount(() => {
703
812
  <td>轧差</td>
704
813
  </tr>
705
814
 
815
+ <!-- 八类业务均按“报备金额 + 未核销金额”两行渲染。蓝色金额可触发明细联查。 -->
706
816
  <template v-for="section in pairSections" :key="section.key">
707
817
  <tr>
708
818
  <td rowspan="2" class="section-name">{{ section.label }}</td>
@@ -741,6 +851,7 @@ onBeforeUnmount(() => {
741
851
  </tr>
742
852
  </template>
743
853
 
854
+ <!-- 手工填入区:收入和支出以亿元录入,轧差由页面实时计算,备注保留原始文本。 -->
744
855
  <tr v-for="row in manualRows" :key="row.key">
745
856
  <td colspan="2">{{ row.label }}</td>
746
857
  <td>
@@ -783,6 +894,7 @@ onBeforeUnmount(() => {
783
894
  </td>
784
895
  </tr>
785
896
 
897
+ <!-- 现金报文及两档未核销流水完全来自匡算接口,不允许手工修改。 -->
786
898
  <tr v-for="row in singleResultRows" :key="row.key">
787
899
  <td colspan="2">{{ row.label }}</td>
788
900
  <td align="right" class="money-cell even">
@@ -801,6 +913,7 @@ onBeforeUnmount(() => {
801
913
  <td class="even"></td>
802
914
  </tr>
803
915
 
916
+ <!-- 第一阶段汇总:小计以及在昨日余额基础上计算出的日初可用资金。 -->
804
917
  <tr class="summary-row">
805
918
  <td colspan="2" class="red">小计</td>
806
919
  <td align="right" class="money-cell strong-value">
@@ -825,6 +938,7 @@ onBeforeUnmount(() => {
825
938
  <td colspan="6"></td>
826
939
  </tr>
827
940
 
941
+ <!-- 第二阶段手工输入:当天资金交易的预计收入、支出和备注。 -->
828
942
  <tr>
829
943
  <td colspan="2" class="red">今日资金交易预计收付额</td>
830
944
  <td>
@@ -867,6 +981,7 @@ onBeforeUnmount(() => {
867
981
  </td>
868
982
  </tr>
869
983
 
984
+ <!-- 资金新业务仍按报备/未核销两行展示,最终汇入今日预计余额。 -->
870
985
  <tr>
871
986
  <td rowspan="2" class="section-name">{{ fundSection.label }}</td>
872
987
  <td>报备金额</td>
@@ -902,6 +1017,7 @@ onBeforeUnmount(() => {
902
1017
  </td>
903
1018
  <td></td>
904
1019
  </tr>
1020
+ <!-- 最终结果 = 日初可用资金 + 今日资金交易预计收付轧差。 -->
905
1021
  <tr class="total-row">
906
1022
  <td colspan="2" class="bold red">今日超额备付金预计余额</td>
907
1023
  <td colspan="3" class="bold red">
@@ -916,6 +1032,7 @@ onBeforeUnmount(() => {
916
1032
  </template>
917
1033
 
918
1034
  <style scoped>
1035
+ /* 页面保持紧凑的业务报表形态,外层卡片负责与应用背景分离。 */
919
1036
  .rmb-position-estimation-page {
920
1037
  width: calc(100% - 20px);
921
1038
  margin: 10px;
@@ -926,6 +1043,7 @@ onBeforeUnmount(() => {
926
1043
  box-sizing: border-box;
927
1044
  }
928
1045
 
1046
+ /* 表格高度超过可视区域时在容器内部滚动,避免整页操作栏被卷走。 */
929
1047
  #mainDiv {
930
1048
  width: 100%;
931
1049
  max-height: 760px;
@@ -935,6 +1053,7 @@ onBeforeUnmount(() => {
935
1053
  box-sizing: border-box;
936
1054
  }
937
1055
 
1056
+ /* 固定列宽保证复杂表头和金额列始终对齐;窄屏通过横向滚动完整查看。 */
938
1057
  .tab {
939
1058
  width: 100%;
940
1059
  min-width: 1180px;
@@ -1007,6 +1126,7 @@ onBeforeUnmount(() => {
1007
1126
  background: #f1f5f9;
1008
1127
  }
1009
1128
 
1129
+ /* 蓝色结果表示该金额可以点击联查,与普通不可点击的轧差值形成区分。 */
1010
1130
  .result-value {
1011
1131
  display: inline-block;
1012
1132
  min-width: 44px;
@@ -1027,6 +1147,7 @@ onBeforeUnmount(() => {
1027
1147
  font-weight: 700;
1028
1148
  }
1029
1149
 
1150
+ /* 小计和关键余额采用暖色背景,强调其业务优先级。 */
1030
1151
  .red {
1031
1152
  color: #dc2626;
1032
1153
  background: #fff7ed !important;
@@ -1052,10 +1173,12 @@ onBeforeUnmount(() => {
1052
1173
  background: #fff;
1053
1174
  }
1054
1175
 
1176
+ /* 表格内输入框统一铺满单元格,以下样式仅作用于金额及备注编辑控件。 */
1055
1177
  .intStyle {
1056
1178
  width: 100%;
1057
1179
  }
1058
1180
 
1181
+ /* 常态保留蓝青色发光边框,让可编辑单元格在密集报表中易于识别。 */
1059
1182
  .intStyle :deep(.el-input__wrapper) {
1060
1183
  height: 18px;
1061
1184
  min-height: 18px;
@@ -1069,6 +1192,7 @@ onBeforeUnmount(() => {
1069
1192
  transition: box-shadow 180ms ease, background-color 180ms ease;
1070
1193
  }
1071
1194
 
1195
+ /* 悬停增强光晕,反馈当前可交互区域。 */
1072
1196
  .intStyle :deep(.el-input__wrapper:hover) {
1073
1197
  box-shadow:
1074
1198
  0 0 0 1px #38bdf8,
@@ -1076,6 +1200,7 @@ onBeforeUnmount(() => {
1076
1200
  inset 0 0 6px rgba(125, 211, 252, 0.18) !important;
1077
1201
  }
1078
1202
 
1203
+ /* 聚焦态使用更强的双层光晕,同时略微提亮输入背景。 */
1079
1204
  .intStyle :deep(.el-input__wrapper.is-focus) {
1080
1205
  background: #fafdff;
1081
1206
  box-shadow:
@@ -1085,6 +1210,7 @@ onBeforeUnmount(() => {
1085
1210
  inset 0 0 6px rgba(96, 165, 250, 0.16) !important;
1086
1211
  }
1087
1212
 
1213
+ /* 请求期间控件禁用,将光效降为灰色以表达不可编辑状态。 */
1088
1214
  .intStyle.is-disabled :deep(.el-input__wrapper) {
1089
1215
  box-shadow:
1090
1216
  0 0 0 1px rgba(148, 163, 184, 0.52),
@@ -1110,11 +1236,13 @@ onBeforeUnmount(() => {
1110
1236
  box-shadow: none;
1111
1237
  }
1112
1238
 
1239
+ /* 金额默认右对齐,备注作为自然语言单独恢复左对齐和常规字重。 */
1113
1240
  .remark-input :deep(.el-input__inner) {
1114
1241
  font-weight: 400;
1115
1242
  text-align: left;
1116
1243
  }
1117
1244
 
1245
+ /* 小于表格最小宽度时只滚动报表区域,不压缩金额列。 */
1118
1246
  @media screen and (max-width: 1600px) {
1119
1247
  #mainDiv {
1120
1248
  overflow-x: auto;
@@ -1,3 +1,18 @@
1
+ /**
2
+ * 匡算接口业务响应中必须返回的全部金额字段。
3
+ *
4
+ * 大部分字段遵循“业务前缀 + 数据阶段 + 金额方向”的命名规则:
5
+ *
6
+ * - 业务前缀:`hg` 回购、`zq` 债券、`pj` 票据、`tg` 托管、`ty` 同业、
7
+ * `fzh` 支行、`lc` 理财、`qt` 其他、`zj` 今日资金交易;
8
+ * - 数据阶段:`Pred` 表示报备/预计金额,`Unverify` 表示未核销金额;
9
+ * - 金额方向:`AmtIn` 收入、`AmtOut` 支出、`AmtNet` 净额。
10
+ *
11
+ * `xjAmt*`、`unVerifyAmt*1` 和 `unVerifyAmt*` 是 TAM 协议中的既有字段名,
12
+ * 分别对应 606 报文、1 亿以下及 1 亿及以上的未核销流水。数组使用 `as const`
13
+ * 固定字面量,既供页面批量校验/渲染,也作为 `RmbPositionAmountField` 的类型来源;
14
+ * 新增响应字段时应同步确认页面表格是否需要展示和参与汇总。
15
+ */
1
16
  export const rmbPositionAmountFields = [
2
17
  'hgPredAmtIn',
3
18
  'hgPredAmtOut',
@@ -64,9 +79,27 @@ export const rmbPositionAmountFields = [
64
79
  'zjUnverifyAmtNet',
65
80
  ] as const
66
81
 
82
+ /** 匡算结果金额字段名的联合类型,确保页面只能访问协议中已登记的金额字段。 */
67
83
  export type RmbPositionAmountField = typeof rmbPositionAmountFields[number]
84
+
85
+ /**
86
+ * 发送给 TAM 的金额类型。
87
+ *
88
+ * 页面输入和展示使用“亿元”,提交前会换算成整数“元”。当前协议约定零值传字符串
89
+ * `'0'`,非零金额传安全整数 `number`,因此这里保留二者的联合类型,不应改成页面
90
+ * 输入框使用的格式化字符串(例如带千分位的 `"1,234.00"`)。
91
+ */
68
92
  export type ProtocolAmount = number | '0'
69
93
 
94
+ /**
95
+ * `/TAM/0001/140103006` 匡算查询的业务请求体。
96
+ *
97
+ * `tranDate` 使用 `yyyyMMdd`;所有 `*Amt*` 字段均为“元”,所有 `*Rmk` 字段均为
98
+ * 对应收付项目的备注。字段前缀含义:`over` 昨日超额备付余额、`fz` 法定准备金
99
+ * 退/缴款及其他来走款、`beps` 小额来走款、`oth` 其他来走款、`ys` 今日资金
100
+ * 交易预计收付额。该对象只包含 TAM 业务 `body`,公共 `appHead/head` 由全局
101
+ * `baseHttpClient` 自动生成。
102
+ */
70
103
  export type RmbPositionEstimationRequestBody = {
71
104
  overAmt: ProtocolAmount
72
105
  tranDate: string
@@ -84,10 +117,21 @@ export type RmbPositionEstimationRequestBody = {
84
117
  ysAmtRmk: string
85
118
  }
86
119
 
120
+ /**
121
+ * `/TAM/0001/140103006` 成功响应的业务 `body`。
122
+ *
123
+ * TAM 返回的金额按“元”编码为字符串,以避免大额金额在传输阶段丢失精度;页面会
124
+ * 校验这些字段并转换为“亿元”格式展示。`fileName` 是协议预留的文件名字段,其余
125
+ * 金额字段由 `rmbPositionAmountFields` 统一约束。
126
+ */
87
127
  export type RmbPositionEstimationResponseBody = {
88
128
  fileName: string
89
129
  } & Record<RmbPositionAmountField, string>
90
130
 
131
+ /**
132
+ * 历史查询可能返回的金额字段,与匡算请求中可人工填写的金额项一一对应。
133
+ * 返回值仍以“元”为单位,页面回填输入框前再换算为“亿元”。
134
+ */
91
135
  export const rmbPositionHistoryAmountFields = [
92
136
  'overAmt',
93
137
  'fzAmtIn',
@@ -100,6 +144,9 @@ export const rmbPositionHistoryAmountFields = [
100
144
  'ysAmtOut',
101
145
  ] as const
102
146
 
147
+ /**
148
+ * 历史查询可能返回的备注字段;字段前缀与对应金额项保持一致,`Rmk` 表示备注。
149
+ */
103
150
  export const rmbPositionHistoryRemarkFields = [
104
151
  'fzAmtRmk',
105
152
  'bepsAmtRmk',
@@ -110,10 +157,22 @@ export const rmbPositionHistoryRemarkFields = [
110
157
  type RmbPositionHistoryAmountField = typeof rmbPositionHistoryAmountFields[number]
111
158
  type RmbPositionHistoryRemarkField = typeof rmbPositionHistoryRemarkFields[number]
112
159
 
160
+ /**
161
+ * `/TAM/0001/140103005` 历史填入数据查询的业务请求体。
162
+ * `tranDate` 为待回填日期,格式为 `yyyyMMdd`。
163
+ */
113
164
  export type RmbPositionHistoryRequestBody = {
114
165
  tranDate: string
115
166
  }
116
167
 
168
+ /**
169
+ * `/TAM/0001/140103005` 成功响应的业务 `body`。
170
+ *
171
+ * 历史字段使用 `Partial`,因为服务端允许仅返回已保存的字段;当指定日期没有保存
172
+ * 记录时,会返回 `body: {}`。这表示查询成功但没有历史数据,页面应清空/保持空白
173
+ * 输入项,而不是将其视为报错。存在的金额字段以“元”的数字字符串返回,备注字段
174
+ * 为普通字符串。
175
+ */
117
176
  export type RmbPositionHistoryResponseBody = Partial<Record<
118
177
  RmbPositionHistoryAmountField | RmbPositionHistoryRemarkField,
119
178
  string