verce-vue-test 0.0.39 → 0.0.41
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/design-qa.md +17 -9
- package/package.json +1 -1
- package/src/views/HomeView.vue +340 -172
- package/vite.config.ts +6 -0
- package/mini2.0-main 2/.editorconfig +0 -8
- package/mini2.0-main 2/.env.development +0 -3
- package/mini2.0-main 2/.env.production +0 -3
- package/mini2.0-main 2/.env.test +0 -3
- package/mini2.0-main 2/.gitattributes +0 -1
- package/mini2.0-main 2/.oxlintrc.json +0 -10
- package/mini2.0-main 2/.prettierrc.json +0 -6
- package/mini2.0-main 2/.vscode/extensions.json +0 -9
- package/mini2.0-main 2/README.md +0 -179
- package/mini2.0-main 2/auto-imports.d.ts +0 -629
- package/mini2.0-main 2/components.d.ts +0 -21
- package/mini2.0-main 2/docs/MX_API.md +0 -244
- package/mini2.0-main 2/docs/REQUEST.md +0 -217
- package/mini2.0-main 2/docs/jsapi.js +0 -515
- package/mini2.0-main 2/docs/package-json-guide.md +0 -132
- package/mini2.0-main 2/env.d.ts +0 -13
- package/mini2.0-main 2/eslint.config.ts +0 -26
- package/mini2.0-main 2/index.html +0 -16
- package/mini2.0-main 2/package-lock.json +0 -6442
- package/mini2.0-main 2/package.json +0 -66
- package/mini2.0-main 2/plugins/bump-version.ts +0 -61
- package/mini2.0-main 2/postcss.config.ts +0 -15
- package/mini2.0-main 2/public/favicon.ico +0 -0
- package/mini2.0-main 2/public/images/12a73787-86a9-4891-a65f-66104746f6a8.png +0 -0
- package/mini2.0-main 2/public/images/5798d7aa-ba8b-4605-8079-58b35495ac55.png +0 -0
- package/mini2.0-main 2/public/images/73fef1e4-0fd0-4a1a-9b8b-a70a5b6acbbc.png +0 -0
- package/mini2.0-main 2/public/images/bc685b4c-0cca-4a79-924c-a8ee10e6f8eb.png +0 -0
- package/mini2.0-main 2/public/images/c3dbbd9d-be56-490e-b9f4-6ee17ebefffc.png +0 -0
- package/mini2.0-main 2/public/images/ea745a10-42aa-4f44-8d7f-3ab02cc0adcd.png +0 -0
- package/mini2.0-main 2/public/images/f5876785-b927-4347-ba19-999114240649.png +0 -0
- package/mini2.0-main 2/public/images/img.png +0 -0
- package/mini2.0-main 2/src/App.vue +0 -11
- package/mini2.0-main 2/src/api/user.ts +0 -33
- package/mini2.0-main 2/src/auto-imports.d.ts +0 -639
- package/mini2.0-main 2/src/components.d.ts +0 -23
- package/mini2.0-main 2/src/config/config.properties +0 -3
- package/mini2.0-main 2/src/config/env.ts +0 -6
- package/mini2.0-main 2/src/config/plugin.properties.pro +0 -6
- package/mini2.0-main 2/src/config/plugin.properties.test +0 -6
- package/mini2.0-main 2/src/core/mxApi/index.ts +0 -217
- package/mini2.0-main 2/src/core/request/index.ts +0 -42
- package/mini2.0-main 2/src/main.ts +0 -28
- package/mini2.0-main 2/src/router/index.ts +0 -70
- package/mini2.0-main 2/src/stores/app.ts +0 -24
- package/mini2.0-main 2/src/stores/counter.ts +0 -12
- package/mini2.0-main 2/src/stores/user.ts +0 -52
- package/mini2.0-main 2/src/types/api.d.ts +0 -14
- package/mini2.0-main 2/src/types/nprogress.d.ts +0 -8
- package/mini2.0-main 2/src/utils/query.ts +0 -27
- package/mini2.0-main 2/src/utils/request.ts +0 -159
- package/mini2.0-main 2/src/views/clearing-detail/index.vue +0 -49
- package/mini2.0-main 2/src/views/foreign-position/index.vue +0 -49
- package/mini2.0-main 2/src/views/home/index.vue +0 -201
- package/mini2.0-main 2/src/views/login/index.vue +0 -196
- package/mini2.0-main 2/src/views/net-debit/index.vue +0 -49
- package/mini2.0-main 2/src/views/pbc-position/index.vue +0 -49
- package/mini2.0-main 2/src/views/position-estimate/index.vue +0 -49
- package/mini2.0-main 2/src/views/rmb-position/index.vue +0 -49
- package/mini2.0-main 2/src/views/warning/index.vue +0 -49
- package/mini2.0-main 2/tsconfig.app.json +0 -18
- package/mini2.0-main 2/tsconfig.json +0 -11
- package/mini2.0-main 2/tsconfig.node.json +0 -28
- package/mini2.0-main 2/vite.config.ts +0 -69
|
@@ -1,23 +0,0 @@
|
|
|
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
|
-
VanCellGroup: typeof import('vant/es')['CellGroup']
|
|
18
|
-
VanField: typeof import('vant/es')['Field']
|
|
19
|
-
VanForm: typeof import('vant/es')['Form']
|
|
20
|
-
VanIcon: typeof import('vant/es')['Icon']
|
|
21
|
-
VanLoading: typeof import('vant/es')['Loading']
|
|
22
|
-
}
|
|
23
|
-
}
|
|
@@ -1,217 +0,0 @@
|
|
|
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
|
-
* - success/error/complete: 宿主回调
|
|
19
|
-
*/
|
|
20
|
-
export interface MXAjaxParams {
|
|
21
|
-
/** 请求方式,未传时按敏行文档默认 GET。 */
|
|
22
|
-
type?: MXAjaxType
|
|
23
|
-
/** 请求地址,可以是完整 URL,也可以由调用方传入业务接口路径。 */
|
|
24
|
-
url: string
|
|
25
|
-
/** 返回数据格式,例如 text/json,具体支持范围以敏行宿主为准。 */
|
|
26
|
-
dataType?: string
|
|
27
|
-
/** 是否异步请求,未传时默认 true。 */
|
|
28
|
-
async?: boolean
|
|
29
|
-
/** 请求数据,原样透传给敏行宿主。 */
|
|
30
|
-
data?: unknown
|
|
31
|
-
/** 请求成功回调,收到的是宿主原始返回值。 */
|
|
32
|
-
success?: (data: unknown) => void
|
|
33
|
-
/** 请求失败回调,收到的是宿主原始错误值。 */
|
|
34
|
-
error?: (data: unknown) => void
|
|
35
|
-
/** 请求完成回调,无论成功或失败都由宿主触发。 */
|
|
36
|
-
complete?: () => void
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Promise 化后的 AJAX 返回结构。
|
|
41
|
-
*
|
|
42
|
-
* 敏行宿主以回调返回原始数据;封装层会尝试 JSON.parse,
|
|
43
|
-
* 成功则返回解析后的对象,失败则保留原始数据。
|
|
44
|
-
*/
|
|
45
|
-
export interface MXAjaxResponse<T = unknown> {
|
|
46
|
-
data: T
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 获取 APP token 成功回调。
|
|
51
|
-
*/
|
|
52
|
-
export type MXAppTokenSuccess = (token: string) => void
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* 获取 APP token 失败回调。
|
|
56
|
-
*/
|
|
57
|
-
export type MXAppTokenError = (error: unknown) => void
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 当前项目使用的敏行公共宿主能力。
|
|
61
|
-
*/
|
|
62
|
-
interface MXCommonHost {
|
|
63
|
-
ajax?: (options: MXAjaxParams) => void
|
|
64
|
-
getEncryptString?: (success: MXAppTokenSuccess, error?: MXAppTokenError) => void
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
declare global {
|
|
68
|
-
interface Window {
|
|
69
|
-
/** 敏行旧宿主命名空间。 */
|
|
70
|
-
MXCommon?: MXCommonHost
|
|
71
|
-
/** 敏行新宿主命名空间,部分客户端使用 NXCommon。 */
|
|
72
|
-
NXCommon?: MXCommonHost
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 获取当前可用的敏行公共宿主对象。
|
|
78
|
-
*
|
|
79
|
-
* 优先使用 MXCommon;如果客户端只注入 NXCommon,则回退到 NXCommon。
|
|
80
|
-
* 增加 window 判断是为了避免在类型检查、SSR 或非浏览器上下文导入时报错。
|
|
81
|
-
*/
|
|
82
|
-
const getHostCommon = () => {
|
|
83
|
-
if (typeof window === 'undefined') return undefined
|
|
84
|
-
|
|
85
|
-
return window.MXCommon || window.NXCommon
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 安全解析宿主返回的数据。
|
|
90
|
-
*
|
|
91
|
-
* 敏行 AJAX 示例中 dataType 常使用 text,业务响应可能是 JSON 字符串。
|
|
92
|
-
* 这里仅在字符串非空且 JSON.parse 成功时转换;否则保持原值,避免吞掉
|
|
93
|
-
* 文本响应或宿主返回的非 JSON 数据。
|
|
94
|
-
*/
|
|
95
|
-
const safeJsonParse = (data: unknown) => {
|
|
96
|
-
if (typeof data !== 'string') return data
|
|
97
|
-
|
|
98
|
-
const text = data.trim()
|
|
99
|
-
if (!text) return data
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
return JSON.parse(text)
|
|
103
|
-
} catch {
|
|
104
|
-
return data
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 发起敏行 AJAX 请求。
|
|
110
|
-
*
|
|
111
|
-
* 该方法做三件事:
|
|
112
|
-
* 1. 判断当前环境是否存在 MXCommon.ajax / NXCommon.ajax。
|
|
113
|
-
* 2. 补齐敏行文档默认值,例如 type=GET、async=true。
|
|
114
|
-
* 3. 将宿主回调包装成 Promise,同时保留调用方传入的回调。
|
|
115
|
-
*
|
|
116
|
-
* @param options 敏行 AJAX 请求参数
|
|
117
|
-
* @returns Promise 化后的请求结果
|
|
118
|
-
*/
|
|
119
|
-
export function ajax<T = unknown>(options: MXAjaxParams): Promise<MXAjaxResponse<T>> {
|
|
120
|
-
return new Promise((resolve, reject) => {
|
|
121
|
-
const hostCommon = getHostCommon()
|
|
122
|
-
|
|
123
|
-
// 非敏行宿主环境无法调用 MXCommon.ajax,直接进入失败链路。
|
|
124
|
-
if (!hostCommon?.ajax) {
|
|
125
|
-
const error = new Error('当前环境不支持 MXCommon.ajax')
|
|
126
|
-
options.error?.(error)
|
|
127
|
-
options.complete?.()
|
|
128
|
-
reject(error)
|
|
129
|
-
return
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 透传调用方参数,并补齐敏行文档中的默认请求配置。
|
|
133
|
-
const requestOptions: MXAjaxParams = {
|
|
134
|
-
...options,
|
|
135
|
-
type: options.type || 'GET',
|
|
136
|
-
async: options.async ?? true,
|
|
137
|
-
success(data) {
|
|
138
|
-
// 先保留原始回调行为,再 resolve Promise,避免破坏旧调用方。
|
|
139
|
-
options.success?.(data)
|
|
140
|
-
resolve({ data: safeJsonParse(data) as T })
|
|
141
|
-
},
|
|
142
|
-
error(data) {
|
|
143
|
-
const errorData = safeJsonParse(data)
|
|
144
|
-
// error 同样保留调用方回调,再 reject 给 await/catch 使用。
|
|
145
|
-
options.error?.(errorData)
|
|
146
|
-
reject(errorData)
|
|
147
|
-
},
|
|
148
|
-
complete() {
|
|
149
|
-
options.complete?.()
|
|
150
|
-
},
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// 每次调用敏行 AJAX 前打印完整关键参数,方便原生联调定位问题。
|
|
154
|
-
console.log('[MXCommon.ajax] request params', {
|
|
155
|
-
type: requestOptions.type,
|
|
156
|
-
url: requestOptions.url,
|
|
157
|
-
dataType: requestOptions.dataType,
|
|
158
|
-
async: requestOptions.async,
|
|
159
|
-
data: requestOptions.data,
|
|
160
|
-
hasSuccessCallback: Boolean(options.success),
|
|
161
|
-
hasErrorCallback: Boolean(options.error),
|
|
162
|
-
hasCompleteCallback: Boolean(options.complete),
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
hostCommon.ajax(requestOptions)
|
|
166
|
-
})
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* 获取敏行宿主提供的 APP token。
|
|
171
|
-
*
|
|
172
|
-
* 宿主文档方法名为 MXCommon.getEncryptString(),这里只封装该方法。
|
|
173
|
-
*
|
|
174
|
-
* @returns Promise 化后的 APP token 字符串
|
|
175
|
-
*/
|
|
176
|
-
export function getAppToken(): Promise<string> {
|
|
177
|
-
return new Promise((resolve, reject) => {
|
|
178
|
-
const hostCommon = getHostCommon()
|
|
179
|
-
const getToken = hostCommon?.getEncryptString
|
|
180
|
-
|
|
181
|
-
if (!getToken) {
|
|
182
|
-
const error = new Error('当前环境不支持 MXCommon.getEncryptString')
|
|
183
|
-
reject(error)
|
|
184
|
-
return
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
console.log('[MXCommon.getEncryptString] request params', {
|
|
188
|
-
hasSuccessCallback: true,
|
|
189
|
-
hasErrorCallback: true,
|
|
190
|
-
actualMethod: 'getEncryptString',
|
|
191
|
-
})
|
|
192
|
-
|
|
193
|
-
getToken(
|
|
194
|
-
(token) => {
|
|
195
|
-
resolve(token)
|
|
196
|
-
},
|
|
197
|
-
(error) => {
|
|
198
|
-
reject(error)
|
|
199
|
-
},
|
|
200
|
-
)
|
|
201
|
-
})
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* MXCommon.getEncryptString 的同名封装。
|
|
206
|
-
*
|
|
207
|
-
* 保留宿主方法名,方便调用方按敏行文档搜索和使用。
|
|
208
|
-
*/
|
|
209
|
-
export const getEncryptString = getAppToken
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* 判断当前页面是否运行在敏行宿主环境中。
|
|
213
|
-
*
|
|
214
|
-
* 只要宿主注入了 MXCommon 或 NXCommon,就认为是原生环境。
|
|
215
|
-
*/
|
|
216
|
-
export const isNativeApp = (): boolean =>
|
|
217
|
-
typeof window.MXCommon !== 'undefined' || typeof window.NXCommon !== 'undefined'
|
|
@@ -1,42 +0,0 @@
|
|
|
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 type { ApiResponse } from '@/types/api'
|
|
7
|
-
|
|
8
|
-
export type { RequestConfig } from '@/utils/request'
|
|
9
|
-
|
|
10
|
-
export function request<R = unknown, T = unknown>(
|
|
11
|
-
config: RequestConfig<T>,
|
|
12
|
-
): Promise<ApiResponse<R>> {
|
|
13
|
-
if (isNativeApp()) {
|
|
14
|
-
return nativeRequest<R, T>(config)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return axiosRequest<R, T>(config)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
async function nativeRequest<R = unknown, T = unknown>(
|
|
21
|
-
config: RequestConfig<T>,
|
|
22
|
-
): Promise<ApiResponse<R>> {
|
|
23
|
-
const method = (config.method || 'GET').toUpperCase()
|
|
24
|
-
|
|
25
|
-
if (!isMXAjaxType(method)) {
|
|
26
|
-
throw new Error(`敏行 AJAX 不支持 ${method} 请求`)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const response = await ajax<ApiResponse<R>>({
|
|
30
|
-
type: method,
|
|
31
|
-
url: appendQuery(config.url, config.params),
|
|
32
|
-
data: config.data,
|
|
33
|
-
dataType: 'text',
|
|
34
|
-
async: true,
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
return response.data
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function isMXAjaxType(method: string): method is MXAjaxType {
|
|
41
|
-
return method === 'GET' || method === 'POST' || method === 'PUT' || method === 'DELETE'
|
|
42
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
|
|
10
|
-
const app = createApp(App)
|
|
11
|
-
const pinia = createPinia()
|
|
12
|
-
|
|
13
|
-
pinia.use(piniaPluginPersistedstate)
|
|
14
|
-
|
|
15
|
-
app.use(pinia)
|
|
16
|
-
app.use(router)
|
|
17
|
-
|
|
18
|
-
// 等待原生环境检测完成后再挂载,确保所有组件读到的 isNative 都是正确值
|
|
19
|
-
const appStore = useAppStore()
|
|
20
|
-
appStore.initNativeDetection()
|
|
21
|
-
|
|
22
|
-
// 测试环境 + 原生设备:加载 vConsole 调试面板
|
|
23
|
-
if (import.meta.env.VITE_APP_ENV === 'test' && appStore.isNative) {
|
|
24
|
-
const { default: VConsole } = await import('vconsole')
|
|
25
|
-
new VConsole()
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
app.mount('#app')
|
|
@@ -1,70 +0,0 @@
|
|
|
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
|
-
},
|
|
18
|
-
{
|
|
19
|
-
path: '/rmb-position',
|
|
20
|
-
name: 'RmbPosition',
|
|
21
|
-
component: () => import('@/views/rmb-position/index.vue'),
|
|
22
|
-
meta: { requiresAuth: true },
|
|
23
|
-
},
|
|
24
|
-
{
|
|
25
|
-
path: '/foreign-position',
|
|
26
|
-
name: 'ForeignPosition',
|
|
27
|
-
component: () => import('@/views/foreign-position/index.vue'),
|
|
28
|
-
meta: { requiresAuth: true },
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
path: '/pbc-position',
|
|
32
|
-
name: 'PbcPosition',
|
|
33
|
-
component: () => import('@/views/pbc-position/index.vue'),
|
|
34
|
-
meta: { requiresAuth: true },
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
path: '/position-estimate',
|
|
38
|
-
name: 'PositionEstimate',
|
|
39
|
-
component: () => import('@/views/position-estimate/index.vue'),
|
|
40
|
-
meta: { requiresAuth: true },
|
|
41
|
-
},
|
|
42
|
-
{
|
|
43
|
-
path: '/net-debit',
|
|
44
|
-
name: 'NetDebit',
|
|
45
|
-
component: () => import('@/views/net-debit/index.vue'),
|
|
46
|
-
meta: { requiresAuth: true },
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
path: '/clearing-detail',
|
|
50
|
-
name: 'ClearingDetail',
|
|
51
|
-
component: () => import('@/views/clearing-detail/index.vue'),
|
|
52
|
-
meta: { requiresAuth: true },
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
path: '/warning',
|
|
56
|
-
name: 'Warning',
|
|
57
|
-
component: () => import('@/views/warning/index.vue'),
|
|
58
|
-
meta: { requiresAuth: true },
|
|
59
|
-
},
|
|
60
|
-
],
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
router.beforeEach((to) => {
|
|
64
|
-
const userStore = useUserStore()
|
|
65
|
-
if (to.meta.requiresAuth && !userStore.token) {
|
|
66
|
-
return { name: 'Login' }
|
|
67
|
-
}
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
export default router
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
import { isNativeApp } 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
|
-
function initNativeDetection() {
|
|
20
|
-
isNative.value = isNativeApp()
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return { isNative, initNativeDetection }
|
|
24
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { defineStore } from 'pinia'
|
|
2
|
-
|
|
3
|
-
const TOKEN_KEY = 'token'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 用户状态 Store
|
|
7
|
-
*
|
|
8
|
-
* 使用 Composition API 风格(setup 语法)定义,通过 pinia-plugin-persistedstate
|
|
9
|
-
* 自动将 state 持久化到 localStorage,刷新页面后状态不会丢失。
|
|
10
|
-
*/
|
|
11
|
-
export const useUserStore = defineStore(
|
|
12
|
-
'user',
|
|
13
|
-
|
|
14
|
-
() => {
|
|
15
|
-
// -------------------------------- State --------------------------------
|
|
16
|
-
|
|
17
|
-
/** 登录凭证,登录成功后由后端返回,后续请求通过请求头携带 */
|
|
18
|
-
const token = ref('')
|
|
19
|
-
|
|
20
|
-
// ------------------------------ Actions --------------------------------
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 设置 token
|
|
24
|
-
* 登录成功后调用,触发 persist 插件自动写入 localStorage
|
|
25
|
-
*/
|
|
26
|
-
function setToken(value: string) {
|
|
27
|
-
token.value = value
|
|
28
|
-
localStorage.setItem(TOKEN_KEY, value)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 清空 token
|
|
33
|
-
* 退出登录时调用,触发 persist 插件自动清除 localStorage 对应条目
|
|
34
|
-
*/
|
|
35
|
-
function clearToken() {
|
|
36
|
-
token.value = ''
|
|
37
|
-
localStorage.removeItem(TOKEN_KEY)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// ----------------------------- Return ----------------------------------
|
|
41
|
-
|
|
42
|
-
return { token, setToken, clearToken }
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 持久化配置
|
|
47
|
-
* true = 全量持久化(state 中所有字段自动写入/恢复 localStorage)
|
|
48
|
-
* 如需精细控制,可替换为对象形式:
|
|
49
|
-
* persist: { key: 'user', storage: localStorage, paths: ['token'] }
|
|
50
|
-
*/
|
|
51
|
-
{ persist: true },
|
|
52
|
-
)
|
|
@@ -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
|
-
}
|