@movk/nuxt 1.1.1 → 1.2.0
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/README.md +5 -29
- package/dist/module.d.mts +3 -31
- package/dist/module.json +3 -3
- package/dist/module.mjs +135 -77
- package/dist/runtime/auto-form/controls.d.ts +221 -0
- package/dist/runtime/auto-form/controls.js +70 -0
- package/dist/runtime/{utils → auto-form}/field-utils.d.ts +4 -20
- package/dist/runtime/{utils → auto-form}/field-utils.js +1 -2
- package/dist/runtime/auto-form/metadata.d.ts +22 -0
- package/dist/runtime/auto-form/metadata.js +53 -0
- package/dist/runtime/auto-form/provider.d.ts +27 -0
- package/dist/runtime/{internal/useAutoFormProvider.js → auto-form/provider.js} +1 -1
- package/dist/runtime/{utils → auto-form}/reactive-utils.d.ts +4 -22
- package/dist/runtime/{utils → auto-form}/schema-introspector.d.ts +3 -9
- package/dist/runtime/{utils → auto-form}/schema-introspector.js +11 -9
- package/dist/runtime/components/AutoForm.d.vue.ts +4 -5
- package/dist/runtime/components/AutoForm.vue +12 -35
- package/dist/runtime/components/AutoForm.vue.d.ts +4 -5
- package/dist/runtime/components/ColorChooser.d.vue.ts +10 -6
- package/dist/runtime/components/ColorChooser.vue +4 -7
- package/dist/runtime/components/ColorChooser.vue.d.ts +10 -6
- package/dist/runtime/components/DatePicker.d.vue.ts +16 -10
- package/dist/runtime/components/DatePicker.vue.d.ts +16 -10
- package/dist/runtime/components/SearchForm.d.vue.ts +171 -0
- package/dist/runtime/components/SearchForm.vue +216 -0
- package/dist/runtime/components/SearchForm.vue.d.ts +171 -0
- package/dist/runtime/components/SlideVerify.d.vue.ts +5 -32
- package/dist/runtime/components/SlideVerify.vue +4 -4
- package/dist/runtime/components/SlideVerify.vue.d.ts +5 -32
- package/dist/runtime/components/StarRating.d.vue.ts +8 -16
- package/dist/runtime/components/StarRating.vue +50 -65
- package/dist/runtime/components/StarRating.vue.d.ts +8 -16
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.d.vue.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue +16 -23
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererArray.vue.d.ts +10 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.d.vue.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue +50 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererChildren.vue.d.ts +26 -0
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue +2 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererField.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue +29 -64
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererLayout.vue.d.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.d.vue.ts +8 -2
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue +15 -69
- package/dist/runtime/components/auto-form-renderer/AutoFormRendererNested.vue.d.ts +8 -2
- package/dist/runtime/components/input/AsPhoneNumberInput.d.vue.ts +36 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue +35 -0
- package/dist/runtime/components/input/AsPhoneNumberInput.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithCharacterLimit.d.vue.ts +17 -9
- package/dist/runtime/components/input/WithCharacterLimit.vue +5 -5
- package/dist/runtime/components/input/WithCharacterLimit.vue.d.ts +17 -9
- package/dist/runtime/components/input/WithClear.d.vue.ts +13 -9
- package/dist/runtime/components/input/WithClear.vue +2 -2
- package/dist/runtime/components/input/WithClear.vue.d.ts +13 -9
- package/dist/runtime/components/input/WithCopy.d.vue.ts +16 -10
- package/dist/runtime/components/input/WithCopy.vue +3 -3
- package/dist/runtime/components/input/WithCopy.vue.d.ts +16 -10
- package/dist/runtime/components/input/WithFloatingLabel.d.vue.ts +36 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue +67 -0
- package/dist/runtime/components/input/WithFloatingLabel.vue.d.ts +36 -0
- package/dist/runtime/components/input/WithPasswordToggle.d.vue.ts +11 -9
- package/dist/runtime/components/input/WithPasswordToggle.vue +3 -3
- package/dist/runtime/components/input/WithPasswordToggle.vue.d.ts +11 -9
- package/dist/runtime/components/theme-picker/ThemePicker.d.vue.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePicker.vue +19 -25
- package/dist/runtime/components/theme-picker/ThemePicker.vue.d.ts +1 -1
- package/dist/runtime/components/theme-picker/ThemePickerButton.d.vue.ts +1 -7
- package/dist/runtime/components/theme-picker/ThemePickerButton.vue.d.ts +1 -7
- package/dist/runtime/composables/index.d.ts +8 -0
- package/dist/runtime/composables/index.js +8 -0
- package/dist/runtime/composables/useApiFetch.d.ts +17 -14
- package/dist/runtime/composables/useApiFetch.js +3 -28
- package/dist/runtime/composables/useAutoForm.d.ts +14 -98
- package/dist/runtime/composables/useAutoForm.js +37 -157
- package/dist/runtime/composables/useClientApiFetch.d.ts +5 -6
- package/dist/runtime/composables/useDownloadWithProgress.js +5 -6
- package/dist/runtime/composables/useLazyApiFetch.d.ts +18 -0
- package/dist/runtime/composables/useLazyApiFetch.js +4 -0
- package/dist/runtime/composables/useTheme.d.ts +17 -14
- package/dist/runtime/composables/useTheme.js +68 -72
- package/dist/runtime/composables/useUploadWithProgress.d.ts +2 -2
- package/dist/runtime/composables/useUploadWithProgress.js +7 -7
- package/dist/runtime/constants/api-defaults.d.ts +9 -0
- package/dist/runtime/constants/api-defaults.js +32 -0
- package/dist/runtime/constants/auto-form.d.ts +0 -2
- package/dist/runtime/constants/auto-form.js +0 -25
- package/dist/runtime/constants/grid-cols.d.ts +7 -0
- package/dist/runtime/constants/grid-cols.js +44 -0
- package/dist/runtime/plugins/api.factory.js +78 -121
- package/dist/runtime/plugins/theme.js +44 -64
- package/dist/runtime/style.css +1 -1
- package/dist/runtime/types/api.d.ts +277 -146
- package/dist/runtime/types/auto-form.d.ts +122 -411
- package/dist/runtime/types/index.d.ts +3 -2
- package/dist/runtime/types/index.js +3 -2
- package/dist/runtime/types/module.d.ts +96 -0
- package/dist/runtime/types/theme.d.ts +2 -0
- package/dist/runtime/types/zod.d.ts +11 -10
- package/dist/runtime/utils/api-utils.d.ts +27 -48
- package/dist/runtime/utils/api-utils.js +18 -47
- package/dist/runtime/utils/meta.d.ts +7 -0
- package/dist/runtime/utils/meta.js +16 -0
- package/dist/types.d.mts +6 -2
- package/package.json +68 -37
- package/dist/runtime/composables/useApiAuth.d.ts +0 -47
- package/dist/runtime/composables/useApiAuth.js +0 -66
- package/dist/runtime/internal/useAutoFormProvider.d.ts +0 -50
- package/dist/runtime/schemas/api.d.ts +0 -590
- package/dist/runtime/schemas/api.js +0 -228
- package/dist/runtime/server/api/_movk/session.post.d.ts +0 -10
- package/dist/runtime/server/api/_movk/session.post.js +0 -18
- package/dist/runtime/types/auth.d.ts +0 -34
- package/dist/runtime/types/auto-form-renderer.d.ts +0 -22
- package/dist/runtime/types/components.d.ts +0 -43
- package/dist/runtime/utils/auto-form.d.ts +0 -3
- package/dist/runtime/utils/auto-form.js +0 -18
- /package/dist/runtime/{utils → auto-form}/reactive-utils.js +0 -0
- /package/dist/runtime/types/{auto-form-renderer.js → module.js} +0 -0
- /package/dist/runtime/types/{components.js → theme.js} +0 -0
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import type { $Fetch,
|
|
1
|
+
import type { $Fetch, FetchError } from 'ofetch';
|
|
2
2
|
import type { UseFetchOptions as NuxtUseFetchOptions, AsyncData } from 'nuxt/app';
|
|
3
3
|
import type { ToastProps } from '@nuxt/ui';
|
|
4
|
-
import type { z } from 'zod/v4';
|
|
5
|
-
import type { apiEndpointPublicConfigSchema, movkApiPublicConfigSchema, movkApiPrivateConfigSchema, movkApiFullConfigSchema, apiUnauthorizedConfigSchema, apiResponseConfigSchema, apiAuthConfigSchema, apiToastConfigSchema } from '../schemas/api.js';
|
|
6
|
-
import type { User, UserSession, UserSessionComposable } from '#auth-utils';
|
|
7
4
|
declare module 'ofetch' {
|
|
8
5
|
interface FetchOptions {
|
|
9
6
|
context?: ApiFetchContext;
|
|
@@ -19,47 +16,264 @@ export interface ApiFetchContext {
|
|
|
19
16
|
/** 是否跳过业务状态码检查 */
|
|
20
17
|
skipBusinessCheck?: boolean;
|
|
21
18
|
}
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
19
|
+
/**
|
|
20
|
+
* API 响应配置
|
|
21
|
+
* @description 定义业务状态码判断规则和数据/消息字段的映射关系
|
|
22
|
+
*/
|
|
23
|
+
export interface ApiResponseConfig {
|
|
24
|
+
/**
|
|
25
|
+
* 表示成功的业务状态码列表
|
|
26
|
+
* @defaultValue [200, 0]
|
|
27
|
+
*/
|
|
28
|
+
successCodes: (number | string)[];
|
|
29
|
+
/**
|
|
30
|
+
* 响应中业务状态码的字段名
|
|
31
|
+
* @defaultValue 'code'
|
|
32
|
+
*/
|
|
33
|
+
codeKey: string;
|
|
34
|
+
/**
|
|
35
|
+
* 响应中消息内容的字段名
|
|
36
|
+
* @defaultValue 'message'
|
|
37
|
+
*/
|
|
38
|
+
messageKey: string;
|
|
39
|
+
/**
|
|
40
|
+
* 响应中业务数据的字段名
|
|
41
|
+
* @defaultValue 'data'
|
|
42
|
+
*/
|
|
43
|
+
dataKey: string;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 401 未授权处理配置
|
|
47
|
+
* @description 定义当接收到 401 响应时的自动处理行为
|
|
48
|
+
*/
|
|
49
|
+
export interface ApiUnauthorizedConfig {
|
|
50
|
+
/**
|
|
51
|
+
* 是否自动重定向到登录页
|
|
52
|
+
* @defaultValue true
|
|
53
|
+
*/
|
|
54
|
+
redirect?: boolean;
|
|
55
|
+
/**
|
|
56
|
+
* 登录页路径
|
|
57
|
+
* @defaultValue '/login'
|
|
58
|
+
*/
|
|
59
|
+
loginPath?: string;
|
|
60
|
+
/**
|
|
61
|
+
* 是否清除用户会话
|
|
62
|
+
* @defaultValue true
|
|
63
|
+
*/
|
|
64
|
+
clearSession?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* API 认证配置
|
|
68
|
+
* @description 定义认证令牌的来源、格式和请求头配置
|
|
69
|
+
*/
|
|
70
|
+
export interface ApiAuthConfig {
|
|
71
|
+
/**
|
|
72
|
+
* 是否启用认证
|
|
73
|
+
* @defaultValue false
|
|
74
|
+
*/
|
|
75
|
+
enabled: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* 令牌来源类型
|
|
78
|
+
* @defaultValue 'session'
|
|
79
|
+
*/
|
|
80
|
+
tokenSource: 'session';
|
|
81
|
+
/**
|
|
82
|
+
* 令牌在会话对象中的路径(支持点号分隔的嵌套路径)
|
|
83
|
+
* @defaultValue 'token'
|
|
84
|
+
* @example 'token' | 'user.accessToken' | 'auth.credentials.token'
|
|
85
|
+
*/
|
|
86
|
+
sessionTokenPath: string;
|
|
87
|
+
/**
|
|
88
|
+
* 令牌类型前缀
|
|
89
|
+
* @defaultValue 'Bearer'
|
|
90
|
+
*/
|
|
91
|
+
tokenType: 'Bearer' | 'Basic' | 'Custom';
|
|
92
|
+
/**
|
|
93
|
+
* 自定义令牌类型前缀(当 tokenType 为 'Custom' 时使用)
|
|
94
|
+
*/
|
|
95
|
+
customTokenType?: string;
|
|
96
|
+
/**
|
|
97
|
+
* 认证请求头名称
|
|
98
|
+
* @defaultValue 'Authorization'
|
|
99
|
+
*/
|
|
100
|
+
headerName: string;
|
|
101
|
+
/**
|
|
102
|
+
* 401 未授权处理配置
|
|
103
|
+
*/
|
|
104
|
+
unauthorized?: ApiUnauthorizedConfig;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Toast 提示配置
|
|
108
|
+
* @description 定义成功和错误提示的全局样式和行为
|
|
109
|
+
*/
|
|
110
|
+
export interface ApiToastConfig {
|
|
111
|
+
/**
|
|
112
|
+
* 是否启用 Toast 提示
|
|
113
|
+
* @defaultValue true
|
|
114
|
+
*/
|
|
115
|
+
enabled: boolean;
|
|
116
|
+
/**
|
|
117
|
+
* 成功提示配置
|
|
118
|
+
*/
|
|
119
|
+
success?: {
|
|
120
|
+
/**
|
|
121
|
+
* 是否显示成功提示
|
|
122
|
+
* @defaultValue true
|
|
123
|
+
*/
|
|
124
|
+
show: boolean;
|
|
125
|
+
/**
|
|
126
|
+
* 提示颜色
|
|
127
|
+
* @defaultValue 'success'
|
|
128
|
+
*/
|
|
129
|
+
color: string;
|
|
130
|
+
/**
|
|
131
|
+
* 图标类名
|
|
132
|
+
* @defaultValue 'i-lucide-circle-check'
|
|
133
|
+
*/
|
|
134
|
+
icon?: string;
|
|
135
|
+
/**
|
|
136
|
+
* 显示时长(毫秒)
|
|
137
|
+
* @defaultValue 3000
|
|
138
|
+
*/
|
|
139
|
+
duration: number;
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* 错误提示配置
|
|
143
|
+
*/
|
|
144
|
+
error?: {
|
|
145
|
+
/**
|
|
146
|
+
* 是否显示错误提示
|
|
147
|
+
* @defaultValue true
|
|
148
|
+
*/
|
|
149
|
+
show: boolean;
|
|
150
|
+
/**
|
|
151
|
+
* 提示颜色
|
|
152
|
+
* @defaultValue 'error'
|
|
153
|
+
*/
|
|
154
|
+
color: string;
|
|
155
|
+
/**
|
|
156
|
+
* 图标类名
|
|
157
|
+
* @defaultValue 'i-lucide-circle-x'
|
|
158
|
+
*/
|
|
159
|
+
icon?: string;
|
|
160
|
+
/**
|
|
161
|
+
* 显示时长(毫秒)
|
|
162
|
+
* @defaultValue 3000
|
|
163
|
+
*/
|
|
164
|
+
duration: number;
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* API 端点公共配置
|
|
169
|
+
* @description 定义单个 API 端点的配置(可在客户端访问的配置)
|
|
170
|
+
*/
|
|
171
|
+
export interface ApiEndpointPublicConfig {
|
|
172
|
+
/**
|
|
173
|
+
* 端点的基础 URL
|
|
174
|
+
*/
|
|
175
|
+
baseURL: string;
|
|
176
|
+
/**
|
|
177
|
+
* 端点别名(用于标识)
|
|
178
|
+
*/
|
|
179
|
+
alias?: string;
|
|
180
|
+
/**
|
|
181
|
+
* 端点级别的认证配置(覆盖全局配置)
|
|
182
|
+
*/
|
|
183
|
+
auth?: Partial<ApiAuthConfig>;
|
|
184
|
+
/**
|
|
185
|
+
* 端点级别的 Toast 配置(覆盖全局配置)
|
|
186
|
+
*/
|
|
187
|
+
toast?: Partial<ApiToastConfig>;
|
|
188
|
+
/**
|
|
189
|
+
* 端点级别的响应配置(覆盖全局配置)
|
|
190
|
+
*/
|
|
191
|
+
response?: Partial<ApiResponseConfig>;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Movk API 模块公共配置
|
|
195
|
+
* @description 定义模块的全局配置(可在客户端访问)
|
|
196
|
+
*/
|
|
197
|
+
export interface MovkApiPublicConfig {
|
|
198
|
+
/**
|
|
199
|
+
* 默认使用的端点名称
|
|
200
|
+
* @defaultValue 'default'
|
|
201
|
+
*/
|
|
202
|
+
defaultEndpoint: string;
|
|
203
|
+
/**
|
|
204
|
+
* 是否启用调试模式(在控制台输出请求和响应日志)
|
|
205
|
+
* @defaultValue false
|
|
206
|
+
*/
|
|
207
|
+
debug: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* 端点配置映射
|
|
210
|
+
* @defaultValue { default: { baseURL: '/api' } }
|
|
211
|
+
*/
|
|
212
|
+
endpoints: Record<string, ApiEndpointPublicConfig>;
|
|
213
|
+
/**
|
|
214
|
+
* 全局响应配置(已合并默认值,运行时必然存在)
|
|
215
|
+
*/
|
|
216
|
+
response: ApiResponseConfig;
|
|
217
|
+
/**
|
|
218
|
+
* 全局认证配置(已合并默认值,运行时必然存在)
|
|
219
|
+
*/
|
|
220
|
+
auth: ApiAuthConfig;
|
|
221
|
+
/**
|
|
222
|
+
* 全局 Toast 配置(已合并默认值,运行时必然存在)
|
|
223
|
+
*/
|
|
224
|
+
toast: ApiToastConfig;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 端点私有配置(仅服务端)
|
|
228
|
+
* @description 从端点配置中拆分出的服务端专用字段,不会暴露给客户端
|
|
229
|
+
*/
|
|
230
|
+
export interface EndpointPrivateConfig {
|
|
231
|
+
/** 自定义请求头(仅服务端使用,不会暴露给客户端) */
|
|
232
|
+
headers?: Record<string, string>;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Movk API 模块完整配置
|
|
236
|
+
* @description 定义模块的完整配置(公共+私有),用于模块初始化时的配置验证
|
|
237
|
+
*/
|
|
238
|
+
export interface MovkApiFullConfig {
|
|
239
|
+
/**
|
|
240
|
+
* 是否启用 API 模块
|
|
241
|
+
* @defaultValue true
|
|
242
|
+
*/
|
|
243
|
+
enabled?: boolean;
|
|
244
|
+
/**
|
|
245
|
+
* 默认使用的端点名称
|
|
246
|
+
* @defaultValue 'default'
|
|
247
|
+
*/
|
|
248
|
+
defaultEndpoint?: string;
|
|
249
|
+
/**
|
|
250
|
+
* 是否启用调试模式
|
|
251
|
+
* @defaultValue false
|
|
252
|
+
*/
|
|
253
|
+
debug?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* 端点配置映射(包含公共和私有配置)
|
|
256
|
+
* @defaultValue { default: { baseURL: '/api' } }
|
|
257
|
+
*/
|
|
258
|
+
endpoints?: Record<string, ApiEndpointPublicConfig & EndpointPrivateConfig>;
|
|
259
|
+
/**
|
|
260
|
+
* 全局响应配置
|
|
261
|
+
*/
|
|
262
|
+
response?: Partial<ApiResponseConfig>;
|
|
263
|
+
/**
|
|
264
|
+
* 全局认证配置
|
|
265
|
+
*/
|
|
266
|
+
auth?: Partial<ApiAuthConfig>;
|
|
267
|
+
/**
|
|
268
|
+
* 全局 Toast 配置
|
|
269
|
+
*/
|
|
270
|
+
toast?: Partial<ApiToastConfig>;
|
|
271
|
+
}
|
|
38
272
|
/**
|
|
39
273
|
* API 响应数据结构
|
|
40
|
-
* @description
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
export interface ApiResponse<T = unknown> {
|
|
44
|
-
/** 业务状态码 */
|
|
45
|
-
code?: number | string;
|
|
46
|
-
/** HTTP 状态码或业务状态 */
|
|
47
|
-
status?: number | string;
|
|
48
|
-
/** 消息内容(简写) */
|
|
49
|
-
msg?: string;
|
|
50
|
-
/** 消息内容 */
|
|
51
|
-
message?: string;
|
|
52
|
-
/** 业务数据 */
|
|
53
|
-
data?: T;
|
|
54
|
-
/** 业务数据(别名) */
|
|
55
|
-
result?: T;
|
|
56
|
-
/** 认证令牌 */
|
|
57
|
-
token?: string;
|
|
58
|
-
/** 访问令牌 */
|
|
59
|
-
accessToken?: string;
|
|
60
|
-
/** 错误信息 */
|
|
61
|
-
error?: string | null;
|
|
62
|
-
/** 支持任意额外字段 */
|
|
274
|
+
* @description 字段名通过 ApiResponseConfig 的 codeKey/messageKey/dataKey 配置化读取
|
|
275
|
+
*/
|
|
276
|
+
export interface ApiResponse {
|
|
63
277
|
[key: string]: unknown;
|
|
64
278
|
}
|
|
65
279
|
/**
|
|
@@ -79,16 +293,14 @@ export interface ApiError extends Error {
|
|
|
79
293
|
* @description 合并全局配置和端点配置后的最终配置,供内部使用
|
|
80
294
|
*/
|
|
81
295
|
export interface ResolvedEndpointConfig extends ApiEndpointPublicConfig {
|
|
82
|
-
/**
|
|
83
|
-
auth:
|
|
84
|
-
/** Toast
|
|
85
|
-
toast:
|
|
86
|
-
/**
|
|
87
|
-
response:
|
|
296
|
+
/** 认证配置(已合并全局默认值) */
|
|
297
|
+
auth: ApiAuthConfig;
|
|
298
|
+
/** Toast 配置(已合并全局默认值) */
|
|
299
|
+
toast: ApiToastConfig;
|
|
300
|
+
/** 响应配置(已合并全局默认值) */
|
|
301
|
+
response: ApiResponseConfig;
|
|
88
302
|
/** 自定义请求头(仅服务端配置) */
|
|
89
303
|
headers?: Record<string, string>;
|
|
90
|
-
/** 内置请求钩子(内部使用) */
|
|
91
|
-
builtinHooks?: FetchHooks;
|
|
92
304
|
}
|
|
93
305
|
/**
|
|
94
306
|
* 请求级别的 Toast 提示选项
|
|
@@ -104,115 +316,34 @@ export interface RequestToastOptions {
|
|
|
104
316
|
/** 自定义错误消息 */
|
|
105
317
|
errorMessage?: string;
|
|
106
318
|
}
|
|
319
|
+
/**
|
|
320
|
+
* API 实例类型
|
|
321
|
+
* @description $fetch.create() 返回的实例,附加 use() 方法支持多端点切换
|
|
322
|
+
*/
|
|
323
|
+
export type ApiInstance = $Fetch & {
|
|
324
|
+
/** 切换到指定端点,返回该端点的 $fetch 实例 */
|
|
325
|
+
use: (endpoint: string) => ApiInstance;
|
|
326
|
+
};
|
|
107
327
|
/**
|
|
108
328
|
* useApiFetch 的扩展选项
|
|
109
|
-
* @template
|
|
110
|
-
* @template DataT - 转换后的数据类型
|
|
329
|
+
* @template T - 业务数据类型(已解包)
|
|
111
330
|
*/
|
|
112
|
-
export interface ApiFetchExtras
|
|
331
|
+
export interface ApiFetchExtras {
|
|
113
332
|
/** 使用的端点名称(默认使用 defaultEndpoint) */
|
|
114
333
|
endpoint?: string;
|
|
115
334
|
/** Toast 提示配置,设置为 false 禁用提示 */
|
|
116
335
|
toast?: RequestToastOptions | false;
|
|
117
336
|
/** 是否跳过业务状态码检查 */
|
|
118
337
|
skipBusinessCheck?: boolean;
|
|
119
|
-
/** 数据转换函数(应用于提取后的业务数据) */
|
|
120
|
-
transform?: (data: ResT) => DataT;
|
|
121
338
|
}
|
|
122
339
|
/**
|
|
123
340
|
* useApiFetch 选项类型
|
|
124
|
-
* @template
|
|
125
|
-
* @template DataT -
|
|
341
|
+
* @template T - 业务数据类型(已解包)
|
|
342
|
+
* @template DataT - transform 转换后的类型(默认等于 T)
|
|
126
343
|
*/
|
|
127
|
-
export type UseApiFetchOptions<
|
|
344
|
+
export type UseApiFetchOptions<T = unknown, DataT = T> = Omit<NuxtUseFetchOptions<T, DataT>, '$fetch' | 'context'> & ApiFetchExtras;
|
|
128
345
|
/**
|
|
129
346
|
* useApiFetch 返回值类型
|
|
130
|
-
* @template DataT -
|
|
347
|
+
* @template DataT - 最终数据类型
|
|
131
348
|
*/
|
|
132
349
|
export type UseApiFetchReturn<DataT> = AsyncData<DataT | null, FetchError | ApiError | null>;
|
|
133
|
-
/**
|
|
134
|
-
* 文件下载选项
|
|
135
|
-
*/
|
|
136
|
-
export interface DownloadOptions extends Omit<FetchOptions<'json'>, 'responseType'> {
|
|
137
|
-
/** Toast 提示配置,设置为 false 禁用提示 */
|
|
138
|
-
toast?: RequestToastOptions | false;
|
|
139
|
-
/** 下载进度回调(0-100) */
|
|
140
|
-
onProgress?: (progress: number) => void;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* 文件上传选项
|
|
144
|
-
*/
|
|
145
|
-
export interface UploadOptions extends Omit<FetchOptions<'json'>, 'responseType' | 'body'> {
|
|
146
|
-
/**
|
|
147
|
-
* FormData 中的文件字段名
|
|
148
|
-
* @defaultValue 'file'
|
|
149
|
-
*/
|
|
150
|
-
fieldName?: string;
|
|
151
|
-
/** Toast 提示配置,设置为 false 禁用提示 */
|
|
152
|
-
toast?: RequestToastOptions | false;
|
|
153
|
-
/** 上传进度回调(0-100) */
|
|
154
|
-
onProgress?: (progress: number) => void;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* API 客户端接口
|
|
158
|
-
* @description 提供统一的 API 请求、文件上传下载等功能
|
|
159
|
-
*/
|
|
160
|
-
export interface ApiClient {
|
|
161
|
-
/** ofetch 实例,用于发起请求 */
|
|
162
|
-
$fetch: $Fetch;
|
|
163
|
-
/** 切换到指定端点 */
|
|
164
|
-
use: (endpoint: string) => ApiClient;
|
|
165
|
-
/** 下载文件 */
|
|
166
|
-
download: (url: string, filename?: string, options?: DownloadOptions) => Promise<void>;
|
|
167
|
-
/**
|
|
168
|
-
* 上传文件
|
|
169
|
-
* @template T - API 响应数据类型
|
|
170
|
-
*/
|
|
171
|
-
upload: <T = unknown>(url: string, file: File | File[] | FormData, options?: UploadOptions) => Promise<ApiResponse<T>>;
|
|
172
|
-
/** 获取当前端点配置 */
|
|
173
|
-
getConfig: () => ResolvedEndpointConfig;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* 登录选项
|
|
177
|
-
* @template LoginRData - 登录接口响应数据类型
|
|
178
|
-
*/
|
|
179
|
-
export interface LoginOptions<LoginRData = unknown> {
|
|
180
|
-
/** 登录接口路径 */
|
|
181
|
-
loginPath: string;
|
|
182
|
-
/** 登录凭证(用户名/密码等) */
|
|
183
|
-
credentials: unknown;
|
|
184
|
-
/** 获取用户信息的接口路径(可选,如果登录接口不返回用户信息) */
|
|
185
|
-
userInfoPath?: string;
|
|
186
|
-
/**
|
|
187
|
-
* 从登录响应中提取令牌的函数
|
|
188
|
-
* @defaultValue 从 response.token 或 response.data.token 提取
|
|
189
|
-
*/
|
|
190
|
-
tokenExtractor?: (response: ApiResponse<LoginRData>) => string | null | undefined;
|
|
191
|
-
/**
|
|
192
|
-
* 自定义会话构建函数
|
|
193
|
-
* @defaultValue 使用 { user, token } 作为会话数据
|
|
194
|
-
*/
|
|
195
|
-
sessionBuilder?: (userInfo: User, token: string) => UserSession;
|
|
196
|
-
/** 使用的端点名称(默认使用 defaultEndpoint) */
|
|
197
|
-
endpoint?: string;
|
|
198
|
-
}
|
|
199
|
-
/**
|
|
200
|
-
* 登录结果
|
|
201
|
-
*/
|
|
202
|
-
export interface LoginResult {
|
|
203
|
-
/** 用户信息 */
|
|
204
|
-
user: User;
|
|
205
|
-
/** 认证令牌 */
|
|
206
|
-
token: string;
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* useApiAuth 返回值类型
|
|
210
|
-
* @description 扩展 nuxt-auth-utils 的 UserSessionComposable,添加 login 方法
|
|
211
|
-
*/
|
|
212
|
-
export interface UseApiAuthReturn extends UserSessionComposable {
|
|
213
|
-
/**
|
|
214
|
-
* 登录方法
|
|
215
|
-
* @template LoginRData - 登录接口响应数据类型
|
|
216
|
-
*/
|
|
217
|
-
login: <LoginRData = unknown>(options: LoginOptions<LoginRData>) => Promise<LoginResult>;
|
|
218
|
-
}
|