verce-vue-test 0.0.54 → 0.0.55

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.
Files changed (82) hide show
  1. package/mini2.0-main/src/api/rmb-position.ts +139 -0
  2. package/mini2.0-main/src/api/tam.ts +170 -0
  3. package/{mini2.0-main 2/src/api/user.ts → mini2.0-main/src/api/user.ts} +16 -0
  4. package/{mini2.0-main 2/src/stores/user.ts → mini2.0-main/src/stores/user.ts} +56 -4
  5. package/{mini2.0-main 2/src/types/api.d.ts → mini2.0-main/src/types/api.d.ts} +1 -1
  6. package/{mini2.0-main 2/src/utils/auth-token.ts → mini2.0-main/src/utils/auth-token.ts} +50 -6
  7. package/{mini2.0-main 2/src/utils/request.ts → mini2.0-main/src/utils/request.ts} +10 -6
  8. package/{mini2.0-main 2/src/views/login/index.vue → mini2.0-main/src/views/login/index.vue} +46 -6
  9. package/package.json +1 -1
  10. package/mini2.0-main 2/src/api/rmb-position.ts +0 -287
  11. /package/{mini2.0-main 2 → mini2.0-main}/.editorconfig +0 -0
  12. /package/{mini2.0-main 2 → mini2.0-main}/.env.development +0 -0
  13. /package/{mini2.0-main 2 → mini2.0-main}/.env.production +0 -0
  14. /package/{mini2.0-main 2 → mini2.0-main}/.env.test +0 -0
  15. /package/{mini2.0-main 2 → mini2.0-main}/.gitattributes +0 -0
  16. /package/{mini2.0-main 2 → mini2.0-main}/.oxlintrc.json +0 -0
  17. /package/{mini2.0-main 2 → mini2.0-main}/.prettierrc.json +0 -0
  18. /package/{mini2.0-main 2 → mini2.0-main}/.vscode/extensions.json +0 -0
  19. /package/{mini2.0-main 2 → mini2.0-main}/README.md +0 -0
  20. /package/{mini2.0-main 2 → mini2.0-main}/auto-imports.d.ts +0 -0
  21. /package/{mini2.0-main 2 → mini2.0-main}/components.d.ts +0 -0
  22. /package/{mini2.0-main 2 → mini2.0-main}/design-qa.md +0 -0
  23. /package/{mini2.0-main 2 → mini2.0-main}/docs/MX_API.md +0 -0
  24. /package/{mini2.0-main 2 → mini2.0-main}/docs/REQUEST.md +0 -0
  25. /package/{mini2.0-main 2 → mini2.0-main}/docs/jsapi.js +0 -0
  26. /package/{mini2.0-main 2 → mini2.0-main}/docs/package-json-guide.md +0 -0
  27. /package/{mini2.0-main 2 → mini2.0-main}/env.d.ts +0 -0
  28. /package/{mini2.0-main 2 → mini2.0-main}/eslint.config.ts +0 -0
  29. /package/{mini2.0-main 2 → mini2.0-main}/index.html +0 -0
  30. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/design-comparison.png +0 -0
  31. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-back-top.png +0 -0
  32. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-page.png +0 -0
  33. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-sticky-check.png +0 -0
  34. /package/{mini2.0-main 2 → mini2.0-main}/output/playwright/rmb-position/rmb-position-sticky-scrolled.png +0 -0
  35. /package/{mini2.0-main 2 → mini2.0-main}/package-lock.json +0 -0
  36. /package/{mini2.0-main 2 → mini2.0-main}/package.json +0 -0
  37. /package/{mini2.0-main 2 → mini2.0-main}/plugins/bump-version.ts +0 -0
  38. /package/{mini2.0-main 2 → mini2.0-main}/postcss.config.ts +0 -0
  39. /package/{mini2.0-main 2 → mini2.0-main}/public/favicon.ico +0 -0
  40. /package/{mini2.0-main 2 → mini2.0-main}/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
  41. /package/{mini2.0-main 2 → mini2.0-main}/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
  42. /package/{mini2.0-main 2 → mini2.0-main}/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
  43. /package/{mini2.0-main 2 → mini2.0-main}/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
  44. /package/{mini2.0-main 2 → mini2.0-main}/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
  45. /package/{mini2.0-main 2 → mini2.0-main}/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
  46. /package/{mini2.0-main 2 → mini2.0-main}/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
  47. /package/{mini2.0-main 2 → mini2.0-main}/public/images/img.png +0 -0
  48. /package/{mini2.0-main 2 → mini2.0-main}/src/App.vue +0 -0
  49. /package/{mini2.0-main 2 → mini2.0-main}/src/api/announcement.ts +0 -0
  50. /package/{mini2.0-main 2 → mini2.0-main}/src/api/health.ts +0 -0
  51. /package/{mini2.0-main 2 → mini2.0-main}/src/auto-imports.d.ts +0 -0
  52. /package/{mini2.0-main 2 → mini2.0-main}/src/components.d.ts +0 -0
  53. /package/{mini2.0-main 2 → mini2.0-main}/src/config/config.properties +0 -0
  54. /package/{mini2.0-main 2 → mini2.0-main}/src/config/env.ts +0 -0
  55. /package/{mini2.0-main 2 → mini2.0-main}/src/config/plugin.properties.pro +0 -0
  56. /package/{mini2.0-main 2 → mini2.0-main}/src/config/plugin.properties.test +0 -0
  57. /package/{mini2.0-main 2 → mini2.0-main}/src/core/mxApi/index.ts +0 -0
  58. /package/{mini2.0-main 2 → mini2.0-main}/src/core/request/index.ts +0 -0
  59. /package/{mini2.0-main 2 → mini2.0-main}/src/main.ts +0 -0
  60. /package/{mini2.0-main 2 → mini2.0-main}/src/router/index.ts +0 -0
  61. /package/{mini2.0-main 2 → mini2.0-main}/src/stores/app.ts +0 -0
  62. /package/{mini2.0-main 2 → mini2.0-main}/src/stores/counter.ts +0 -0
  63. /package/{mini2.0-main 2 → mini2.0-main}/src/types/nprogress.d.ts +0 -0
  64. /package/{mini2.0-main 2 → mini2.0-main}/src/utils/code-highlight.ts +0 -0
  65. /package/{mini2.0-main 2 → mini2.0-main}/src/utils/copy.ts +0 -0
  66. /package/{mini2.0-main 2 → mini2.0-main}/src/utils/query.ts +0 -0
  67. /package/{mini2.0-main 2 → mini2.0-main}/src/views/article-detail/index.vue +0 -0
  68. /package/{mini2.0-main 2 → mini2.0-main}/src/views/article-edit/index.vue +0 -0
  69. /package/{mini2.0-main 2 → mini2.0-main}/src/views/articles/index.vue +0 -0
  70. /package/{mini2.0-main 2 → mini2.0-main}/src/views/clearing-detail/index.vue +0 -0
  71. /package/{mini2.0-main 2 → mini2.0-main}/src/views/foreign-position/index.vue +0 -0
  72. /package/{mini2.0-main 2 → mini2.0-main}/src/views/home/index.vue +0 -0
  73. /package/{mini2.0-main 2 → mini2.0-main}/src/views/mine/index.vue +0 -0
  74. /package/{mini2.0-main 2 → mini2.0-main}/src/views/net-debit/index.vue +0 -0
  75. /package/{mini2.0-main 2 → mini2.0-main}/src/views/pbc-position/index.vue +0 -0
  76. /package/{mini2.0-main 2 → mini2.0-main}/src/views/position-estimate/index.vue +0 -0
  77. /package/{mini2.0-main 2 → mini2.0-main}/src/views/rmb-position/index.vue +0 -0
  78. /package/{mini2.0-main 2 → mini2.0-main}/src/views/warning/index.vue +0 -0
  79. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.app.json +0 -0
  80. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.json +0 -0
  81. /package/{mini2.0-main 2 → mini2.0-main}/tsconfig.node.json +0 -0
  82. /package/{mini2.0-main 2 → mini2.0-main}/vite.config.ts +0 -0
@@ -0,0 +1,139 @@
1
+ import {
2
+ buildTamRequestPayload,
3
+ tamRequest,
4
+ type TamRequestPayload,
5
+ type TamResponse,
6
+ } from '@/api/tam'
7
+
8
+ export type RmbForecastRecord = {
9
+ /** 业务类型,用于映射列表中的业务名称。 */
10
+ busiType?: string
11
+ /** 客户名称,客户类型为空时作为展示兜底。 */
12
+ clientName?: string
13
+ /** 客户类型,用于映射列表中的客户类型文案。 */
14
+ clientType?: string
15
+ /** 交易对手名称,客户名称为空时作为展示兜底。 */
16
+ competName?: string
17
+ /** 落地机构,列表主标题展示字段。 */
18
+ groundBranch?: string
19
+ /** 预报金额,接口按元返回,页面转换为亿元展示。 */
20
+ predAmt?: string
21
+ /** 预报状态,用于判断列表状态标签。 */
22
+ predStatus?: string
23
+ /** 交易日期,列表日期展示字段。 */
24
+ tranDate?: string
25
+ /** 核销状态,用于判断列表状态标签。 */
26
+ verifyStatus?: string
27
+ }
28
+
29
+ export type RmbForecastQueryForm = {
30
+ /** 交易时间,当前视图必填筛选项。 */
31
+ tranDate: string
32
+ /** 落地机构,当前视图按关键字查询。 */
33
+ groundBranch?: string
34
+ /** 起始金额,页面单位为亿元。 */
35
+ startTranAmt?: string
36
+ /** 截止金额,页面单位为亿元。 */
37
+ endTranAmt?: string
38
+ }
39
+
40
+ export type RmbForecastQueryPayload = {
41
+ appHead: TamRequestPayload<RmbForecastQueryBody>['appHead']
42
+ body: RmbForecastQueryBody
43
+ head: TamRequestPayload<RmbForecastQueryBody>['head']
44
+ }
45
+
46
+ export type RmbForecastQueryResult = {
47
+ body: RmbForecastQueryResultBody
48
+ head: TamResponse<RmbForecastQueryResultBody>['head']
49
+ }
50
+
51
+ type RmbForecastQueryBody = {
52
+ /** 业务类型,当前视图未开放筛选,固定传空。 */
53
+ busiType: string
54
+ /** 客户名称,当前视图未开放筛选,固定传空。 */
55
+ clientName: string
56
+ /** 交易对手名称,当前视图未开放筛选,固定传空。 */
57
+ competName: string
58
+ /** 截止金额,页面亿元转换为接口元级整数字符串。 */
59
+ endTransAmt: string
60
+ /** 落地机构,来自当前视图输入框。 */
61
+ groundBranch: string
62
+ /** 支付渠道,当前视图未开放筛选,固定传空。 */
63
+ payChannel: string
64
+ /** 收支方向,当前视图未开放筛选,固定传空。 */
65
+ payDirec: string
66
+ /** 预报状态,当前视图未开放筛选,固定传空。 */
67
+ predStatus: string
68
+ /** 排序规则,当前视图未开放筛选,固定传空。 */
69
+ sortRule: string
70
+ /** 起始金额,页面亿元转换为接口元级整数字符串。 */
71
+ startTransAmt: string
72
+ /** 交易时间,接口格式为 YYYYMMDD。 */
73
+ tranDate: string
74
+ /** 核销状态,当前视图未开放筛选,固定传空。 */
75
+ verifyStatus: string
76
+ }
77
+
78
+ type RmbForecastQueryResultBody = {
79
+ resultList: RmbForecastRecord[]
80
+ totalCount: string
81
+ }
82
+
83
+ type QueryOptions = {
84
+ form: RmbForecastQueryForm
85
+ pageIndex: number
86
+ pageSize: number
87
+ }
88
+
89
+ const TRAN_CODE = '/TAM/0001/140101001'
90
+
91
+ export function buildRmbForecastQueryPayload({
92
+ form,
93
+ pageIndex,
94
+ pageSize,
95
+ }: QueryOptions): RmbForecastQueryPayload {
96
+ const tranDate = normalizeDate(form.tranDate)
97
+
98
+ // 当前视图只提供交易日期、落地机构、起始金额、截止金额,其余查询字段按接口约定传空。
99
+ return buildTamRequestPayload({
100
+ tranCode: TRAN_CODE,
101
+ pageIndex,
102
+ pageSize,
103
+ body: {
104
+ busiType: '',
105
+ clientName: '',
106
+ competName: '',
107
+ endTransAmt: toRequestAmount(form.endTranAmt),
108
+ groundBranch: form.groundBranch || '',
109
+ payChannel: '',
110
+ payDirec: '',
111
+ predStatus: '',
112
+ sortRule: '',
113
+ // 后端字段名为 TransAmt,保持与交易入参一致。
114
+ startTransAmt: toRequestAmount(form.startTranAmt),
115
+ tranDate,
116
+ verifyStatus: '',
117
+ },
118
+ })
119
+ }
120
+
121
+ export async function queryRmbForecastPage(
122
+ payload: RmbForecastQueryPayload,
123
+ ): Promise<RmbForecastQueryResult> {
124
+ return tamRequest<RmbForecastQueryBody, RmbForecastQueryResultBody>(payload)
125
+ }
126
+
127
+ function normalizeDate(value: string) {
128
+ // 日期选择器产出 YYYY-MM-DD;接口需要 YYYYMMDD。
129
+ if (/^\d{8}$/.test(value)) return value
130
+ return value.replaceAll('-', '')
131
+ }
132
+
133
+ function toRequestAmount(value?: string) {
134
+ if (!value?.trim()) return ''
135
+
136
+ // 页面按“亿元”录入,接口按元级整数金额查询。
137
+ const amount = Number(value)
138
+ return Number.isFinite(amount) ? String(Math.round(amount * 100000000)) : ''
139
+ }
@@ -0,0 +1,170 @@
1
+ import dayjs from 'dayjs'
2
+ import { request } from '@/core/request'
3
+ import { useUserStore } from '@/stores/user'
4
+
5
+ export type TamAppHead = {
6
+ fileName: string
7
+ opType: string
8
+ ip: string
9
+ }
10
+
11
+ export type TamHead = {
12
+ adminUserId: string
13
+ apprUserId: string
14
+ areaCode: string
15
+ branchId: string
16
+ consumerId: string
17
+ consumerSeqNo: string
18
+ digitalSign: string
19
+ fileFlag: string
20
+ filePath: string
21
+ isBatch: boolean
22
+ pageIndex: number
23
+ pageSize: number
24
+ spanId: string
25
+ traceId: string
26
+ tranCode: string
27
+ tranDate: string
28
+ tranTimestamp: string
29
+ userId: string
30
+ verifyUserId: string
31
+ versionId: string
32
+ }
33
+
34
+ export type TamRequestPayload<TBody> = {
35
+ appHead: TamAppHead
36
+ head: TamHead
37
+ body: TBody
38
+ }
39
+
40
+ export type TamResponseHead = Omit<TamHead, 'pageIndex' | 'pageSize'> & {
41
+ ctrlBits?: string
42
+ extra?: Record<string, unknown>
43
+ pageIndex: number | string
44
+ pageSize: number | string
45
+ retCode: string
46
+ retMsg: string
47
+ retStatus: string
48
+ }
49
+
50
+ export type TamResponse<TBody> = {
51
+ head: TamResponseHead
52
+ body: TBody
53
+ }
54
+
55
+ type BuildTamPayloadOptions<TBody> = {
56
+ tranCode: string
57
+ body: TBody
58
+ pageIndex?: number
59
+ pageSize?: number
60
+ appHead?: Partial<TamAppHead>
61
+ head?: Partial<TamHead>
62
+ }
63
+
64
+ let consumerSeqSeed = Math.floor(Math.random() * 100000000)
65
+
66
+ export function buildTamRequestPayload<TBody>({
67
+ tranCode,
68
+ body,
69
+ pageIndex = 1,
70
+ pageSize = 10,
71
+ appHead,
72
+ head,
73
+ }: BuildTamPayloadOptions<TBody>): TamRequestPayload<TBody> {
74
+ const now = dayjs()
75
+ const loginContext = getTamLoginContext()
76
+
77
+ return {
78
+ appHead: {
79
+ fileName: '',
80
+ opType: '',
81
+ ip: loginContext.ip,
82
+ ...appHead,
83
+ },
84
+ head: {
85
+ adminUserId: '',
86
+ apprUserId: '',
87
+ areaCode: '0000',
88
+ branchId: loginContext.branchId,
89
+ consumerId: 'TAM001',
90
+ // 规则:当前登录用户 ID + 日期 + 8 位运行期递增序列。
91
+ consumerSeqNo: `${loginContext.userId}${now.format('YYYYMMDD')}${createConsumerSeq()}`,
92
+ digitalSign: '',
93
+ fileFlag: 'N',
94
+ filePath: '',
95
+ isBatch: false,
96
+ pageIndex,
97
+ pageSize,
98
+ spanId: '',
99
+ traceId: '',
100
+ tranCode,
101
+ tranDate: now.format('YYYYMMDD'),
102
+ tranTimestamp: now.format('HHmmss'),
103
+ userId: loginContext.userId,
104
+ verifyUserId: '',
105
+ versionId: '0001',
106
+ ...head,
107
+ },
108
+ body,
109
+ }
110
+ }
111
+
112
+ export async function tamRequest<TBody, TResponseBody>(
113
+ payload: TamRequestPayload<TBody>,
114
+ ): Promise<TamResponse<TResponseBody>> {
115
+ const response = await request<TamResponse<TResponseBody>, TamRequestPayload<TBody>>({
116
+ url: payload.head.tranCode,
117
+ method: 'POST',
118
+ data: payload,
119
+ })
120
+ const result = response as unknown as TamResponse<TResponseBody>
121
+
122
+ if (result.head?.retStatus && result.head.retStatus !== 'S') {
123
+ throw new Error(result.head.retMsg || '交易失败')
124
+ }
125
+
126
+ return result
127
+ }
128
+
129
+ function getTamLoginContext() {
130
+ const userStore = useUserStore()
131
+ const principal = userStore.authPayload?.principal
132
+
133
+ return {
134
+ // TAM 用户号优先取登录返回的 userId,兼容只返回 username 的场景。
135
+ userId: firstText(principal?.userId, principal?.username, userStore.username),
136
+ // 当前登录机构来自 /uaa/user/getOrgByUserName 的第一条记录。
137
+ branchId: firstText(
138
+ userStore.loginOrg?.orgNo,
139
+ userStore.loginOrg?.orgId,
140
+ principal?.branchId,
141
+ principal?.orgId,
142
+ principal?.currentOrgId,
143
+ getLastText(principal?.orgIds),
144
+ ),
145
+ // appHead.ip 使用登录返回的请求 IP。
146
+ ip: firstText(principal?.reqIpAddr, principal?.ip, principal?.loginIp),
147
+ }
148
+ }
149
+
150
+ function createConsumerSeq() {
151
+ consumerSeqSeed = (consumerSeqSeed + 1) % 100000000
152
+ return String(consumerSeqSeed).padStart(8, '0')
153
+ }
154
+
155
+ function getLastText(value: unknown) {
156
+ if (!Array.isArray(value)) return undefined
157
+
158
+ return [...value].reverse().find((item) => typeof item === 'string' && item.trim())
159
+ }
160
+
161
+ function firstText(...values: unknown[]) {
162
+ for (const value of values) {
163
+ if (typeof value !== 'string') continue
164
+
165
+ const text = value.trim()
166
+ if (text) return text
167
+ }
168
+
169
+ return ''
170
+ }
@@ -7,10 +7,26 @@ interface UserInfo {
7
7
  avatar: string
8
8
  }
9
9
 
10
+ export type UserOrg = {
11
+ orgNo: string
12
+ orgCnAbre: string
13
+ SORTNO: number
14
+ orgId: string
15
+ }
16
+
10
17
  export function getUserInfoApi(id: number) {
11
18
  return request<UserInfo>({ url: `/user/${id}` })
12
19
  }
13
20
 
21
+ export function getOrgByUserNameApi(username: string) {
22
+ return request<UserOrg[]>({
23
+ url: '/uaa/user/getOrgByUserName',
24
+ params: {
25
+ username,
26
+ },
27
+ })
28
+ }
29
+
14
30
  export function loginApi(data: { username: string; password: string }) {
15
31
  return request<AuthTokenResponse>({
16
32
  url: '/uaa/oauth/token',
@@ -1,12 +1,17 @@
1
1
  import { defineStore } from 'pinia'
2
+ import type { UserOrg } from '@/api/user'
3
+ import type { AuthTokenPayload } from '@/utils/auth-token'
2
4
 
3
5
  const LEGACY_TOKEN_KEYS = ['token', 'refresh_token', 'user']
4
6
 
7
+ /** 用户登录态在本地存储中的 key,由 pinia-plugin-persistedstate 使用。 */
8
+ const AUTH_PERSIST_KEY = 'mini2_user_auth'
9
+
5
10
  /**
6
11
  * 用户状态 Store
7
12
  *
8
13
  * 使用 Composition API 风格(setup 语法)定义。
9
- * token 只保存在 Pinia 内存态中,刷新页面后需要重新登录或通过敏行自动登录恢复。
14
+ * 登录信息通过 pinia-plugin-persistedstate 保存到本地,刷新页面后可继续使用。
10
15
  */
11
16
  export const useUserStore = defineStore(
12
17
  'user',
@@ -15,12 +20,18 @@ export const useUserStore = defineStore(
15
20
  // -------------------------------- State --------------------------------
16
21
 
17
22
  /** 登录凭证,登录成功后由后端返回,后续请求通过请求头携带 */
18
- const token = ref('1')
23
+ const token = ref('')
19
24
  const refreshToken = ref('')
20
25
  const username = ref('')
21
26
  const realName = ref('')
22
27
  const organizationName = ref('')
23
28
 
29
+ /** 登录接口原始返回信息,已在保存前去除敏感字段。 */
30
+ const authPayload = ref<AuthTokenPayload | null>(null)
31
+
32
+ /** 当前登录机构,登录后取机构列表第一条。 */
33
+ const loginOrg = ref<UserOrg | null>(null)
34
+
24
35
  clearLegacyStoredTokens()
25
36
 
26
37
  // ------------------------------ Actions --------------------------------
@@ -37,20 +48,41 @@ export const useUserStore = defineStore(
37
48
  refreshToken.value = value
38
49
  }
39
50
 
40
- function setAuthTokens(accessToken: string, newRefreshToken?: string) {
51
+ function setAuthTokens(
52
+ accessToken: string,
53
+ newRefreshToken?: string,
54
+ payload?: AuthTokenPayload,
55
+ ) {
41
56
  setToken(accessToken)
42
57
 
43
58
  if (newRefreshToken) {
44
59
  setRefreshToken(newRefreshToken)
45
60
  }
61
+
62
+ if (payload) {
63
+ authPayload.value = payload
64
+ }
46
65
  }
47
66
 
48
- function setUserInfo(info: { username?: string; realName?: string; organizationName?: string }) {
67
+ function setUserInfo(info: {
68
+ username?: string
69
+ realName?: string
70
+ organizationName?: string
71
+ }) {
49
72
  username.value = info.username || username.value
50
73
  realName.value = info.realName || realName.value
51
74
  organizationName.value = info.organizationName || organizationName.value
52
75
  }
53
76
 
77
+ function setAuthPayload(payload: AuthTokenPayload | null) {
78
+ authPayload.value = payload
79
+ }
80
+
81
+ function setLoginOrg(org: UserOrg) {
82
+ loginOrg.value = org
83
+ organizationName.value = org.orgCnAbre || organizationName.value
84
+ }
85
+
54
86
  /**
55
87
  * 清空 token
56
88
  * 退出登录或刷新 token 失败时调用。
@@ -61,6 +93,8 @@ export const useUserStore = defineStore(
61
93
  username.value = ''
62
94
  realName.value = ''
63
95
  organizationName.value = ''
96
+ authPayload.value = null
97
+ loginOrg.value = null
64
98
  }
65
99
 
66
100
  // ----------------------------- Return ----------------------------------
@@ -71,13 +105,31 @@ export const useUserStore = defineStore(
71
105
  username,
72
106
  realName,
73
107
  organizationName,
108
+ authPayload,
109
+ loginOrg,
74
110
  setToken,
75
111
  setRefreshToken,
76
112
  setAuthTokens,
77
113
  setUserInfo,
114
+ setAuthPayload,
115
+ setLoginOrg,
78
116
  clearToken,
79
117
  }
80
118
  },
119
+ {
120
+ persist: {
121
+ key: AUTH_PERSIST_KEY,
122
+ pick: [
123
+ 'token',
124
+ 'refreshToken',
125
+ 'username',
126
+ 'realName',
127
+ 'organizationName',
128
+ 'authPayload',
129
+ 'loginOrg',
130
+ ],
131
+ },
132
+ },
81
133
  )
82
134
 
83
135
  function clearLegacyStoredTokens() {
@@ -1,6 +1,6 @@
1
1
  /** 后端统一响应格式 */
2
2
  export interface ApiResponse<T = unknown> {
3
- code: number
3
+ code: number | string
4
4
  message: string
5
5
  data: T
6
6
  }
@@ -3,7 +3,15 @@ import { useUserStore } from '@/stores/user'
3
3
  export const REFRESH_TOKEN_URL = '/uaa/oauth/mobile/refresh_token'
4
4
 
5
5
  export type AuthPrincipal = {
6
+ branchId?: string
7
+ currentOrgId?: string
8
+ ip?: string
9
+ loginIp?: string
10
+ orgId?: string
11
+ orgIds?: string[]
12
+ reqIpAddr?: string
6
13
  username?: string
14
+ userId?: string
7
15
  userRealName?: string
8
16
  organizationName?: string
9
17
  orgName?: string
@@ -54,11 +62,18 @@ export type AuthTokenResponse = AuthTokenPayload & {
54
62
  let refreshTokenPromise: Promise<string> | null = null
55
63
 
56
64
  export function getAccessTokenFromResponse(response: AuthTokenResponse) {
57
- return response.data?.token || response.data?.access_token || response.token || response.access_token
65
+ return (
66
+ response.data?.token || response.data?.access_token || response.token || response.access_token
67
+ )
58
68
  }
59
69
 
60
70
  export function getRefreshTokenFromResponse(response: AuthTokenResponse) {
61
- return response.data?.refresh_token || response.data?.refreshToken || response.refresh_token || response.refreshToken
71
+ return (
72
+ response.data?.refresh_token ||
73
+ response.data?.refreshToken ||
74
+ response.refresh_token ||
75
+ response.refreshToken
76
+ )
62
77
  }
63
78
 
64
79
  export function getStoredAccessToken() {
@@ -81,16 +96,18 @@ export function getAuthHeaders(headers?: Record<string, string>, skipAuth = fals
81
96
  }
82
97
 
83
98
  export function saveAuthTokens(response: AuthTokenResponse) {
99
+ const payload = getAuthPayloadFromResponse(response)
100
+ const payloadForStorage = sanitizeAuthPayload(payload)
84
101
  const token = getAccessTokenFromResponse(response)
85
102
  const refreshToken = getRefreshTokenFromResponse(response)
86
- const principal = getPrincipalFromResponse(response)
103
+ const principal = payload.principal
87
104
 
88
105
  if (!token) {
89
106
  throw new Error('接口未返回业务 token')
90
107
  }
91
108
 
92
109
  const userStore = useUserStore()
93
- userStore.setAuthTokens(token, refreshToken)
110
+ userStore.setAuthTokens(token, refreshToken, payloadForStorage)
94
111
  userStore.setUserInfo({
95
112
  username: principal?.username,
96
113
  realName: principal?.userRealName,
@@ -100,8 +117,35 @@ export function saveAuthTokens(response: AuthTokenResponse) {
100
117
  return token
101
118
  }
102
119
 
103
- function getPrincipalFromResponse(response: AuthTokenResponse) {
104
- return response.data?.principal || response.principal
120
+ function getAuthPayloadFromResponse(response: AuthTokenResponse) {
121
+ // 登录接口可能直接返回 token,也可能包一层 data;这里统一取真正的认证载荷。
122
+ if (isAuthPayload(response.data)) {
123
+ return response.data
124
+ }
125
+
126
+ return response
127
+ }
128
+
129
+ function isAuthPayload(payload?: AuthTokenPayload): payload is AuthTokenPayload {
130
+ return Boolean(
131
+ payload &&
132
+ (payload.token ||
133
+ payload.access_token ||
134
+ payload.refresh_token ||
135
+ payload.refreshToken ||
136
+ payload.principal),
137
+ )
138
+ }
139
+
140
+ function sanitizeAuthPayload(payload: AuthTokenPayload): AuthTokenPayload {
141
+ if (!payload.principal) return payload
142
+
143
+ // 后端 principal 里会带 password 哈希,本地只保存业务需要的用户信息。
144
+ const { password: _password, ...principal } = payload.principal
145
+ return {
146
+ ...payload,
147
+ principal,
148
+ }
105
149
  }
106
150
 
107
151
  function getOrganizationNameFromPrincipal(principal?: AuthPrincipal) {
@@ -82,8 +82,8 @@ service.interceptors.response.use(
82
82
  // 普通业务接口返回 { code, message, data };OAuth 登录接口直接返回 token 结构。
83
83
  const res = response.data
84
84
 
85
- // 只有响应体明确包含 code 字段时,才按统一业务格式判断。
86
- if (typeof res.code !== 'undefined' && res.code !== 0) {
85
+ // 只有响应体明确包含 code 字段时,才按统一业务格式判断,兼容 0 和 "0000" 两种成功码。
86
+ if (typeof res.code !== 'undefined' && !isSuccessCode(res.code)) {
87
87
  showToast(res.message || '请求失败')
88
88
 
89
89
  // 将业务错误抛出,调用方可通过 catch 捕获
@@ -130,9 +130,7 @@ service.interceptors.response.use(
130
130
 
131
131
  // 优先取映射表中的提示,没有则显示状态码;无 response 说明是网络异常
132
132
  const status = error.response?.status as number
133
- const message = error.response
134
- ? statusCodeMap[status] || `连接错误 ${status}`
135
- : '网络连接异常'
133
+ const message = error.response ? statusCodeMap[status] || `连接错误 ${status}` : '网络连接异常'
136
134
 
137
135
  showToast(message)
138
136
 
@@ -150,6 +148,10 @@ function shouldRefreshToken(config: AuthAxiosRequestConfig) {
150
148
  return !config.skipAuth && !config._retry && Boolean(getStoredRefreshToken())
151
149
  }
152
150
 
151
+ function isSuccessCode(code: ApiResponse['code']) {
152
+ return code === 0 || code === '0' || code === '0000'
153
+ }
154
+
153
155
  async function requestRefreshTokenByAxios() {
154
156
  const refreshToken = getStoredRefreshToken()
155
157
 
@@ -215,7 +217,9 @@ export interface RequestConfig<T = unknown> {
215
217
  * data: { username: 'admin', password: '123' }
216
218
  * })
217
219
  */
218
- export function request<R = unknown, T = unknown>(config: RequestConfig<T>): Promise<ApiResponse<R>> {
220
+ export function request<R = unknown, T = unknown>(
221
+ config: RequestConfig<T>,
222
+ ): Promise<ApiResponse<R>> {
219
223
  const axiosConfig: AuthAxiosRequestConfig<T> = {
220
224
  url: config.url,
221
225
  method: config.method || 'GET',
@@ -1,13 +1,15 @@
1
1
  <script setup lang="ts">
2
2
  import { useRouter } from 'vue-router'
3
- import { loginApi, loginByAppTokenApi } from '@/api/user'
3
+ import { getOrgByUserNameApi, loginApi, loginByAppTokenApi } from '@/api/user'
4
4
  import { showToast } from 'vant'
5
5
  import { useAppStore } from '@/stores/app'
6
+ import { useUserStore } from '@/stores/user'
6
7
  import { getAppToken } from '@/core/mxApi'
7
8
  import { saveAuthTokens, type AuthTokenResponse } from '@/utils/auth-token'
8
9
 
9
10
  const router = useRouter()
10
11
  const appStore = useAppStore()
12
+ const userStore = useUserStore()
11
13
 
12
14
  const form = ref({
13
15
  username: '',
@@ -17,6 +19,7 @@ const form = ref({
17
19
  const loading = ref(false)
18
20
  const appVersion = __APP_VERSION__
19
21
  const APP_TOKEN_TIMEOUT = 30000
22
+ const LOGIN_UNAVAILABLE_MESSAGE = '抱歉暂时无法登录'
20
23
 
21
24
  onMounted(() => {
22
25
  if (!appStore.isNative) return
@@ -29,12 +32,14 @@ async function loginWithAppToken() {
29
32
  try {
30
33
  const appToken = await getAppTokenWithTimeout()
31
34
  const res = await loginByAppTokenApi(appToken)
32
- saveBusinessToken(res)
35
+ await saveBusinessTokenAndOrg(res)
33
36
  showToast('登录成功')
34
37
  router.push('/')
35
38
  } catch (error) {
36
39
  console.error('[登录页] APP token 自动登录失败', error)
37
- showToast({ message: 'APP 自动登录失败,请手动登录', duration: 3000 })
40
+ if (!isLoginUnavailableError(error)) {
41
+ showToast({ message: 'APP 自动登录失败,请手动登录', duration: 3000 })
42
+ }
38
43
  appStore.isNative = false
39
44
  } finally {
40
45
  loading.value = false
@@ -56,18 +61,53 @@ async function onSubmit() {
56
61
  loading.value = true
57
62
  try {
58
63
  const res = await loginApi(form.value)
59
- saveBusinessToken(res)
64
+ await saveBusinessTokenAndOrg(res)
60
65
  showToast('登录成功')
61
66
  router.push('/')
62
- } catch {
67
+ } catch (error) {
68
+ if (!isLoginUnavailableError(error)) {
69
+ console.error('[登录页] 账号密码登录失败', error)
70
+ }
63
71
  // 错误已由 request.ts 拦截器统一处理
64
72
  } finally {
65
73
  loading.value = false
66
74
  }
67
75
  }
68
76
 
69
- function saveBusinessToken(response: unknown) {
77
+ async function saveBusinessTokenAndOrg(response: unknown) {
78
+ // 先保存 token,后续机构接口需要携带 Authorization 访问。
70
79
  saveAuthTokens(response as AuthTokenResponse)
80
+
81
+ try {
82
+ const username = userStore.username.trim()
83
+ if (!username) {
84
+ rejectLoginWithoutOrg()
85
+ }
86
+
87
+ const orgResponse = await getOrgByUserNameApi(username)
88
+ // 后端约定第一条机构就是当前登录机构;空数组表示该用户暂不可进入系统。
89
+ const firstOrg = Array.isArray(orgResponse.data) ? orgResponse.data[0] : undefined
90
+
91
+ if (!firstOrg) {
92
+ rejectLoginWithoutOrg()
93
+ }
94
+
95
+ // 机构列表第一条就是当前用户本次登录机构,保存后供 TAM 公共 head 使用。
96
+ userStore.setLoginOrg(firstOrg)
97
+ } catch (error) {
98
+ // 机构校验失败时撤销刚保存的登录态,避免后续路由误认为已登录。
99
+ userStore.clearToken()
100
+ throw error
101
+ }
102
+ }
103
+
104
+ function rejectLoginWithoutOrg(): never {
105
+ showToast(LOGIN_UNAVAILABLE_MESSAGE)
106
+ throw new Error(LOGIN_UNAVAILABLE_MESSAGE)
107
+ }
108
+
109
+ function isLoginUnavailableError(error: unknown) {
110
+ return error instanceof Error && error.message === LOGIN_UNAVAILABLE_MESSAGE
71
111
  }
72
112
  </script>
73
113
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verce-vue-test",
3
- "version": "0.0.54",
3
+ "version": "0.0.55",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,287 +0,0 @@
1
- import dayjs from 'dayjs'
2
-
3
- export type RmbForecastRecord = {
4
- busiType?: string
5
- clientName?: string
6
- clientType?: string
7
- competAcct?: string
8
- competName?: string
9
- groundBranch?: string
10
- payChannel?: string
11
- payDirec?: string
12
- predAmt?: string
13
- predDate?: string
14
- predRefNo?: string
15
- predStatus?: string
16
- tranDate?: string
17
- verifyAmt?: string
18
- verifyStatus?: string
19
- }
20
-
21
- export type RmbForecastQueryForm = {
22
- tranDate: string
23
- groundBranch?: string
24
- startTranAmt?: string
25
- endTranAmt?: string
26
- busiType?: string
27
- clientName?: string
28
- competName?: string
29
- payChannel?: string
30
- payDirec?: string
31
- predStatus?: string
32
- sortRule?: string
33
- verifyStatus?: string
34
- }
35
-
36
- export type RmbForecastQueryPayload = {
37
- appHead: {
38
- fileName: string
39
- opType: string
40
- ip: string
41
- }
42
- body: {
43
- tranDate: string
44
- busiType: string
45
- clientName: string
46
- competName: string
47
- groundBranch: string
48
- payChannel: string
49
- endTranAmt: number | null
50
- payDirec: string
51
- predStatus: string
52
- sortRule: string
53
- startTranAmt: number | null
54
- verifyStatus: string
55
- }
56
- head: {
57
- adminUserId: string
58
- apprUserId: string
59
- areaCode: string
60
- branchId: string
61
- consumerId: string
62
- consumerSeqNo: string
63
- digitalSign: string
64
- fileFlag: string
65
- filePath: string
66
- isBatch: boolean
67
- pageIndex: number
68
- pageSize: number
69
- spanId: string
70
- traceId: string
71
- tranCode: string
72
- tranDate: string
73
- tranTimeStamp: string
74
- userId: string
75
- verifyUserId: string
76
- versionId: string
77
- }
78
- }
79
-
80
- export type RmbForecastQueryResult = {
81
- body: {
82
- resultList: RmbForecastRecord[]
83
- totalCount: string
84
- }
85
- head: RmbForecastQueryPayload['head'] & {
86
- retCode: string
87
- retMsg: string
88
- retStatus: string
89
- }
90
- }
91
-
92
- type QueryOptions = {
93
- form: RmbForecastQueryForm
94
- pageIndex: number
95
- pageSize: number
96
- }
97
-
98
- const TRAN_CODE = '/TAM/0001/140101001'
99
- const DEFAULT_TOTAL = 251
100
-
101
- const baseMockRecords: RmbForecastRecord[] = [
102
- {
103
- busiType: '1',
104
- clientName: '铁运客户',
105
- clientType: '1',
106
- competAcct: '1',
107
- competName: '1',
108
- groundBranch: '沙雅支行营业部',
109
- payChannel: '1',
110
- payDirec: '1',
111
- predAmt: '1100000000',
112
- predDate: '20260512 10:50:42',
113
- predRefNo: '2026051201437066',
114
- predStatus: '2',
115
- verifyAmt: '0',
116
- verifyStatus: '1',
117
- },
118
- {
119
- busiType: '1',
120
- competName: '3234',
121
- groundBranch: '北京银行总行核算中心',
122
- payChannel: '1',
123
- payDirec: '1',
124
- predAmt: '0',
125
- verifyStatus: '1',
126
- },
127
- {
128
- busiType: '1',
129
- groundBranch: '北京银行股份有限公司北京分行',
130
- payChannel: '1',
131
- payDirec: '1',
132
- predAmt: '123',
133
- verifyStatus: '1',
134
- },
135
- {
136
- busiType: '5',
137
- competName: '111',
138
- groundBranch: '乌市营业部',
139
- payChannel: '1',
140
- payDirec: '1',
141
- predAmt: '0',
142
- verifyStatus: '1',
143
- },
144
- {
145
- busiType: '4',
146
- competName: 'ddd',
147
- competAcct: '123123124124',
148
- groundBranch: '北京银行总行核算中心',
149
- predAmt: '0',
150
- verifyStatus: '1',
151
- },
152
- {
153
- busiType: '7',
154
- competName: 'www',
155
- competAcct: '123214455123',
156
- groundBranch: '北京银行总行核算中心',
157
- predAmt: '0',
158
- verifyStatus: '1',
159
- },
160
- {
161
- busiType: '2',
162
- groundBranch: '北京银行总行核算中心',
163
- payChannel: '2',
164
- payDirec: '1',
165
- predAmt: '1234444444',
166
- verifyStatus: '1',
167
- },
168
- ]
169
-
170
- export function buildRmbForecastQueryPayload({
171
- form,
172
- pageIndex,
173
- pageSize,
174
- }: QueryOptions): RmbForecastQueryPayload {
175
- const now = dayjs()
176
- const tranDate = normalizeDate(form.tranDate)
177
-
178
- return {
179
- appHead: {
180
- fileName: '',
181
- opType: '',
182
- ip: '10.51.106.161',
183
- },
184
- body: {
185
- tranDate,
186
- busiType: form.busiType || '',
187
- clientName: form.clientName || '',
188
- competName: form.competName || '',
189
- groundBranch: form.groundBranch || '',
190
- payChannel: form.payChannel || '',
191
- endTranAmt: toRequestAmount(form.endTranAmt),
192
- payDirec: form.payDirec || '',
193
- predStatus: form.predStatus || '',
194
- sortRule: form.sortRule || '',
195
- startTranAmt: toRequestAmount(form.startTranAmt),
196
- verifyStatus: form.verifyStatus || '',
197
- },
198
- head: {
199
- adminUserId: '',
200
- apprUserId: '',
201
- areaCode: '0000',
202
- branchId: '25001',
203
- consumerId: 'TAM001',
204
- consumerSeqNo: `superuser6${now.format('YYYYMMDDHHmmssSSS')}`,
205
- digitalSign: '',
206
- fileFlag: 'N',
207
- filePath: '',
208
- isBatch: false,
209
- pageIndex,
210
- pageSize,
211
- spanId: '',
212
- traceId: '',
213
- tranCode: TRAN_CODE,
214
- tranDate: now.format('YYYYMMDD'),
215
- tranTimeStamp: now.format('HHmmss'),
216
- userId: 'superuser6',
217
- verifyUserId: '',
218
- versionId: '0001',
219
- },
220
- }
221
- }
222
-
223
- export async function queryRmbForecastPage(
224
- payload: RmbForecastQueryPayload,
225
- ): Promise<RmbForecastQueryResult> {
226
- const records = buildMockRecords(payload.body.tranDate)
227
- .filter((record) =>
228
- payload.body.groundBranch ? record.groundBranch?.includes(payload.body.groundBranch) : true,
229
- )
230
- .filter((record) => {
231
- const amount = Number(record.predAmt || 0)
232
- const matchesMin =
233
- payload.body.startTranAmt === null ? true : amount >= payload.body.startTranAmt
234
- const matchesMax = payload.body.endTranAmt === null ? true : amount <= payload.body.endTranAmt
235
-
236
- return matchesMin && matchesMax
237
- })
238
-
239
- const start = (payload.head.pageIndex - 1) * payload.head.pageSize
240
- const end = start + payload.head.pageSize
241
-
242
- await wait(220)
243
-
244
- return {
245
- body: {
246
- resultList: records.slice(start, end),
247
- totalCount: String(records.length),
248
- },
249
- head: {
250
- ...payload.head,
251
- retCode: '000000',
252
- retMsg: '交易成功',
253
- retStatus: 'S',
254
- },
255
- }
256
- }
257
-
258
- function buildMockRecords(tranDate: string) {
259
- return Array.from({ length: DEFAULT_TOTAL }, (_, index) => {
260
- const base = baseMockRecords[index % baseMockRecords.length]!
261
- const serial = String(index + 1).padStart(4, '0')
262
- const predAmt = base.predAmt === '0' ? String((index % 9) * 10000000) : base.predAmt
263
-
264
- return {
265
- ...base,
266
- predAmt,
267
- tranDate,
268
- predRefNo: base.predRefNo || `${tranDate}${serial}`,
269
- }
270
- })
271
- }
272
-
273
- function normalizeDate(value: string) {
274
- if (/^\d{8}$/.test(value)) return value
275
- return value.replaceAll('-', '')
276
- }
277
-
278
- function toRequestAmount(value?: string) {
279
- if (!value?.trim()) return null
280
-
281
- const amount = Number(value)
282
- return Number.isFinite(amount) ? Math.round(amount * 100000000) : null
283
- }
284
-
285
- function wait(ms: number) {
286
- return new Promise((resolve) => window.setTimeout(resolve, ms))
287
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes