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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verce-vue-test",
3
- "version": "0.0.76",
3
+ "version": "0.0.78",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -88,7 +88,7 @@ const router = createRouter({
88
88
  {
89
89
  path: '/rmb-position-estimation',
90
90
  name: 'rmbPositionEstimation',
91
- component: () => import('../views/RmbPositionEstimationView.vue'),
91
+ component: () => import('../views/rmb-position-estimation/index.vue'),
92
92
  },
93
93
  {
94
94
  path: '/executive-management',
@@ -0,0 +1,159 @@
1
+ const apiBaseUrl = String(
2
+ import.meta.env.VITE_API_BASE_URL || 'http://localhost:3011/oms',
3
+ ).replace(/\/+$/, '')
4
+
5
+ const tamBranchId = String(import.meta.env.VITE_TAM_BRANCH_ID || 'HQ001')
6
+ const tamUserId = String(import.meta.env.VITE_TAM_USER_ID || 'HQ00601')
7
+ const tamClientIp = String(import.meta.env.VITE_TAM_CLIENT_IP || '')
8
+
9
+ export type HttpRequestOptions = Omit<RequestInit, 'body' | 'method'>
10
+
11
+ export type TamResponse<T> = {
12
+ head: {
13
+ retStatus?: string
14
+ retCode?: string
15
+ retMsg?: string
16
+ [key: string]: unknown
17
+ }
18
+ body: T
19
+ }
20
+
21
+ type ErrorResponse = {
22
+ error?: {
23
+ message?: string
24
+ }
25
+ head?: {
26
+ retMsg?: string
27
+ }
28
+ }
29
+
30
+ function pad(value: number) {
31
+ return String(value).padStart(2, '0')
32
+ }
33
+
34
+ function compactDate(date: Date) {
35
+ return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
36
+ }
37
+
38
+ function compactTime(date: Date) {
39
+ return `${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
40
+ }
41
+
42
+ function createConsumerSeqNo(date: Date) {
43
+ return `${tamUserId}${compactDate(date)}${compactTime(date)}${String(date.getMilliseconds()).padStart(3, '0')}`
44
+ }
45
+
46
+ function isTamPath(path: string) {
47
+ return path.startsWith('/TAM/')
48
+ }
49
+
50
+ function createTamRequest(path: string, body: unknown) {
51
+ const now = new Date()
52
+
53
+ return {
54
+ appHead: {
55
+ fileName: '',
56
+ opType: '',
57
+ ip: tamClientIp,
58
+ },
59
+ head: {
60
+ branchId: tamBranchId,
61
+ consumerSeqNo: createConsumerSeqNo(now),
62
+ consumerId: 'TAM001',
63
+ tranCode: path,
64
+ tranDate: compactDate(now),
65
+ tranTimestamp: compactTime(now),
66
+ pageSize: '10',
67
+ pageIndex: '1',
68
+ traceId: '',
69
+ spanId: '',
70
+ userId: tamUserId,
71
+ versionId: '0001',
72
+ verifyUserId: '',
73
+ adminUserId: '',
74
+ apprUserId: '',
75
+ areaCode: '0000',
76
+ digitalSign: '',
77
+ fileFlag: 'N',
78
+ filePath: '',
79
+ isBatch: false,
80
+ },
81
+ body,
82
+ }
83
+ }
84
+
85
+ function resolveUrl(path: string) {
86
+ return /^https?:\/\//i.test(path) ? path : `${apiBaseUrl}${path}`
87
+ }
88
+
89
+ function getErrorMessage(payload: unknown, fallback: string) {
90
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) return fallback
91
+ const response = payload as ErrorResponse
92
+ return response.head?.retMsg || response.error?.message || fallback
93
+ }
94
+
95
+ async function request<T>(
96
+ method: string,
97
+ path: string,
98
+ data?: unknown,
99
+ options: HttpRequestOptions = {},
100
+ ): Promise<T> {
101
+ const tamRequest = isTamPath(path)
102
+ const response = await fetch(resolveUrl(path), {
103
+ ...options,
104
+ method,
105
+ headers: {
106
+ 'Content-Type': 'application/json',
107
+ ...options.headers,
108
+ },
109
+ body: data === undefined
110
+ ? undefined
111
+ : JSON.stringify(tamRequest ? createTamRequest(path, data) : data),
112
+ })
113
+
114
+ let payload: unknown
115
+ try {
116
+ payload = await response.json()
117
+ } catch {
118
+ throw new Error(`接口返回的不是有效 JSON(HTTP ${response.status})`)
119
+ }
120
+
121
+ if (!response.ok) {
122
+ throw new Error(getErrorMessage(payload, `请求失败(HTTP ${response.status})`))
123
+ }
124
+
125
+ if (tamRequest) {
126
+ if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
127
+ throw new Error('TAM 接口返回结构不正确')
128
+ }
129
+ const tamResponse = payload as TamResponse<unknown>
130
+ if (tamResponse.head?.retStatus !== 'S' || tamResponse.head?.retCode !== '00000') {
131
+ throw new Error(tamResponse.head?.retMsg || 'TAM 交易失败')
132
+ }
133
+ if (!tamResponse.body || typeof tamResponse.body !== 'object' || Array.isArray(tamResponse.body)) {
134
+ throw new Error('TAM 接口返回结构不正确')
135
+ }
136
+ }
137
+
138
+ return payload as T
139
+ }
140
+
141
+ const baseHttpClient = {
142
+ get<T>(path: string, options?: HttpRequestOptions) {
143
+ return request<T>('GET', path, undefined, options)
144
+ },
145
+ post<T>(path: string, data?: unknown, options?: HttpRequestOptions) {
146
+ return request<T>('POST', path, data, options)
147
+ },
148
+ put<T>(path: string, data?: unknown, options?: HttpRequestOptions) {
149
+ return request<T>('PUT', path, data, options)
150
+ },
151
+ patch<T>(path: string, data?: unknown, options?: HttpRequestOptions) {
152
+ return request<T>('PATCH', path, data, options)
153
+ },
154
+ delete<T>(path: string, options?: HttpRequestOptions) {
155
+ return request<T>('DELETE', path, undefined, options)
156
+ },
157
+ }
158
+
159
+ export default baseHttpClient
@@ -1,221 +1,55 @@
1
- import { mockCurrentUser } from '../foreign-currency-position-forecast/mock'
2
-
3
- const TRAN_CODE = '/TAM/0001/140103006'
4
- const apiBaseUrl = String(import.meta.env.VITE_API_BASE_URL || 'http://localhost:3011/oms').replace(/\/+$/, '')
5
- const tamBranchId = String(import.meta.env.VITE_TAM_BRANCH_ID || mockCurrentUser.organizationCode)
6
- const tamUserId = String(import.meta.env.VITE_TAM_USER_ID || mockCurrentUser.userCode)
7
- const tamClientIp = String(import.meta.env.VITE_TAM_CLIENT_IP || '')
8
-
9
- export const rmbPositionAmountFields = [
10
- 'hgPredAmtIn',
11
- 'hgPredAmtOut',
12
- 'hgPredAmtNet',
13
- 'hgUnverifyAmtIn',
14
- 'hgUnverifyAmtOut',
15
- 'hgUnverifyAmtNet',
16
- 'zqPredAmtIn',
17
- 'zqPredAmtOut',
18
- 'zqPredAmtNet',
19
- 'zqUnverifyAmtIn',
20
- 'zqUnverifyAmtOut',
21
- 'zqUnverifyAmtNet',
22
- 'pjPredAmtIn',
23
- 'pjPredAmtOut',
24
- 'pjPredAmtNet',
25
- 'pjUnverifyAmtIn',
26
- 'pjUnverifyAmtOut',
27
- 'pjUnverifyAmtNet',
28
- 'tgPredAmtIn',
29
- 'tgPredAmtOut',
30
- 'tgPredAmtNet',
31
- 'tgUnverifyAmtIn',
32
- 'tgUnverifyAmtOut',
33
- 'tgUnverifyAmtNet',
34
- 'tyPredAmtIn',
35
- 'tyPredAmtOut',
36
- 'tyPredAmtNet',
37
- 'tyUnverifyAmtIn',
38
- 'tyUnverifyAmtOut',
39
- 'tyUnverifyAmtNet',
40
- 'fzhPredAmtIn',
41
- 'fzhPredAmtOut',
42
- 'fzhPredAmtNet',
43
- 'fzhUnverifyAmtIn',
44
- 'fzhUnverifyAmtOut',
45
- 'fzhUnverifyAmtNet',
46
- 'lcPredAmtIn',
47
- 'lcPredAmtOut',
48
- 'lcPredAmtNet',
49
- 'lcUnverifyAmtIn',
50
- 'lcUnverifyAmtOut',
51
- 'lcUnverifyAmtNet',
52
- 'qtPredAmtIn',
53
- 'qtPredAmtOut',
54
- 'qtPredAmtNet',
55
- 'qtUnverifyAmtIn',
56
- 'qtUnverifyAmtOut',
57
- 'qtUnverifyAmtNet',
58
- 'xjAmtIn',
59
- 'xjAmtOut',
60
- 'xjAmtNet',
61
- 'unVerifyAmtIn1',
62
- 'unVerifyAmtOut1',
63
- 'unVerifyAmtNet1',
64
- 'unVerifyAmtIn',
65
- 'unVerifyAmtOut',
66
- 'unVerifyAmtNet',
67
- 'zjPredAmtIn',
68
- 'zjPredAmtOut',
69
- 'zjPredAmtNet',
70
- 'zjUnverifyAmtIn',
71
- 'zjUnverifyAmtOut',
72
- 'zjUnverifyAmtNet',
73
- ] as const
74
-
75
- export type RmbPositionAmountField = typeof rmbPositionAmountFields[number]
76
- export type ProtocolAmount = number | '0'
77
-
78
- export type RmbPositionEstimationRequestBody = {
79
- overAmt: ProtocolAmount
80
- tranDate: string
81
- fzAmtIn: ProtocolAmount
82
- fzAmtOut: ProtocolAmount
83
- fzAmtRmk: string
84
- bepsAmtIn: ProtocolAmount
85
- bepsAmtOut: ProtocolAmount
86
- bepsAmtRmk: string
87
- othAmtIn: ProtocolAmount
88
- othAmtOut: ProtocolAmount
89
- othAmtRmk: string
90
- ysAmtIn: ProtocolAmount
91
- ysAmtOut: ProtocolAmount
92
- ysAmtRmk: string
93
- }
94
-
95
- export type RmbPositionEstimationResponseBody = {
96
- fileName: string
97
- } & Record<RmbPositionAmountField, string>
98
-
99
- type TamResponse = {
100
- head?: {
101
- retStatus?: string
102
- retCode?: string
103
- retMsg?: string
104
- }
105
- body?: Record<string, unknown>
106
- }
107
-
108
- type RequestOptions = {
109
- signal?: AbortSignal
110
- }
111
-
112
- function pad(value: number) {
113
- return String(value).padStart(2, '0')
114
- }
115
-
116
- function compactDate(date: Date) {
117
- return `${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}`
118
- }
119
-
120
- function compactTime(date: Date) {
121
- return `${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`
122
- }
123
-
124
- function createConsumerSeqNo(date: Date) {
125
- return `${tamUserId}${compactDate(date)}${compactTime(date)}${String(date.getMilliseconds()).padStart(3, '0')}`
126
- }
127
-
128
- function getResponseMessage(payload: TamResponse, fallback: string) {
129
- return payload.head?.retMsg || fallback
130
- }
131
-
132
- function normalizeResponseBody(
133
- source: Record<string, unknown>,
134
- ): RmbPositionEstimationResponseBody {
135
- const result = {
136
- fileName: String(source.fileName ?? ''),
137
- } as RmbPositionEstimationResponseBody
138
-
139
- rmbPositionAmountFields.forEach((field) => {
140
- if (!Object.hasOwn(source, field)) {
141
- throw new Error(`人民币头寸匡算接口缺少返回字段:${field}`)
142
- }
143
- const value = String(source[field] ?? '').trim()
144
- if (!/^-?(?:\d+(?:\.\d+)?|\.\d+)$/.test(value)) {
145
- throw new Error(`人民币头寸匡算接口金额字段格式不正确:${field}`)
146
- }
147
- result[field] = value
148
- })
149
-
150
- return result
151
- }
152
-
153
- export async function requestRmbPositionEstimation(
154
- body: RmbPositionEstimationRequestBody,
155
- options: RequestOptions = {},
156
- ) {
157
- const now = new Date()
158
- const request = {
159
- appHead: {
160
- fileName: '',
161
- opType: '',
162
- ip: tamClientIp,
163
- },
164
- head: {
165
- branchId: tamBranchId,
166
- consumerSeqNo: createConsumerSeqNo(now),
167
- consumerId: 'TAM001',
168
- tranCode: TRAN_CODE,
169
- tranDate: compactDate(now),
170
- tranTimestamp: compactTime(now),
171
- pageSize: '10',
172
- pageIndex: '1',
173
- traceId: '',
174
- spanId: '',
175
- userId: tamUserId,
176
- versionId: '0001',
177
- verifyUserId: '',
178
- adminUserId: '',
179
- apprUserId: '',
180
- areaCode: '0000',
181
- digitalSign: '',
182
- fileFlag: 'N',
183
- filePath: '',
184
- isBatch: false,
185
- },
186
- body,
187
- }
188
-
189
- const response = await fetch(`${apiBaseUrl}${TRAN_CODE}`, {
190
- method: 'POST',
191
- headers: { 'Content-Type': 'application/json' },
192
- body: JSON.stringify(request),
193
- signal: options.signal,
194
- })
195
-
196
- let payload: TamResponse
197
- try {
198
- payload = await response.json() as TamResponse
199
- } catch {
200
- throw new Error(`人民币头寸匡算接口返回的不是有效 JSON(HTTP ${response.status})`)
201
- }
202
-
203
- if (!payload || typeof payload !== 'object' || Array.isArray(payload)) {
204
- throw new Error('人民币头寸匡算接口返回结构不正确')
205
- }
206
-
207
- if (!response.ok) {
208
- throw new Error(getResponseMessage(payload, `人民币头寸匡算请求失败(HTTP ${response.status})`))
209
- }
210
- if (payload.head?.retStatus !== 'S' || payload.head?.retCode !== '00000') {
211
- throw new Error(getResponseMessage(payload, '人民币头寸匡算失败'))
212
- }
213
- if (!payload.body || typeof payload.body !== 'object' || Array.isArray(payload.body)) {
214
- throw new Error('人民币头寸匡算接口返回结构不正确')
215
- }
216
-
217
- return {
218
- body: normalizeResponseBody(payload.body),
219
- message: getResponseMessage(payload, '交易成功'),
220
- }
221
- }
1
+ import baseHttpClient, {
2
+ type HttpRequestOptions,
3
+ type TamResponse,
4
+ } from '@/utils/baseHttpClient'
5
+ import type {
6
+ RmbPositionEstimationRequestBody,
7
+ RmbPositionHistoryRequestBody,
8
+ } from './types'
9
+
10
+ /**
11
+ * 人民币头寸匡算页面的接口入口。
12
+ *
13
+ * 本文件只描述“调用哪个接口、传入什么业务参数”,不在这里拼装 TAM 公共报文头,
14
+ * 也不负责校验或转换返回字段。`baseHttpClient` 会识别 `/TAM/` 路径,并自动将
15
+ * `params` 包装到 TAM 请求报文的 `body` 中,同时补齐 `appHead` 和 `head`。
16
+ *
17
+ * 两个方法返回的都是未经页面整理的 TAM 原始响应:`{ head, body }`。其中 `head`
18
+ * 是交易状态等公共信息,`body` 是接口业务数据;具体业务字段由页面在使用前校验。
19
+ */
20
+ const API = {
21
+ /**
22
+ * 按交易日期及页面填写数据执行人民币头寸匡算。
23
+ *
24
+ * `params` 中的金额已经由页面从“亿元”换算为协议要求的“元”;这里直接透传,
25
+ * 不再做单位换算。可通过 `options` 传递 fetch 请求选项,例如传入
26
+ * `{ signal: controller.signal }`,在日期切换、重复查询或组件卸载时取消旧请求,
27
+ * 避免较早返回的结果覆盖当前页面数据。
28
+ */
29
+ queryAPI: (params: RmbPositionEstimationRequestBody, options?: HttpRequestOptions) => {
30
+ return baseHttpClient.post<TamResponse<Record<string, unknown>>>(
31
+ '/TAM/0001/140103006',
32
+ params,
33
+ options,
34
+ )
35
+ },
36
+
37
+ /**
38
+ * 按交易日期查询此前保存的页面填入数据,用于切换日期后的历史回填。
39
+ *
40
+ * 返回 `body` 的金额仍以“元”为单位,页面负责转换为“亿元”后展示。若该日期
41
+ * 没有历史记录,服务端会正常返回成功报文和空对象 `body: {}`;空对象表示
42
+ * “无可回填数据”,不属于接口异常。
43
+ *
44
+ * `options` 与 `queryAPI` 相同,可传入 `AbortSignal` 取消已经失效的历史查询。
45
+ */
46
+ historyAPI: (params: RmbPositionHistoryRequestBody, options?: HttpRequestOptions) => {
47
+ return baseHttpClient.post<TamResponse<Record<string, unknown>>>(
48
+ '/TAM/0001/140103005',
49
+ params,
50
+ options,
51
+ )
52
+ },
53
+ }
54
+
55
+ export default API