verce-vue-test 0.0.38 → 0.0.39
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/888/mini2.0-main/.editorconfig +8 -0
- package/888/mini2.0-main/.env.development +3 -0
- package/888/mini2.0-main/.env.production +3 -0
- package/888/mini2.0-main/.env.test +3 -0
- package/888/mini2.0-main/.gitattributes +1 -0
- package/888/mini2.0-main/.oxlintrc.json +10 -0
- package/888/mini2.0-main/.prettierrc.json +6 -0
- package/888/mini2.0-main/.vscode/extensions.json +9 -0
- package/888/mini2.0-main/README.md +179 -0
- package/888/mini2.0-main/auto-imports.d.ts +629 -0
- package/888/mini2.0-main/components.d.ts +21 -0
- package/888/mini2.0-main/design-qa.md +36 -0
- package/888/mini2.0-main/docs/MX_API.md +244 -0
- package/888/mini2.0-main/docs/REQUEST.md +217 -0
- package/888/mini2.0-main/docs/jsapi.js +515 -0
- package/888/mini2.0-main/docs/package-json-guide.md +132 -0
- package/888/mini2.0-main/env.d.ts +15 -0
- package/888/mini2.0-main/eslint.config.ts +26 -0
- package/888/mini2.0-main/index.html +16 -0
- package/888/mini2.0-main/output/playwright/rmb-position/design-comparison.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-back-top.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-page.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-sticky-check.png +0 -0
- package/888/mini2.0-main/output/playwright/rmb-position/rmb-position-sticky-scrolled.png +0 -0
- package/888/mini2.0-main/package-lock.json +6442 -0
- package/888/mini2.0-main/package.json +66 -0
- package/888/mini2.0-main/plugins/bump-version.ts +61 -0
- package/888/mini2.0-main/postcss.config.ts +15 -0
- package/888/mini2.0-main/public/favicon.ico +0 -0
- package/888/mini2.0-main/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
- package/888/mini2.0-main/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
- package/888/mini2.0-main/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
- package/888/mini2.0-main/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
- package/888/mini2.0-main/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
- package/888/mini2.0-main/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
- package/888/mini2.0-main/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
- package/888/mini2.0-main/public/images/img.png +0 -0
- package/888/mini2.0-main/src/App.vue +59 -0
- package/888/mini2.0-main/src/api/health.ts +13 -0
- package/888/mini2.0-main/src/api/rmb-position.ts +287 -0
- package/888/mini2.0-main/src/api/user.ts +54 -0
- package/888/mini2.0-main/src/auto-imports.d.ts +639 -0
- package/888/mini2.0-main/src/components.d.ts +30 -0
- package/888/mini2.0-main/src/config/config.properties +3 -0
- package/888/mini2.0-main/src/config/env.ts +6 -0
- package/888/mini2.0-main/src/config/plugin.properties.pro +6 -0
- package/888/mini2.0-main/src/config/plugin.properties.test +6 -0
- package/888/mini2.0-main/src/core/mxApi/index.ts +344 -0
- package/888/mini2.0-main/src/core/request/index.ts +135 -0
- package/888/mini2.0-main/src/main.ts +39 -0
- package/888/mini2.0-main/src/router/index.ts +77 -0
- package/888/mini2.0-main/src/stores/app.ts +24 -0
- package/888/mini2.0-main/src/stores/counter.ts +12 -0
- package/888/mini2.0-main/src/stores/user.ts +85 -0
- package/888/mini2.0-main/src/types/api.d.ts +14 -0
- package/888/mini2.0-main/src/types/nprogress.d.ts +8 -0
- package/888/mini2.0-main/src/utils/auth-token.ts +197 -0
- package/888/mini2.0-main/src/utils/query.ts +27 -0
- package/888/mini2.0-main/src/utils/request.ts +233 -0
- package/888/mini2.0-main/src/views/clearing-detail/index.vue +49 -0
- package/888/mini2.0-main/src/views/foreign-position/index.vue +49 -0
- package/888/mini2.0-main/src/views/home/index.vue +213 -0
- package/888/mini2.0-main/src/views/login/index.vue +202 -0
- package/888/mini2.0-main/src/views/mine/index.vue +143 -0
- package/888/mini2.0-main/src/views/net-debit/index.vue +49 -0
- package/888/mini2.0-main/src/views/pbc-position/index.vue +49 -0
- package/888/mini2.0-main/src/views/position-estimate/index.vue +49 -0
- package/888/mini2.0-main/src/views/rmb-position/index.vue +1042 -0
- package/888/mini2.0-main/src/views/warning/index.vue +49 -0
- package/888/mini2.0-main/tsconfig.app.json +18 -0
- package/888/mini2.0-main/tsconfig.json +11 -0
- package/888/mini2.0-main/tsconfig.node.json +28 -0
- package/888/mini2.0-main/vite.config.ts +98 -0
- package/design-qa.md +39 -0
- package/output/playwright/home-1672x941.png +0 -0
- package/output/playwright/home-preview-1672x941.png +0 -0
- package/output/playwright/home-reference-vs-preview.png +0 -0
- package/package.json +1 -1
- package/src/assets/home/card-clearing-city.png +0 -0
- package/src/assets/home/card-cross-border-map.png +0 -0
- package/src/assets/home/card-digital-currency.png +0 -0
- package/src/assets/home/card-eur-church.png +0 -0
- package/src/assets/home/card-hkd-skyline.png +0 -0
- package/src/assets/home/card-jpy-fuji.png +0 -0
- package/src/assets/home/card-rmb-great-wall.png +0 -0
- package/src/assets/home/card-usd-liberty.png +0 -0
- package/src/assets/home/home-page-bg.png +0 -0
- package/src/router/index.ts +1 -0
- package/src/views/HomeView.vue +619 -33
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/* eslint-disable */
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// biome-ignore lint: disable
|
|
4
|
+
// oxlint-disable
|
|
5
|
+
// ------
|
|
6
|
+
// Generated by unplugin-vue-components
|
|
7
|
+
// Read more: https://github.com/vuejs/core/pull/3399
|
|
8
|
+
|
|
9
|
+
export {}
|
|
10
|
+
|
|
11
|
+
/* prettier-ignore */
|
|
12
|
+
declare module 'vue' {
|
|
13
|
+
export interface GlobalComponents {
|
|
14
|
+
RouterLink: typeof import('vue-router')['RouterLink']
|
|
15
|
+
RouterView: typeof import('vue-router')['RouterView']
|
|
16
|
+
VanButton: typeof import('vant/es')['Button']
|
|
17
|
+
VanCell: typeof import('vant/es')['Cell']
|
|
18
|
+
VanCellGroup: typeof import('vant/es')['CellGroup']
|
|
19
|
+
VanDatePicker: typeof import('vant/es')['DatePicker']
|
|
20
|
+
VanEmpty: typeof import('vant/es')['Empty']
|
|
21
|
+
VanField: typeof import('vant/es')['Field']
|
|
22
|
+
VanForm: typeof import('vant/es')['Form']
|
|
23
|
+
VanIcon: typeof import('vant/es')['Icon']
|
|
24
|
+
VanList: typeof import('vant/es')['List']
|
|
25
|
+
VanLoading: typeof import('vant/es')['Loading']
|
|
26
|
+
VanPopup: typeof import('vant/es')['Popup']
|
|
27
|
+
VanTabbar: typeof import('vant/es')['Tabbar']
|
|
28
|
+
VanTabbarItem: typeof import('vant/es')['TabbarItem']
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 敏行 AJAX 支持的 HTTP 请求类型。
|
|
3
|
+
*
|
|
4
|
+
* 该枚举范围来自 MXCommon.ajax 文档;未包含 PATCH,
|
|
5
|
+
* 调用方如需 PATCH 应在业务请求中提前处理。
|
|
6
|
+
*/
|
|
7
|
+
export type MXAjaxType = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* MXCommon.ajax 入参。
|
|
11
|
+
*
|
|
12
|
+
* 这里只保留敏行 AJAX 文档中明确支持的公共字段:
|
|
13
|
+
* - type: 请求方式,默认 GET
|
|
14
|
+
* - url: 请求地址
|
|
15
|
+
* - dataType: 返回数据格式
|
|
16
|
+
* - async: 是否异步请求,默认 true
|
|
17
|
+
* - data: 请求数据,兼容实际宿主能力透传
|
|
18
|
+
* - headers: 请求头,兼容实际宿主能力透传
|
|
19
|
+
* - success/error/complete: 宿主回调
|
|
20
|
+
*/
|
|
21
|
+
export interface MXAjaxParams {
|
|
22
|
+
/** 请求方式,未传时按敏行文档默认 GET。 */
|
|
23
|
+
type?: MXAjaxType
|
|
24
|
+
/** 请求地址,可以是完整 URL,也可以由调用方传入业务接口路径。 */
|
|
25
|
+
url: string
|
|
26
|
+
/** 返回数据格式,例如 text/json,具体支持范围以敏行宿主为准。 */
|
|
27
|
+
dataType?: string
|
|
28
|
+
/** 是否异步请求,未传时默认 true。 */
|
|
29
|
+
async?: boolean
|
|
30
|
+
/** 请求数据,原样透传给敏行宿主。 */
|
|
31
|
+
data?: unknown
|
|
32
|
+
/** 请求头,原样透传给敏行宿主。 */
|
|
33
|
+
headers?: Record<string, string>
|
|
34
|
+
/** 请求成功回调,收到的是宿主原始返回值。 */
|
|
35
|
+
success?: (data: unknown) => void
|
|
36
|
+
/** 请求失败回调,收到的是宿主原始错误值。 */
|
|
37
|
+
error?: (data: unknown) => void
|
|
38
|
+
/** 请求完成回调,无论成功或失败都由宿主触发。 */
|
|
39
|
+
complete?: () => void
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Promise 化后的 AJAX 返回结构。
|
|
44
|
+
*
|
|
45
|
+
* 敏行宿主以回调返回原始数据;封装层会尝试 JSON.parse,
|
|
46
|
+
* 成功则返回解析后的对象,失败则保留原始数据。
|
|
47
|
+
*/
|
|
48
|
+
export interface MXAjaxResponse<T = unknown> {
|
|
49
|
+
data: T
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 获取 APP token 成功回调。
|
|
54
|
+
*/
|
|
55
|
+
export type MXAppTokenSuccess = (token: string) => void
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 获取 APP token 失败回调。
|
|
59
|
+
*/
|
|
60
|
+
export type MXAppTokenError = (error: unknown) => void
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* MXCommon.getEncryptString 入参。
|
|
64
|
+
*/
|
|
65
|
+
interface MXGetEncryptStringOptions {
|
|
66
|
+
onSuccess: MXAppTokenSuccess
|
|
67
|
+
onError?: MXAppTokenError
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* MXCommon 宿主能力。
|
|
72
|
+
*/
|
|
73
|
+
interface MXCommonHost {
|
|
74
|
+
ajax?: (options: MXAjaxParams) => void
|
|
75
|
+
getEncryptString?: (options: MXGetEncryptStringOptions) => void
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* NXCommon 宿主能力。
|
|
80
|
+
*
|
|
81
|
+
* 当前只用于 AJAX 兜底,不用于获取 APP token。
|
|
82
|
+
*/
|
|
83
|
+
interface NXCommonHost {
|
|
84
|
+
ajax?: (options: MXAjaxParams) => void
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const DEFAULT_NATIVE_TIMEOUT = 5000
|
|
88
|
+
const NATIVE_POLL_INTERVAL = 100
|
|
89
|
+
|
|
90
|
+
declare global {
|
|
91
|
+
/** 敏行旧宿主命名空间。 */
|
|
92
|
+
const MXCommon: MXCommonHost | undefined
|
|
93
|
+
/** 敏行新宿主命名空间,部分客户端使用 NXCommon。 */
|
|
94
|
+
const NXCommon: NXCommonHost | undefined
|
|
95
|
+
|
|
96
|
+
interface Window {
|
|
97
|
+
/** 敏行旧宿主命名空间。 */
|
|
98
|
+
MXCommon?: MXCommonHost
|
|
99
|
+
/** 敏行新宿主命名空间,部分客户端使用 NXCommon。 */
|
|
100
|
+
NXCommon?: NXCommonHost
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* 获取当前可用的敏行公共宿主对象。
|
|
106
|
+
*
|
|
107
|
+
* 优先使用 MXCommon;如果客户端只注入 NXCommon,则回退到 NXCommon。
|
|
108
|
+
* 使用 typeof 判断是为了避免全局变量未注入时产生运行时错误。
|
|
109
|
+
*/
|
|
110
|
+
const getHostCommon = () => {
|
|
111
|
+
return getMXCommon() || getNXCommon()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const getMXCommon = () => (typeof MXCommon !== 'undefined' ? MXCommon : undefined)
|
|
115
|
+
|
|
116
|
+
const getNXCommon = () => (typeof NXCommon !== 'undefined' ? NXCommon : undefined)
|
|
117
|
+
|
|
118
|
+
const getNativeSnapshot = () => ({
|
|
119
|
+
是否存在MXCommon: typeof MXCommon !== 'undefined',
|
|
120
|
+
是否存在NXCommon: typeof NXCommon !== 'undefined',
|
|
121
|
+
是否存在MXCommonAjax: typeof MXCommon !== 'undefined' && typeof MXCommon.ajax === 'function',
|
|
122
|
+
是否存在NXCommonAjax: typeof NXCommon !== 'undefined' && typeof NXCommon.ajax === 'function',
|
|
123
|
+
是否存在获取Token方法:
|
|
124
|
+
typeof MXCommon !== 'undefined' && typeof MXCommon.getEncryptString === 'function',
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 安全解析宿主返回的数据。
|
|
129
|
+
*
|
|
130
|
+
* 敏行 AJAX 示例中 dataType 常使用 text,业务响应可能是 JSON 字符串。
|
|
131
|
+
* 这里仅在字符串非空且 JSON.parse 成功时转换;否则保持原值,避免吞掉
|
|
132
|
+
* 文本响应或宿主返回的非 JSON 数据。
|
|
133
|
+
*/
|
|
134
|
+
const safeJsonParse = (data: unknown) => {
|
|
135
|
+
if (typeof data !== 'string') return data
|
|
136
|
+
|
|
137
|
+
const text = data.trim()
|
|
138
|
+
if (!text) return data
|
|
139
|
+
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(text)
|
|
142
|
+
} catch {
|
|
143
|
+
return data
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* 发起敏行 AJAX 请求。
|
|
149
|
+
*
|
|
150
|
+
* 该方法做三件事:
|
|
151
|
+
* 1. 判断当前环境是否存在 MXCommon.ajax / NXCommon.ajax。
|
|
152
|
+
* 2. 补齐敏行文档默认值,例如 type=GET、async=true。
|
|
153
|
+
* 3. 将宿主回调包装成 Promise,同时保留调用方传入的回调。
|
|
154
|
+
*
|
|
155
|
+
* @param options 敏行 AJAX 请求参数
|
|
156
|
+
* @returns Promise 化后的请求结果
|
|
157
|
+
*/
|
|
158
|
+
export function ajax<T = unknown>(options: MXAjaxParams): Promise<MXAjaxResponse<T>> {
|
|
159
|
+
return new Promise((resolve, reject) => {
|
|
160
|
+
const hostCommon = getHostCommon()
|
|
161
|
+
|
|
162
|
+
// 非敏行宿主环境无法调用 MXCommon.ajax,直接进入失败链路。
|
|
163
|
+
if (!hostCommon?.ajax) {
|
|
164
|
+
const error = new Error('当前环境不支持 MXCommon.ajax')
|
|
165
|
+
options.error?.(error)
|
|
166
|
+
options.complete?.()
|
|
167
|
+
reject(error)
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// 透传调用方参数,并补齐敏行文档中的默认请求配置。
|
|
172
|
+
const requestOptions: MXAjaxParams = {
|
|
173
|
+
...options,
|
|
174
|
+
type: options.type || 'GET',
|
|
175
|
+
async: options.async ?? true,
|
|
176
|
+
success(data) {
|
|
177
|
+
console.log('[敏行AJAX] 原生请求成功返回', {
|
|
178
|
+
url: requestOptions.url,
|
|
179
|
+
data: safeJsonParse(data),
|
|
180
|
+
})
|
|
181
|
+
// 先保留原始回调行为,再 resolve Promise,避免破坏旧调用方。
|
|
182
|
+
options.success?.(data)
|
|
183
|
+
resolve({ data: safeJsonParse(data) as T })
|
|
184
|
+
},
|
|
185
|
+
error(data) {
|
|
186
|
+
const errorData = safeJsonParse(data)
|
|
187
|
+
console.error('[敏行AJAX] 原生请求失败返回', {
|
|
188
|
+
url: requestOptions.url,
|
|
189
|
+
data: errorData,
|
|
190
|
+
})
|
|
191
|
+
// error 同样保留调用方回调,再 reject 给 await/catch 使用。
|
|
192
|
+
options.error?.(errorData)
|
|
193
|
+
reject(errorData)
|
|
194
|
+
},
|
|
195
|
+
complete() {
|
|
196
|
+
options.complete?.()
|
|
197
|
+
},
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// 每次调用敏行 AJAX 前打印完整关键参数,方便原生联调定位问题。
|
|
201
|
+
console.log('[敏行AJAX] 发起原生请求', {
|
|
202
|
+
type: requestOptions.type,
|
|
203
|
+
url: requestOptions.url,
|
|
204
|
+
dataType: requestOptions.dataType,
|
|
205
|
+
async: requestOptions.async,
|
|
206
|
+
data: requestOptions.data,
|
|
207
|
+
headers: requestOptions.headers,
|
|
208
|
+
hasSuccessCallback: Boolean(options.success),
|
|
209
|
+
hasErrorCallback: Boolean(options.error),
|
|
210
|
+
hasCompleteCallback: Boolean(options.complete),
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
hostCommon.ajax(requestOptions)
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 获取敏行宿主提供的 APP token。
|
|
219
|
+
*
|
|
220
|
+
* 宿主文档方法名为 MXCommon.getEncryptString({ onSuccess, onError }),
|
|
221
|
+
* 这里只做 Promise 化薄封装。
|
|
222
|
+
*
|
|
223
|
+
* @returns Promise 化后的 APP token 字符串
|
|
224
|
+
*/
|
|
225
|
+
export function getAppToken(): Promise<string> {
|
|
226
|
+
return new Promise((resolve, reject) => {
|
|
227
|
+
if (typeof MXCommon === 'undefined' || typeof MXCommon.getEncryptString !== 'function') {
|
|
228
|
+
const error = new Error('当前环境不支持 MXCommon.getEncryptString')
|
|
229
|
+
console.error('[敏行Token] 获取失败:方法不存在', error)
|
|
230
|
+
reject(error)
|
|
231
|
+
return
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const onSuccess: MXAppTokenSuccess = (token) => {
|
|
235
|
+
console.log('[敏行Token] 获取成功', {
|
|
236
|
+
token,
|
|
237
|
+
是否返回Token: Boolean(token),
|
|
238
|
+
Token长度: token?.length || 0,
|
|
239
|
+
})
|
|
240
|
+
resolve(token)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const onError: MXAppTokenError = (error) => {
|
|
244
|
+
console.error('[敏行Token] 获取失败', error)
|
|
245
|
+
reject(error)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
MXCommon.getEncryptString({
|
|
249
|
+
onSuccess,
|
|
250
|
+
onError,
|
|
251
|
+
})
|
|
252
|
+
})
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* MXCommon.getEncryptString 的同名封装。
|
|
257
|
+
*
|
|
258
|
+
* 保留宿主方法名,方便调用方按敏行文档搜索和使用。
|
|
259
|
+
*/
|
|
260
|
+
export const getEncryptString = getAppToken
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 判断当前页面是否运行在敏行宿主环境中。
|
|
264
|
+
*
|
|
265
|
+
* 只要宿主注入了 MXCommon 或 NXCommon,就认为是原生环境。
|
|
266
|
+
*/
|
|
267
|
+
export const isNativeApp = (): boolean =>
|
|
268
|
+
typeof MXCommon !== 'undefined' || typeof NXCommon !== 'undefined'
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* 等待敏行宿主完成注入后再判断是否为 APP 环境。
|
|
272
|
+
*
|
|
273
|
+
* 部分客户端会在 deviceready 后才注入 MXCommon/NXCommon。如果页面启动时
|
|
274
|
+
* 立即同步判断,容易误判为浏览器环境。这里先做一次即时判断;如果还没有
|
|
275
|
+
* 宿主对象,则等待 deviceready,超过 timeout 后按浏览器环境处理。
|
|
276
|
+
*/
|
|
277
|
+
export function waitNativeReady(timeout = DEFAULT_NATIVE_TIMEOUT): Promise<boolean> {
|
|
278
|
+
return waitForNativeCapability('原生环境检测', isNativeApp, timeout)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
function waitForNativeCapability(
|
|
282
|
+
label: string,
|
|
283
|
+
hasCapability: () => boolean,
|
|
284
|
+
timeout: number,
|
|
285
|
+
): Promise<boolean> {
|
|
286
|
+
const initialReady = hasCapability()
|
|
287
|
+
|
|
288
|
+
console.log('[敏行环境] 开始检测', {
|
|
289
|
+
检测目标: label,
|
|
290
|
+
超时时间: timeout,
|
|
291
|
+
初始是否就绪: initialReady,
|
|
292
|
+
...getNativeSnapshot(),
|
|
293
|
+
})
|
|
294
|
+
|
|
295
|
+
if (initialReady) {
|
|
296
|
+
console.log('[敏行环境] 启动时已就绪', {
|
|
297
|
+
检测目标: label,
|
|
298
|
+
...getNativeSnapshot(),
|
|
299
|
+
})
|
|
300
|
+
return Promise.resolve(true)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return new Promise((resolve) => {
|
|
304
|
+
let settled = false
|
|
305
|
+
|
|
306
|
+
const finish = (value: boolean, reason: string) => {
|
|
307
|
+
if (settled) return
|
|
308
|
+
|
|
309
|
+
settled = true
|
|
310
|
+
document.removeEventListener('deviceready', onDeviceReady, false)
|
|
311
|
+
clearTimeout(timer)
|
|
312
|
+
clearInterval(interval)
|
|
313
|
+
console.log('[敏行环境] 检测完成', {
|
|
314
|
+
检测目标: label,
|
|
315
|
+
是否就绪: value,
|
|
316
|
+
完成原因: reason,
|
|
317
|
+
...getNativeSnapshot(),
|
|
318
|
+
结果说明: value ? '敏行能力已就绪' : '敏行能力未就绪',
|
|
319
|
+
})
|
|
320
|
+
resolve(value)
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
const onDeviceReady = () => {
|
|
324
|
+
console.log('[敏行环境] 收到 deviceready 事件', {
|
|
325
|
+
检测目标: label,
|
|
326
|
+
...getNativeSnapshot(),
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
if (hasCapability()) {
|
|
330
|
+
finish(true, 'deviceready')
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
const interval = setInterval(() => {
|
|
335
|
+
if (hasCapability()) {
|
|
336
|
+
finish(true, 'polling')
|
|
337
|
+
}
|
|
338
|
+
}, NATIVE_POLL_INTERVAL)
|
|
339
|
+
|
|
340
|
+
const timer = setTimeout(() => finish(false, 'timeout'), timeout)
|
|
341
|
+
|
|
342
|
+
document.addEventListener('deviceready', onDeviceReady, false)
|
|
343
|
+
})
|
|
344
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { ajax, isNativeApp } from '@/core/mxApi'
|
|
2
|
+
import type { MXAjaxType } from '@/core/mxApi'
|
|
3
|
+
import { request as axiosRequest } from '@/utils/request'
|
|
4
|
+
import type { RequestConfig } from '@/utils/request'
|
|
5
|
+
import { appendQuery } from '@/utils/query'
|
|
6
|
+
import { apiConfig } from '@/config/env'
|
|
7
|
+
import type { ApiResponse } from '@/types/api'
|
|
8
|
+
import router from '@/router'
|
|
9
|
+
import {
|
|
10
|
+
clearAuthTokens,
|
|
11
|
+
getAuthHeaders,
|
|
12
|
+
getStoredRefreshToken,
|
|
13
|
+
REFRESH_TOKEN_URL,
|
|
14
|
+
refreshAccessToken,
|
|
15
|
+
type AuthTokenResponse,
|
|
16
|
+
} from '@/utils/auth-token'
|
|
17
|
+
|
|
18
|
+
export type { RequestConfig } from '@/utils/request'
|
|
19
|
+
|
|
20
|
+
export function request<R = unknown, T = unknown>(
|
|
21
|
+
config: RequestConfig<T>,
|
|
22
|
+
): Promise<ApiResponse<R>> {
|
|
23
|
+
if (isNativeApp()) {
|
|
24
|
+
return nativeRequest<R, T>(config)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return axiosRequest<R, T>(config)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async function nativeRequest<R = unknown, T = unknown>(
|
|
31
|
+
config: RequestConfig<T>,
|
|
32
|
+
retried = false,
|
|
33
|
+
): Promise<ApiResponse<R>> {
|
|
34
|
+
const method = (config.method || 'GET').toUpperCase()
|
|
35
|
+
|
|
36
|
+
if (!isMXAjaxType(method)) {
|
|
37
|
+
throw new Error(`敏行 AJAX 不支持 ${method} 请求`)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
const response = await ajax<ApiResponse<R>>({
|
|
42
|
+
type: method,
|
|
43
|
+
url: appendQuery(resolveNativeUrl(config.url), config.params),
|
|
44
|
+
data: config.data,
|
|
45
|
+
dataType: 'text',
|
|
46
|
+
async: true,
|
|
47
|
+
headers: getCommonHeaders(config.headers, config.skipAuth),
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
return response.data
|
|
51
|
+
} catch (error) {
|
|
52
|
+
if (isUnauthorized(error) && !config.skipAuth && !retried) {
|
|
53
|
+
try {
|
|
54
|
+
await refreshAccessToken(requestRefreshTokenByNative)
|
|
55
|
+
return nativeRequest(config, true)
|
|
56
|
+
} catch (refreshError) {
|
|
57
|
+
handleRefreshTokenFailed()
|
|
58
|
+
throw refreshError
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
throw error
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function getCommonHeaders(headers?: Record<string, string>, skipAuth = false) {
|
|
67
|
+
return getAuthHeaders(headers, skipAuth)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function isUnauthorized(error: unknown) {
|
|
71
|
+
const result = error as {
|
|
72
|
+
status?: number | string
|
|
73
|
+
statusCode?: number | string
|
|
74
|
+
code?: number | string
|
|
75
|
+
response?: {
|
|
76
|
+
status?: number | string
|
|
77
|
+
statusCode?: number | string
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return (
|
|
82
|
+
isUnauthorizedCode(result.status) ||
|
|
83
|
+
isUnauthorizedCode(result.statusCode) ||
|
|
84
|
+
isUnauthorizedCode(result.code) ||
|
|
85
|
+
isUnauthorizedCode(result.response?.status) ||
|
|
86
|
+
isUnauthorizedCode(result.response?.statusCode)
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function isUnauthorizedCode(code: number | string | undefined) {
|
|
91
|
+
return code === 401 || code === '401' || code === '0401'
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function requestRefreshTokenByNative() {
|
|
95
|
+
const refreshToken = getStoredRefreshToken()
|
|
96
|
+
|
|
97
|
+
if (!refreshToken) {
|
|
98
|
+
throw new Error('本地不存在 refresh token')
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const response = await ajax<ApiResponse<AuthTokenResponse> & AuthTokenResponse>({
|
|
102
|
+
type: 'POST',
|
|
103
|
+
url: resolveNativeUrl(REFRESH_TOKEN_URL),
|
|
104
|
+
data: {
|
|
105
|
+
refreshToken,
|
|
106
|
+
},
|
|
107
|
+
dataType: 'text',
|
|
108
|
+
async: true,
|
|
109
|
+
headers: getCommonHeaders(undefined, true),
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
if (typeof response.data.code === 'number' && response.data.code !== 0) {
|
|
113
|
+
throw new Error(response.data.message || '刷新 token 失败')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return response.data.data || response.data
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function handleRefreshTokenFailed() {
|
|
120
|
+
clearAuthTokens()
|
|
121
|
+
router.push('/login')
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function isMXAjaxType(method: string): method is MXAjaxType {
|
|
125
|
+
return method === 'GET' || method === 'POST' || method === 'PUT' || method === 'DELETE'
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function resolveNativeUrl(url: string) {
|
|
129
|
+
if (/^[a-z][a-z\d+\-.]*:\/\//i.test(url)) return url
|
|
130
|
+
|
|
131
|
+
const baseURL = apiConfig.baseURL || ''
|
|
132
|
+
if (!baseURL) return url
|
|
133
|
+
|
|
134
|
+
return `${baseURL.replace(/\/+$/, '')}/${url.replace(/^\/+/, '')}`
|
|
135
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { createApp } from 'vue'
|
|
2
|
+
import { createPinia } from 'pinia'
|
|
3
|
+
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
|
|
4
|
+
import 'vant/lib/index.css'
|
|
5
|
+
|
|
6
|
+
import App from './App.vue'
|
|
7
|
+
import router from './router'
|
|
8
|
+
import { useAppStore } from '@/stores/app'
|
|
9
|
+
import { apiConfig, appEnv } from '@/config/env'
|
|
10
|
+
|
|
11
|
+
const app = createApp(App)
|
|
12
|
+
const pinia = createPinia()
|
|
13
|
+
|
|
14
|
+
pinia.use(piniaPluginPersistedstate)
|
|
15
|
+
|
|
16
|
+
app.use(pinia)
|
|
17
|
+
app.use(router)
|
|
18
|
+
|
|
19
|
+
// 等待原生环境检测完成后再挂载,确保所有组件读到的 isNative 都是正确值
|
|
20
|
+
const appStore = useAppStore()
|
|
21
|
+
await appStore.initNativeDetection()
|
|
22
|
+
|
|
23
|
+
console.log('[应用启动] 当前运行环境', {
|
|
24
|
+
当前环境: appEnv,
|
|
25
|
+
是否原生环境: appStore.isNative,
|
|
26
|
+
环境说明: appStore.isNative ? '当前是敏行原生环境' : '当前不是敏行原生环境',
|
|
27
|
+
运行模式: import.meta.env.MODE,
|
|
28
|
+
接口BaseUrl: apiConfig.baseURL,
|
|
29
|
+
请求超时时间: apiConfig.timeout,
|
|
30
|
+
应用版本: __APP_VERSION__,
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
// 测试环境 + 原生设备:加载 vConsole 调试面板
|
|
34
|
+
if (appStore.isNative) {
|
|
35
|
+
const { default: VConsole } = await import('vconsole')
|
|
36
|
+
new VConsole()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
app.mount('#app')
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { createRouter, createWebHashHistory } from 'vue-router'
|
|
2
|
+
import { useUserStore } from '@/stores/user'
|
|
3
|
+
|
|
4
|
+
const router = createRouter({
|
|
5
|
+
history: createWebHashHistory(),
|
|
6
|
+
routes: [
|
|
7
|
+
{
|
|
8
|
+
path: '/',
|
|
9
|
+
name: 'Home',
|
|
10
|
+
component: () => import('@/views/home/index.vue'),
|
|
11
|
+
meta: { requiresAuth: true },
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
path: '/login',
|
|
15
|
+
name: 'Login',
|
|
16
|
+
component: () => import('@/views/login/index.vue'),
|
|
17
|
+
meta: { hideTabbar: true },
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
path: '/rmb-position',
|
|
21
|
+
name: 'RmbPosition',
|
|
22
|
+
component: () => import('@/views/rmb-position/index.vue'),
|
|
23
|
+
meta: { requiresAuth: true, hideTabbar: true },
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
path: '/foreign-position',
|
|
27
|
+
name: 'ForeignPosition',
|
|
28
|
+
component: () => import('@/views/foreign-position/index.vue'),
|
|
29
|
+
meta: { requiresAuth: true },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
path: '/pbc-position',
|
|
33
|
+
name: 'PbcPosition',
|
|
34
|
+
component: () => import('@/views/pbc-position/index.vue'),
|
|
35
|
+
meta: { requiresAuth: true },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
path: '/position-estimate',
|
|
39
|
+
name: 'PositionEstimate',
|
|
40
|
+
component: () => import('@/views/position-estimate/index.vue'),
|
|
41
|
+
meta: { requiresAuth: true },
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: '/net-debit',
|
|
45
|
+
name: 'NetDebit',
|
|
46
|
+
component: () => import('@/views/net-debit/index.vue'),
|
|
47
|
+
meta: { requiresAuth: true },
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
path: '/clearing-detail',
|
|
51
|
+
name: 'ClearingDetail',
|
|
52
|
+
component: () => import('@/views/clearing-detail/index.vue'),
|
|
53
|
+
meta: { requiresAuth: true },
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
path: '/warning',
|
|
57
|
+
name: 'Warning',
|
|
58
|
+
component: () => import('@/views/warning/index.vue'),
|
|
59
|
+
meta: { requiresAuth: true },
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
path: '/mine',
|
|
63
|
+
name: 'Mine',
|
|
64
|
+
component: () => import('@/views/mine/index.vue'),
|
|
65
|
+
meta: { requiresAuth: true },
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
router.beforeEach((to) => {
|
|
71
|
+
const userStore = useUserStore()
|
|
72
|
+
if (to.meta.requiresAuth && !userStore.token) {
|
|
73
|
+
return { name: 'Login' }
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
export default router
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defineStore } from 'pinia'
|
|
2
|
+
import { waitNativeReady } from '@/core/mxApi'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 应用级状态 Store
|
|
6
|
+
*
|
|
7
|
+
* 存放全局共享的运行时状态,不持久化。
|
|
8
|
+
* initNativeDetection 在 main.ts 挂载前调用,组件读取时值已就绪。
|
|
9
|
+
*/
|
|
10
|
+
export const useAppStore = defineStore('app', () => {
|
|
11
|
+
/** 是否在原生 APP WebView 环境中 */
|
|
12
|
+
const isNative = ref(false)
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 初始化原生环境检测
|
|
16
|
+
*
|
|
17
|
+
* 等待敏行宿主注入完成后判断当前运行环境。
|
|
18
|
+
*/
|
|
19
|
+
async function initNativeDetection() {
|
|
20
|
+
isNative.value = await waitNativeReady()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return { isNative, initNativeDetection }
|
|
24
|
+
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ref, computed } from 'vue'
|
|
2
|
+
import { defineStore } from 'pinia'
|
|
3
|
+
|
|
4
|
+
export const useCounterStore = defineStore('counter', () => {
|
|
5
|
+
const count = ref(0)
|
|
6
|
+
const doubleCount = computed(() => count.value * 2)
|
|
7
|
+
function increment() {
|
|
8
|
+
count.value++
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return { count, doubleCount, increment }
|
|
12
|
+
})
|