verce-vue-test 0.0.75 → 0.0.76

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.
@@ -11,7 +11,7 @@ export type UserRole = '006' | '007' | '008'
11
11
 
12
12
  export type ForeignPositionForecast = {
13
13
  predRefNo: string
14
- /** 后端字段沿用既有拼写:1 已授权,0 未授权。 */
14
+ /** 页面沿用既有拼写:1 已授权,0 未授权。 */
15
15
  authirization: '1' | '0'
16
16
  /** FTU 标识:1 是,空字符串为否。 */
17
17
  filter: '1' | ''
@@ -61,68 +61,6 @@ export const mockCurrentUser = {
61
61
  approvalAmountBoundary: 30_000_000,
62
62
  }
63
63
 
64
- const institutions = [
65
- { code: 'BJ001', name: '北京分行营业部' },
66
- { code: 'SH001', name: '上海浦东分行' },
67
- { code: 'SZ001', name: '深圳前海分行' },
68
- { code: 'GZ001', name: '广州天河支行' },
69
- { code: 'HZ001', name: '杭州分行营业部' },
70
- { code: 'CD001', name: '成都高新分行' },
71
- ]
72
-
73
- const clientNames = [
74
- '华远国际贸易有限公司',
75
- '海岳科技集团股份有限公司',
76
- '中盛航空服务有限公司',
77
- '远洋装备制造有限公司',
78
- '星河跨境电商有限公司',
79
- '宏信医药进出口有限公司',
80
- ]
81
-
82
- const counterparties = [
83
- 'PACIFIC GLOBAL LIMITED',
84
- 'EURO TRADE GMBH',
85
- 'ORIENTAL SHIPPING PTE. LTD.',
86
- 'NORTH STAR INDUSTRIES INC.',
87
- 'HORIZON CAPITAL LIMITED',
88
- 'SAKURA SUPPLY CO., LTD.',
89
- ]
90
-
91
- const banks = [
92
- ['BANK OF AMERICA, N.A.', 'BOFAUS3NXXX'],
93
- ['DEUTSCHE BANK AG', 'DEUTDEFFXXX'],
94
- ['DBS BANK LTD.', 'DBSSSGSGXXX'],
95
- ['JPMORGAN CHASE BANK, N.A.', 'CHASUS33XXX'],
96
- ['HSBC HONG KONG', 'HSBCHKHHHKH'],
97
- ['MUFG BANK, LTD.', 'BOTKJPJTXXX'],
98
- ] as const
99
-
100
- const accountBanks = [
101
- '中国银行纽约分行',
102
- '中国银行法兰克福分行',
103
- '中国银行新加坡分行',
104
- '中国银行伦敦分行',
105
- '中国银行香港分行',
106
- '中国银行东京分行',
107
- ]
108
-
109
- const currencies = ['USD', 'EUR', 'HKD', 'JPY', 'GBP', 'SGD']
110
- const forecastWays: ForecastWay[] = ['PW01', 'PW01', 'PW02', 'PW03']
111
- const forecastStatuses: ForecastStatus[] = [
112
- 'PS01',
113
- 'PS02',
114
- 'PS03',
115
- 'PS03',
116
- 'PS04',
117
- 'PS06',
118
- 'PS07',
119
- 'PS08',
120
- 'PS05',
121
- ]
122
- const businessTypes: BusinessType[] = ['10', '11', '12', '13']
123
- const exchangeTypes: ForeignExchangeType[] = ['01', '02', '03']
124
- const paymentRoutes: PaymentRoute[] = ['01', '02', '03']
125
-
126
64
  function pad(value: number) {
127
65
  return String(value).padStart(2, '0')
128
66
  }
@@ -130,86 +68,3 @@ function pad(value: number) {
130
68
  export function formatDate(date: Date) {
131
69
  return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`
132
70
  }
133
-
134
- function formatDateTime(date: Date) {
135
- return `${formatDate(date)} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
136
- }
137
-
138
- export function addDays(date: Date, days: number) {
139
- const next = new Date(date)
140
- next.setHours(12, 0, 0, 0)
141
- next.setDate(next.getDate() + days)
142
- return next
143
- }
144
-
145
- export async function mockFetchForeignPositionForecasts(): Promise<ForeignPositionForecast[]> {
146
- const now = new Date()
147
- const dateOffsets = [0, 1, 2, 3, 5, 7, -1, 10, 15]
148
-
149
- const rows = Array.from({ length: 36 }, (_, index): ForeignPositionForecast => {
150
- const serial = index + 1
151
- const valueDate = addDays(now, dateOffsets[index % dateOffsets.length] ?? 0)
152
- const valueDateText = formatDate(valueDate)
153
- const currentDateText = formatDate(now)
154
- const forecastDate = addDays(now, -(index % 5))
155
- const currency = currencies[index % currencies.length] ?? 'USD'
156
- const predAmount = 780_000 + index * 365_000 + (index % 4) * 128_500
157
- const verifyStatus: VerifyStatus = index % 9 === 4 ? 'VS03' : index % 7 === 5 ? 'VS02' : 'VS01'
158
- const verifyAmount = verifyStatus === 'VS03'
159
- ? predAmount
160
- : verifyStatus === 'VS02'
161
- ? Math.round(predAmount * 0.42 * 100) / 100
162
- : 0
163
- const bank = banks[index % banks.length] ?? banks[0]
164
- const institution = institutions[index % institutions.length] ?? institutions[0]
165
- const businessType = businessTypes[index % businessTypes.length] ?? '10'
166
- const predStatus = forecastStatuses[index % forecastStatuses.length] ?? 'PS01'
167
- const payDirection: PaymentDirection = index % 3 === 0 ? 'O' : 'I'
168
- const clientDisabled = businessType === '12' || businessType === '13'
169
- const counterpartyDisabled = businessType === '11' || (businessType === '10' && payDirection === 'I')
170
-
171
- return {
172
- predRefNo: `FPS${formatDate(now).replaceAll('-', '')}${String(serial).padStart(4, '0')}`,
173
- authirization: index % 3 === 0 ? '1' : '0',
174
- filter: index % 4 === 0 ? '1' : '',
175
- predWay: forecastWays[index % forecastWays.length] ?? 'PW01',
176
- predStatus,
177
- predType: valueDateText > currentDateText ? 'PT01' : valueDateText === currentDateText ? 'PT02' : 'PT03',
178
- groundBranch: institution?.name ?? '',
179
- groundBranchCode: institution?.code ?? '',
180
- payDirection,
181
- bankAccount: accountBanks[index % accountBanks.length] ?? accountBanks[0],
182
- paymentRoute: paymentRoutes[index % paymentRoutes.length] ?? '01',
183
- currency,
184
- predAmount,
185
- valueDate: valueDateText,
186
- verifyStatus,
187
- verifyAmount,
188
- businessType,
189
- clientType: clientDisabled ? '' : index % 5 === 0 ? 'CT02' : 'CT01',
190
- clientId: clientDisabled ? '' : `C${String(100000 + index)}`,
191
- clientName: clientDisabled ? '' : clientNames[index % clientNames.length] ?? clientNames[0],
192
- clientAccount: clientDisabled ? '' : `6217${String(800000000000 + index * 7919)}`,
193
- counterpartyName: counterpartyDisabled ? '' : counterparties[index % counterparties.length] ?? counterparties[0],
194
- counterpartyAccount: counterpartyDisabled ? '' : `${currency}${String(3058000000 + index * 13007)}`,
195
- receivingBank: counterpartyDisabled ? '' : bank[0],
196
- receivingBankSwiftCode: counterpartyDisabled ? '' : bank[1],
197
- foreignExchangeType: businessType === '13' ? '' : exchangeTypes[index % exchangeTypes.length] ?? '03',
198
- counterpartySwiftCode: bank[1],
199
- documentBusinessNo: businessType === '11' ? `DOC${formatDate(now).replaceAll('-', '')}${serial}` : '',
200
- intermediaryBankSwiftCode: businessType === '11' ? '' : index % 4 === 0 ? 'BKCHCNBJXXX' : '',
201
- purpose: index % 3 === 0 ? '跨境贸易货款结算' : '日常经营项下资金收付',
202
- remark: index % 5 === 0 ? '重点客户跨境结算,请关注到账时点。' : '',
203
- forecasterName: index % 2 === 0 ? '王晓峰' : '李思远',
204
- forecasterCode: index % 2 === 0 ? mockCurrentUser.userCode : `BR${String(70020 + index)}`,
205
- forecastDepartment: institution?.name ?? '',
206
- phoneNumber: `138${String(10000000 + index * 97).slice(-8)}`,
207
- forecastTime: formatDateTime(forecastDate),
208
- approvalTime: ['PS03', 'PS04', 'PS05', 'PS08'].includes(predStatus)
209
- ? formatDateTime(addDays(forecastDate, 1))
210
- : '',
211
- }
212
- })
213
-
214
- return Promise.resolve(rows)
215
- }
@@ -0,0 +1,129 @@
1
+ import { computed, reactive, ref } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+ import type { ForeignPositionForecastQuery } from './api'
4
+ import type { ForecastEditorMode } from './editor'
5
+ import type { ForeignPositionForecast } from './mock'
6
+
7
+ export type FilterState = ForeignPositionForecastQuery
8
+ export type ApprovalAction = 'approve' | 'reject' | null
9
+ export type PageMode = 'list' | 'editor'
10
+
11
+ export function createEmptyFilters(): FilterState {
12
+ return {
13
+ valueDate: '',
14
+ payDirection: '',
15
+ forecastStatuses: [],
16
+ foreignExchangeType: '',
17
+ forecastWay: '',
18
+ verifyStatuses: [],
19
+ organizationName: '',
20
+ clientName: '',
21
+ businessType: '',
22
+ currencies: [],
23
+ authirization: '',
24
+ ftuFilter: '',
25
+ minAmount: null,
26
+ maxAmount: null,
27
+ }
28
+ }
29
+
30
+ export function cloneFilters(filters: FilterState): FilterState {
31
+ return {
32
+ ...filters,
33
+ forecastStatuses: [...filters.forecastStatuses],
34
+ verifyStatuses: [...filters.verifyStatuses],
35
+ currencies: [...filters.currencies],
36
+ }
37
+ }
38
+
39
+ export const useForeignPositionForecastStore = defineStore(
40
+ 'foreign-currency-position-forecast',
41
+ () => {
42
+ const filterForm = reactive<FilterState>(createEmptyFilters())
43
+ const appliedFilters = ref<FilterState>(createEmptyFilters())
44
+ const successfulFilters = ref<FilterState>(createEmptyFilters())
45
+ const allRows = ref<ForeignPositionForecast[]>([])
46
+ const totalCount = ref(0)
47
+ const selectedRows = ref<ForeignPositionForecast[]>([])
48
+ const selectionResetKey = ref(0)
49
+ const isLoading = ref(false)
50
+ const isQuerying = ref(false)
51
+ const filterCollapsed = ref(true)
52
+ const currentPage = ref(1)
53
+ const pageSize = ref(25)
54
+ const successfulPage = ref(1)
55
+ const successfulPageSize = ref(25)
56
+
57
+ const pageMode = ref<PageMode>('list')
58
+ const editorMode = ref<ForecastEditorMode>('add')
59
+ const editorRecord = ref<ForeignPositionForecast | null>(null)
60
+ const isSaving = ref(false)
61
+ const approvalAction = ref<ApprovalAction>(null)
62
+
63
+ const selectedCurrencyCount = computed(
64
+ () => new Set(selectedRows.value.map((row) => row.currency)).size,
65
+ )
66
+ const hasMixedCurrencySelection = computed(
67
+ () => selectedRows.value.length > 1 && selectedCurrencyCount.value > 1,
68
+ )
69
+ const amountSummary = computed(() => {
70
+ if (selectedRows.value.length === 0 || selectedCurrencyCount.value !== 1) return null
71
+
72
+ const rows = selectedRows.value
73
+ const currency = rows[0]?.currency ?? ''
74
+ const income = rows
75
+ .filter((row) => row.payDirection === 'I')
76
+ .reduce((sum, row) => sum + row.predAmount, 0) / 10_000
77
+ const expense = rows
78
+ .filter((row) => row.payDirection === 'O')
79
+ .reduce((sum, row) => sum + row.predAmount, 0) / 10_000
80
+
81
+ return {
82
+ currency,
83
+ source: `已选 ${rows.length} 笔`,
84
+ income,
85
+ expense,
86
+ net: income - expense,
87
+ }
88
+ })
89
+ const tableHeight = computed(() => (
90
+ filterCollapsed.value ? 'calc(100vh - 330px)' : 'calc(100vh - 430px)'
91
+ ))
92
+
93
+ function clearTableSelection() {
94
+ selectedRows.value = []
95
+ selectionResetKey.value += 1
96
+ }
97
+
98
+ function resetFilterForm() {
99
+ Object.assign(filterForm, createEmptyFilters())
100
+ }
101
+
102
+ return {
103
+ filterForm,
104
+ appliedFilters,
105
+ successfulFilters,
106
+ allRows,
107
+ totalCount,
108
+ selectedRows,
109
+ selectionResetKey,
110
+ isLoading,
111
+ isQuerying,
112
+ filterCollapsed,
113
+ currentPage,
114
+ pageSize,
115
+ successfulPage,
116
+ successfulPageSize,
117
+ pageMode,
118
+ editorMode,
119
+ editorRecord,
120
+ isSaving,
121
+ approvalAction,
122
+ hasMixedCurrencySelection,
123
+ amountSummary,
124
+ tableHeight,
125
+ clearTableSelection,
126
+ resetFilterForm,
127
+ }
128
+ },
129
+ )
@@ -0,0 +1,221 @@
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
+ }