verce-vue-test 0.0.48 → 0.0.49
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 +1 -1
- package/mini2.0/.editorconfig +0 -8
- package/mini2.0/.env.development +0 -3
- package/mini2.0/.env.production +0 -3
- package/mini2.0/.env.test +0 -3
- package/mini2.0/.gitattributes +0 -1
- package/mini2.0/.oxlintrc.json +0 -10
- package/mini2.0/.prettierrc.json +0 -6
- package/mini2.0/.vscode/extensions.json +0 -9
- package/mini2.0/README.md +0 -179
- package/mini2.0/auto-imports.d.ts +0 -629
- package/mini2.0/components.d.ts +0 -21
- package/mini2.0/design-qa.md +0 -36
- package/mini2.0/docs/MX_API.md +0 -244
- package/mini2.0/docs/REQUEST.md +0 -217
- package/mini2.0/docs/jsapi.js +0 -515
- package/mini2.0/docs/package-json-guide.md +0 -132
- package/mini2.0/env.d.ts +0 -15
- package/mini2.0/eslint.config.ts +0 -26
- package/mini2.0/index.html +0 -16
- package/mini2.0/package-lock.json +0 -6473
- package/mini2.0/package.json +0 -66
- package/mini2.0/plugins/bump-version.ts +0 -61
- package/mini2.0/postcss.config.ts +0 -15
- package/mini2.0/public/favicon.ico +0 -0
- package/mini2.0/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
- package/mini2.0/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
- package/mini2.0/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
- package/mini2.0/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
- package/mini2.0/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
- package/mini2.0/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
- package/mini2.0/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
- package/mini2.0/public/images/img.png +0 -0
- package/mini2.0/src/App.vue +0 -59
- package/mini2.0/src/api/health.ts +0 -13
- package/mini2.0/src/api/rmb-position.ts +0 -287
- package/mini2.0/src/api/user.ts +0 -54
- package/mini2.0/src/auto-imports.d.ts +0 -639
- package/mini2.0/src/components.d.ts +0 -30
- package/mini2.0/src/config/config.properties +0 -3
- package/mini2.0/src/config/env.ts +0 -6
- package/mini2.0/src/config/plugin.properties.pro +0 -6
- package/mini2.0/src/config/plugin.properties.test +0 -6
- package/mini2.0/src/core/mxApi/index.ts +0 -344
- package/mini2.0/src/core/request/index.ts +0 -135
- package/mini2.0/src/main.ts +0 -39
- package/mini2.0/src/router/index.ts +0 -77
- package/mini2.0/src/stores/app.ts +0 -24
- package/mini2.0/src/stores/counter.ts +0 -12
- package/mini2.0/src/stores/user.ts +0 -85
- package/mini2.0/src/types/api.d.ts +0 -14
- package/mini2.0/src/types/nprogress.d.ts +0 -8
- package/mini2.0/src/utils/auth-token.ts +0 -197
- package/mini2.0/src/utils/query.ts +0 -27
- package/mini2.0/src/utils/request.ts +0 -233
- package/mini2.0/src/views/clearing-detail/index.vue +0 -49
- package/mini2.0/src/views/foreign-position/index.vue +0 -49
- package/mini2.0/src/views/home/index.vue +0 -213
- package/mini2.0/src/views/login/index.vue +0 -202
- package/mini2.0/src/views/mine/index.vue +0 -143
- package/mini2.0/src/views/net-debit/index.vue +0 -49
- package/mini2.0/src/views/pbc-position/index.vue +0 -49
- package/mini2.0/src/views/position-estimate/index.vue +0 -49
- package/mini2.0/src/views/rmb-position/index.vue +0 -1042
- package/mini2.0/src/views/warning/index.vue +0 -49
- package/mini2.0/tsconfig.app.json +0 -18
- package/mini2.0/tsconfig.json +0 -11
- package/mini2.0/tsconfig.node.json +0 -28
- package/mini2.0/vite.config.ts +0 -98
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
|
|
3
|
-
const LEGACY_TOKEN_KEYS = ['token', 'refresh_token', 'user']
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 用户状态 Store
|
|
7
|
-
*
|
|
8
|
-
* 使用 Composition API 风格(setup 语法)定义。
|
|
9
|
-
* token 只保存在 Pinia 内存态中,刷新页面后需要重新登录或通过敏行自动登录恢复。
|
|
10
|
-
*/
|
|
11
|
-
export const useUserStore = defineStore(
|
|
12
|
-
'user',
|
|
13
|
-
|
|
14
|
-
() => {
|
|
15
|
-
// -------------------------------- State --------------------------------
|
|
16
|
-
|
|
17
|
-
/** 登录凭证,登录成功后由后端返回,后续请求通过请求头携带 */
|
|
18
|
-
const token = ref('1')
|
|
19
|
-
const refreshToken = ref('')
|
|
20
|
-
const username = ref('')
|
|
21
|
-
const realName = ref('')
|
|
22
|
-
const organizationName = ref('')
|
|
23
|
-
|
|
24
|
-
clearLegacyStoredTokens()
|
|
25
|
-
|
|
26
|
-
// ------------------------------ Actions --------------------------------
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 设置 token
|
|
30
|
-
* 登录成功或刷新 token 成功后调用。
|
|
31
|
-
*/
|
|
32
|
-
function setToken(value: string) {
|
|
33
|
-
token.value = value
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function setRefreshToken(value: string) {
|
|
37
|
-
refreshToken.value = value
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function setAuthTokens(accessToken: string, newRefreshToken?: string) {
|
|
41
|
-
setToken(accessToken)
|
|
42
|
-
|
|
43
|
-
if (newRefreshToken) {
|
|
44
|
-
setRefreshToken(newRefreshToken)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function setUserInfo(info: { username?: string; realName?: string; organizationName?: string }) {
|
|
49
|
-
username.value = info.username || username.value
|
|
50
|
-
realName.value = info.realName || realName.value
|
|
51
|
-
organizationName.value = info.organizationName || organizationName.value
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 清空 token
|
|
56
|
-
* 退出登录或刷新 token 失败时调用。
|
|
57
|
-
*/
|
|
58
|
-
function clearToken() {
|
|
59
|
-
token.value = ''
|
|
60
|
-
refreshToken.value = ''
|
|
61
|
-
username.value = ''
|
|
62
|
-
realName.value = ''
|
|
63
|
-
organizationName.value = ''
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// ----------------------------- Return ----------------------------------
|
|
67
|
-
|
|
68
|
-
return {
|
|
69
|
-
token,
|
|
70
|
-
refreshToken,
|
|
71
|
-
username,
|
|
72
|
-
realName,
|
|
73
|
-
organizationName,
|
|
74
|
-
setToken,
|
|
75
|
-
setRefreshToken,
|
|
76
|
-
setAuthTokens,
|
|
77
|
-
setUserInfo,
|
|
78
|
-
clearToken,
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
function clearLegacyStoredTokens() {
|
|
84
|
-
LEGACY_TOKEN_KEYS.forEach((key) => localStorage.removeItem(key))
|
|
85
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { useUserStore } from '@/stores/user'
|
|
2
|
-
|
|
3
|
-
export const REFRESH_TOKEN_URL = '/uaa/oauth/mobile/refresh_token'
|
|
4
|
-
|
|
5
|
-
export type AuthPrincipal = {
|
|
6
|
-
username?: string
|
|
7
|
-
userRealName?: string
|
|
8
|
-
organizationName?: string
|
|
9
|
-
orgName?: string
|
|
10
|
-
org_name?: string
|
|
11
|
-
currentOrgName?: string
|
|
12
|
-
current_org_name?: string
|
|
13
|
-
institutionName?: string
|
|
14
|
-
institution_name?: string
|
|
15
|
-
branchName?: string
|
|
16
|
-
branch_name?: string
|
|
17
|
-
deptName?: string
|
|
18
|
-
dept_name?: string
|
|
19
|
-
departmentName?: string
|
|
20
|
-
department_name?: string
|
|
21
|
-
unitName?: string
|
|
22
|
-
unit_name?: string
|
|
23
|
-
agencyName?: string
|
|
24
|
-
agency_name?: string
|
|
25
|
-
bankName?: string
|
|
26
|
-
bank_name?: string
|
|
27
|
-
organization?: unknown
|
|
28
|
-
org?: unknown
|
|
29
|
-
institution?: unknown
|
|
30
|
-
branch?: unknown
|
|
31
|
-
dept?: unknown
|
|
32
|
-
department?: unknown
|
|
33
|
-
unit?: unknown
|
|
34
|
-
agency?: unknown
|
|
35
|
-
bank?: unknown
|
|
36
|
-
[key: string]: unknown
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type AuthTokenPayload = {
|
|
40
|
-
token?: string
|
|
41
|
-
access_token?: string
|
|
42
|
-
refresh_token?: string
|
|
43
|
-
refreshToken?: string
|
|
44
|
-
token_type?: string
|
|
45
|
-
expires_in?: number
|
|
46
|
-
scope?: string
|
|
47
|
-
principal?: AuthPrincipal
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export type AuthTokenResponse = AuthTokenPayload & {
|
|
51
|
-
data?: AuthTokenPayload
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
let refreshTokenPromise: Promise<string> | null = null
|
|
55
|
-
|
|
56
|
-
export function getAccessTokenFromResponse(response: AuthTokenResponse) {
|
|
57
|
-
return response.data?.token || response.data?.access_token || response.token || response.access_token
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getRefreshTokenFromResponse(response: AuthTokenResponse) {
|
|
61
|
-
return response.data?.refresh_token || response.data?.refreshToken || response.refresh_token || response.refreshToken
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getStoredAccessToken() {
|
|
65
|
-
return useUserStore().token
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export function getStoredRefreshToken() {
|
|
69
|
-
return useUserStore().refreshToken
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export function getAuthHeaders(headers?: Record<string, string>, skipAuth = false) {
|
|
73
|
-
const token = getStoredAccessToken()
|
|
74
|
-
|
|
75
|
-
return {
|
|
76
|
-
'Content-Type': 'application/json',
|
|
77
|
-
Accept: 'application/json',
|
|
78
|
-
...(!skipAuth && token ? { Authorization: `Bearer ${token}` } : {}),
|
|
79
|
-
...headers,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export function saveAuthTokens(response: AuthTokenResponse) {
|
|
84
|
-
const token = getAccessTokenFromResponse(response)
|
|
85
|
-
const refreshToken = getRefreshTokenFromResponse(response)
|
|
86
|
-
const principal = getPrincipalFromResponse(response)
|
|
87
|
-
|
|
88
|
-
if (!token) {
|
|
89
|
-
throw new Error('接口未返回业务 token')
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
const userStore = useUserStore()
|
|
93
|
-
userStore.setAuthTokens(token, refreshToken)
|
|
94
|
-
userStore.setUserInfo({
|
|
95
|
-
username: principal?.username,
|
|
96
|
-
realName: principal?.userRealName,
|
|
97
|
-
organizationName: getOrganizationNameFromPrincipal(principal),
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
return token
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getPrincipalFromResponse(response: AuthTokenResponse) {
|
|
104
|
-
return response.data?.principal || response.principal
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function getOrganizationNameFromPrincipal(principal?: AuthPrincipal) {
|
|
108
|
-
if (!principal) return undefined
|
|
109
|
-
|
|
110
|
-
return firstText(
|
|
111
|
-
principal.organizationName,
|
|
112
|
-
principal.orgName,
|
|
113
|
-
principal.org_name,
|
|
114
|
-
principal.currentOrgName,
|
|
115
|
-
principal.current_org_name,
|
|
116
|
-
principal.institutionName,
|
|
117
|
-
principal.institution_name,
|
|
118
|
-
principal.branchName,
|
|
119
|
-
principal.branch_name,
|
|
120
|
-
principal.deptName,
|
|
121
|
-
principal.dept_name,
|
|
122
|
-
principal.departmentName,
|
|
123
|
-
principal.department_name,
|
|
124
|
-
principal.unitName,
|
|
125
|
-
principal.unit_name,
|
|
126
|
-
principal.agencyName,
|
|
127
|
-
principal.agency_name,
|
|
128
|
-
principal.bankName,
|
|
129
|
-
principal.bank_name,
|
|
130
|
-
principal.organization,
|
|
131
|
-
principal.org,
|
|
132
|
-
principal.institution,
|
|
133
|
-
principal.branch,
|
|
134
|
-
principal.dept,
|
|
135
|
-
principal.department,
|
|
136
|
-
principal.unit,
|
|
137
|
-
principal.agency,
|
|
138
|
-
principal.bank,
|
|
139
|
-
getNameFromRecord(principal.organization),
|
|
140
|
-
getNameFromRecord(principal.org),
|
|
141
|
-
getNameFromRecord(principal.institution),
|
|
142
|
-
getNameFromRecord(principal.branch),
|
|
143
|
-
getNameFromRecord(principal.dept),
|
|
144
|
-
getNameFromRecord(principal.department),
|
|
145
|
-
getNameFromRecord(principal.unit),
|
|
146
|
-
getNameFromRecord(principal.agency),
|
|
147
|
-
getNameFromRecord(principal.bank),
|
|
148
|
-
)
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
function getNameFromRecord(value: unknown) {
|
|
152
|
-
if (!isRecord(value)) return undefined
|
|
153
|
-
|
|
154
|
-
return firstText(
|
|
155
|
-
value.name,
|
|
156
|
-
value.organizationName,
|
|
157
|
-
value.orgName,
|
|
158
|
-
value.institutionName,
|
|
159
|
-
value.branchName,
|
|
160
|
-
value.deptName,
|
|
161
|
-
value.departmentName,
|
|
162
|
-
value.unitName,
|
|
163
|
-
value.agencyName,
|
|
164
|
-
value.bankName,
|
|
165
|
-
)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
function firstText(...values: unknown[]) {
|
|
169
|
-
for (const value of values) {
|
|
170
|
-
if (typeof value !== 'string') continue
|
|
171
|
-
|
|
172
|
-
const text = value.trim()
|
|
173
|
-
if (text) return text
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
return undefined
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
180
|
-
return typeof value === 'object' && value !== null
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
export function clearAuthTokens() {
|
|
184
|
-
useUserStore().clearToken()
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
export function refreshAccessToken(requestRefreshToken: () => Promise<AuthTokenResponse>) {
|
|
188
|
-
if (!refreshTokenPromise) {
|
|
189
|
-
refreshTokenPromise = requestRefreshToken()
|
|
190
|
-
.then(saveAuthTokens)
|
|
191
|
-
.finally(() => {
|
|
192
|
-
refreshTokenPromise = null
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return refreshTokenPromise
|
|
197
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 将 query 对象拼接到 URL 上
|
|
3
|
-
*
|
|
4
|
-
* 自动过滤 undefined/null 值,支持数组参数。
|
|
5
|
-
*/
|
|
6
|
-
export function appendQuery(url: string, query?: Record<string, unknown>): string {
|
|
7
|
-
if (!query) return url
|
|
8
|
-
|
|
9
|
-
const searchParams = new URLSearchParams()
|
|
10
|
-
Object.entries(query).forEach(([key, value]) => {
|
|
11
|
-
if (value === undefined || value === null) return
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
value.forEach((item) => {
|
|
14
|
-
if (item !== undefined && item !== null) {
|
|
15
|
-
searchParams.append(key, String(item))
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
searchParams.append(key, String(value))
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
const queryString = searchParams.toString()
|
|
24
|
-
if (!queryString) return url
|
|
25
|
-
|
|
26
|
-
return `${url}${url.includes('?') ? '&' : '?'}${queryString}`
|
|
27
|
-
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
import axios from 'axios'
|
|
2
|
-
import type {
|
|
3
|
-
AxiosError,
|
|
4
|
-
AxiosInstance,
|
|
5
|
-
AxiosRequestConfig,
|
|
6
|
-
AxiosResponse,
|
|
7
|
-
InternalAxiosRequestConfig,
|
|
8
|
-
} from 'axios'
|
|
9
|
-
import { showToast } from 'vant'
|
|
10
|
-
import NProgress from 'nprogress'
|
|
11
|
-
import 'nprogress/nprogress.css'
|
|
12
|
-
import { apiConfig } from '@/config/env'
|
|
13
|
-
import type { ApiResponse } from '@/types/api'
|
|
14
|
-
import router from '@/router'
|
|
15
|
-
import {
|
|
16
|
-
clearAuthTokens,
|
|
17
|
-
getStoredAccessToken,
|
|
18
|
-
getStoredRefreshToken,
|
|
19
|
-
REFRESH_TOKEN_URL,
|
|
20
|
-
refreshAccessToken,
|
|
21
|
-
type AuthTokenResponse,
|
|
22
|
-
} from '@/utils/auth-token'
|
|
23
|
-
|
|
24
|
-
// 关闭 NProgress 右侧旋转小圆圈,保持进度条简洁
|
|
25
|
-
NProgress.configure({ showSpinner: false })
|
|
26
|
-
|
|
27
|
-
interface AuthRequestConfig extends InternalAxiosRequestConfig {
|
|
28
|
-
skipAuth?: boolean
|
|
29
|
-
_retry?: boolean
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface AuthAxiosRequestConfig<T = unknown> extends AxiosRequestConfig<T> {
|
|
33
|
-
skipAuth?: boolean
|
|
34
|
-
_retry?: boolean
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// 创建 axios 实例,baseURL 和 timeout 从环境变量配置中读取
|
|
38
|
-
const service: AxiosInstance = axios.create({
|
|
39
|
-
baseURL: apiConfig.baseURL, // 接口基础地址,由 .env 文件中的 VITE_API_BASE_URL 决定
|
|
40
|
-
timeout: apiConfig.timeout, // 请求超时时间(毫秒),默认 10000
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 请求拦截器
|
|
45
|
-
* 在每个请求发出前执行:
|
|
46
|
-
* 1. 启动顶部进度条
|
|
47
|
-
* 2. 自动携带 JWT token 到请求头
|
|
48
|
-
*/
|
|
49
|
-
service.interceptors.request.use(
|
|
50
|
-
(config: AuthRequestConfig) => {
|
|
51
|
-
// 开始加载进度条
|
|
52
|
-
NProgress.start()
|
|
53
|
-
|
|
54
|
-
// 从 Pinia 读取 token,存在则添加到请求头
|
|
55
|
-
const token = getStoredAccessToken()
|
|
56
|
-
if (!config.skipAuth && token) {
|
|
57
|
-
config.headers.Authorization = `Bearer ${token}`
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
return config
|
|
61
|
-
},
|
|
62
|
-
// 请求配置出错时(如网络断开),结束进度条并抛出错误
|
|
63
|
-
(error) => {
|
|
64
|
-
NProgress.done()
|
|
65
|
-
return Promise.reject(error)
|
|
66
|
-
},
|
|
67
|
-
)
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* 响应拦截器
|
|
71
|
-
* 在收到响应后执行:
|
|
72
|
-
* 1. 结束进度条
|
|
73
|
-
* 2. 判断后端业务 code,非 0 视为业务失败
|
|
74
|
-
* 3. HTTP 状态码异常时给出中文提示
|
|
75
|
-
* 4. 401 统一清除 token 并跳转登录页
|
|
76
|
-
*/
|
|
77
|
-
service.interceptors.response.use(
|
|
78
|
-
// ——— 成功响应(HTTP 2xx)———
|
|
79
|
-
(response: AxiosResponse<ApiResponse>) => {
|
|
80
|
-
NProgress.done()
|
|
81
|
-
|
|
82
|
-
// 普通业务接口返回 { code, message, data };OAuth 登录接口直接返回 token 结构。
|
|
83
|
-
const res = response.data
|
|
84
|
-
|
|
85
|
-
// 只有响应体明确包含 code 字段时,才按统一业务格式判断。
|
|
86
|
-
if (typeof res.code !== 'undefined' && res.code !== 0) {
|
|
87
|
-
showToast(res.message || '请求失败')
|
|
88
|
-
|
|
89
|
-
// 将业务错误抛出,调用方可通过 catch 捕获
|
|
90
|
-
return Promise.reject(new Error(res.message || '请求失败'))
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
// 业务成功,直接返回 data 字段,调用方无需再解包 response.data.data
|
|
94
|
-
return res as unknown as AxiosResponse
|
|
95
|
-
},
|
|
96
|
-
|
|
97
|
-
// ——— 失败响应(HTTP 非 2xx 或网络错误)———
|
|
98
|
-
async (error: AxiosError) => {
|
|
99
|
-
NProgress.done()
|
|
100
|
-
|
|
101
|
-
const originalConfig = error.config as AuthAxiosRequestConfig | undefined
|
|
102
|
-
|
|
103
|
-
if (error.response?.status === 401 && originalConfig && shouldRefreshToken(originalConfig)) {
|
|
104
|
-
try {
|
|
105
|
-
const token = await refreshAccessToken(requestRefreshTokenByAxios)
|
|
106
|
-
|
|
107
|
-
originalConfig._retry = true
|
|
108
|
-
originalConfig.headers = {
|
|
109
|
-
...originalConfig.headers,
|
|
110
|
-
Authorization: `Bearer ${token}`,
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return service.request(originalConfig)
|
|
114
|
-
} catch (refreshError) {
|
|
115
|
-
clearAuthTokens()
|
|
116
|
-
router.push('/login')
|
|
117
|
-
showToast('登录已过期,请重新登录')
|
|
118
|
-
return Promise.reject(refreshError)
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// HTTP 状态码 → 中文提示映射表
|
|
123
|
-
const statusCodeMap: Record<number, string> = {
|
|
124
|
-
400: '请求参数错误',
|
|
125
|
-
401: '未授权,请重新登录',
|
|
126
|
-
403: '拒绝访问',
|
|
127
|
-
404: '请求资源不存在',
|
|
128
|
-
500: '服务器内部错误',
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// 优先取映射表中的提示,没有则显示状态码;无 response 说明是网络异常
|
|
132
|
-
const status = error.response?.status as number
|
|
133
|
-
const message = error.response
|
|
134
|
-
? statusCodeMap[status] || `连接错误 ${status}`
|
|
135
|
-
: '网络连接异常'
|
|
136
|
-
|
|
137
|
-
showToast(message)
|
|
138
|
-
|
|
139
|
-
// 401 未授权:清除 token 并跳转登录页
|
|
140
|
-
if (error.response?.status === 401) {
|
|
141
|
-
clearAuthTokens()
|
|
142
|
-
router.push('/login')
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return Promise.reject(error)
|
|
146
|
-
},
|
|
147
|
-
)
|
|
148
|
-
|
|
149
|
-
function shouldRefreshToken(config: AuthAxiosRequestConfig) {
|
|
150
|
-
return !config.skipAuth && !config._retry && Boolean(getStoredRefreshToken())
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async function requestRefreshTokenByAxios() {
|
|
154
|
-
const refreshToken = getStoredRefreshToken()
|
|
155
|
-
|
|
156
|
-
if (!refreshToken) {
|
|
157
|
-
throw new Error('本地不存在 refresh token')
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
const response = await axios.request<ApiResponse<AuthTokenResponse> & AuthTokenResponse>({
|
|
161
|
-
baseURL: apiConfig.baseURL,
|
|
162
|
-
timeout: apiConfig.timeout,
|
|
163
|
-
url: REFRESH_TOKEN_URL,
|
|
164
|
-
method: 'POST',
|
|
165
|
-
data: {
|
|
166
|
-
refreshToken,
|
|
167
|
-
},
|
|
168
|
-
headers: {
|
|
169
|
-
'Content-Type': 'application/json',
|
|
170
|
-
Accept: 'application/json',
|
|
171
|
-
},
|
|
172
|
-
})
|
|
173
|
-
|
|
174
|
-
const result = response.data
|
|
175
|
-
|
|
176
|
-
if (typeof result.code === 'number' && result.code !== 0) {
|
|
177
|
-
throw new Error(result.message || '刷新 token 失败')
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
return result.data || result
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 请求配置接口
|
|
185
|
-
* @property url - 请求地址(必填)
|
|
186
|
-
* @property method - 请求方法,默认 GET
|
|
187
|
-
* @property data - 请求体(POST/PUT/PATCH 时使用)
|
|
188
|
-
* @property params - URL 查询参数(拼接到 ?key=value)
|
|
189
|
-
*/
|
|
190
|
-
export interface RequestConfig<T = unknown> {
|
|
191
|
-
url: string
|
|
192
|
-
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH'
|
|
193
|
-
data?: T
|
|
194
|
-
params?: Record<string, unknown>
|
|
195
|
-
headers?: Record<string, string>
|
|
196
|
-
auth?: { username: string; password: string } // HTTP Basic Auth
|
|
197
|
-
skipAuth?: boolean
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* 通用请求函数
|
|
202
|
-
* @typeParam R - 响应 data 的类型(后端返回的 data 字段类型)
|
|
203
|
-
* @typeParam T - 请求参数的类型(data 的类型)
|
|
204
|
-
* @param config - 请求配置对象
|
|
205
|
-
* @returns Promise,resolve 后直接拿到 ApiResponse<R>
|
|
206
|
-
*
|
|
207
|
-
* @example
|
|
208
|
-
* // GET 请求
|
|
209
|
-
* request<UserInfo>({ url: '/user/1' })
|
|
210
|
-
*
|
|
211
|
-
* // POST 请求
|
|
212
|
-
* request<{ token: string }, LoginParams>({
|
|
213
|
-
* url: '/login',
|
|
214
|
-
* method: 'POST',
|
|
215
|
-
* data: { username: 'admin', password: '123' }
|
|
216
|
-
* })
|
|
217
|
-
*/
|
|
218
|
-
export function request<R = unknown, T = unknown>(config: RequestConfig<T>): Promise<ApiResponse<R>> {
|
|
219
|
-
const axiosConfig: AuthAxiosRequestConfig<T> = {
|
|
220
|
-
url: config.url,
|
|
221
|
-
method: config.method || 'GET',
|
|
222
|
-
data: config.data,
|
|
223
|
-
params: config.params,
|
|
224
|
-
headers: config.headers,
|
|
225
|
-
auth: config.auth,
|
|
226
|
-
skipAuth: config.skipAuth,
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
return service.request<ApiResponse<R>>(axiosConfig) as unknown as Promise<ApiResponse<R>>
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// 同时导出 axios 实例,供需要直接使用 axios 原生方法的场景(如文件上传)
|
|
233
|
-
export default service
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts"></script>
|
|
2
|
-
|
|
3
|
-
<template>
|
|
4
|
-
<main class="page">
|
|
5
|
-
<header class="page-header">
|
|
6
|
-
<button class="back-btn" type="button" @click="$router.back()">←</button>
|
|
7
|
-
<h1>人民币小额网银清算场次明细</h1>
|
|
8
|
-
</header>
|
|
9
|
-
<section class="page-body">
|
|
10
|
-
<p class="placeholder">页面建设中…</p>
|
|
11
|
-
</section>
|
|
12
|
-
</main>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<style scoped>
|
|
16
|
-
.page {
|
|
17
|
-
max-width: 750px;
|
|
18
|
-
min-height: 100vh;
|
|
19
|
-
margin: 0 auto;
|
|
20
|
-
padding: 0 11px;
|
|
21
|
-
background: #f7f8fa;
|
|
22
|
-
}
|
|
23
|
-
.page-header {
|
|
24
|
-
display: flex;
|
|
25
|
-
align-items: center;
|
|
26
|
-
gap: 8px;
|
|
27
|
-
height: 48px;
|
|
28
|
-
}
|
|
29
|
-
.back-btn {
|
|
30
|
-
border: 0;
|
|
31
|
-
background: transparent;
|
|
32
|
-
font-size: 20px;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
.page-header h1 {
|
|
36
|
-
margin: 0;
|
|
37
|
-
font-size: 17px;
|
|
38
|
-
font-weight: 700;
|
|
39
|
-
}
|
|
40
|
-
.page-body {
|
|
41
|
-
padding: 24px 0;
|
|
42
|
-
}
|
|
43
|
-
.placeholder {
|
|
44
|
-
text-align: center;
|
|
45
|
-
color: #969799;
|
|
46
|
-
font-size: 14px;
|
|
47
|
-
padding-top: 120px;
|
|
48
|
-
}
|
|
49
|
-
</style>
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
<script setup lang="ts"></script>
|
|
2
|
-
|
|
3
|
-
<template>
|
|
4
|
-
<main class="page">
|
|
5
|
-
<header class="page-header">
|
|
6
|
-
<button class="back-btn" type="button" @click="$router.back()">←</button>
|
|
7
|
-
<h1>外币头寸预报及查询</h1>
|
|
8
|
-
</header>
|
|
9
|
-
<section class="page-body">
|
|
10
|
-
<p class="placeholder">页面建设中…</p>
|
|
11
|
-
</section>
|
|
12
|
-
</main>
|
|
13
|
-
</template>
|
|
14
|
-
|
|
15
|
-
<style scoped>
|
|
16
|
-
.page {
|
|
17
|
-
max-width: 750px;
|
|
18
|
-
min-height: 100vh;
|
|
19
|
-
margin: 0 auto;
|
|
20
|
-
padding: 0 11px;
|
|
21
|
-
background: #f7f8fa;
|
|
22
|
-
}
|
|
23
|
-
.page-header {
|
|
24
|
-
display: flex;
|
|
25
|
-
align-items: center;
|
|
26
|
-
gap: 8px;
|
|
27
|
-
height: 48px;
|
|
28
|
-
}
|
|
29
|
-
.back-btn {
|
|
30
|
-
border: 0;
|
|
31
|
-
background: transparent;
|
|
32
|
-
font-size: 20px;
|
|
33
|
-
cursor: pointer;
|
|
34
|
-
}
|
|
35
|
-
.page-header h1 {
|
|
36
|
-
margin: 0;
|
|
37
|
-
font-size: 17px;
|
|
38
|
-
font-weight: 700;
|
|
39
|
-
}
|
|
40
|
-
.page-body {
|
|
41
|
-
padding: 24px 0;
|
|
42
|
-
}
|
|
43
|
-
.placeholder {
|
|
44
|
-
text-align: center;
|
|
45
|
-
color: #969799;
|
|
46
|
-
font-size: 14px;
|
|
47
|
-
padding-top: 120px;
|
|
48
|
-
}
|
|
49
|
-
</style>
|