@moluoxixi/ajax-package 0.0.32 → 0.0.34
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 +1016 -0
- package/es/BaseHttpClient.d.ts +111 -0
- package/es/SystemErrorDialog.d.ts +4 -0
- package/es/_types/api.d.ts +115 -2
- package/es/_types/emits.d.ts +7 -0
- package/es/_types/props.d.ts +18 -2
- package/es/_utils/messageWrapper.d.ts +4 -0
- package/es/_utils/notificationWrapper.d.ts +4 -0
- package/es/_utils/systemErrorInfo.d.ts +21 -0
- package/es/class.d.ts +179 -6
- package/es/index.mjs +5154 -63
- package/es/netseriver.d.ts +14 -0
- package/package.json +2 -2
package/es/BaseHttpClient.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, default as axios } from 'axios';
|
|
2
2
|
import { BaseHttpClientConfig } from './_types/index.ts';
|
|
3
3
|
import { MessageInstance, NotificationInstance } from './_utils/index.ts';
|
|
4
|
+
/**
|
|
5
|
+
* BaseHttpClient 基础类
|
|
6
|
+
* 提供最基础的 HTTP 请求功能,包括:
|
|
7
|
+
* - 创建 axios 实例
|
|
8
|
+
* - 自动添加 Token
|
|
9
|
+
* - 基础错误处理(401、超时等)
|
|
10
|
+
* - HTTP 方法(get、post、put、delete、all)
|
|
11
|
+
* - 文件上传
|
|
12
|
+
*/
|
|
4
13
|
export default class BaseHttpClient {
|
|
5
14
|
protected baseURL: string;
|
|
6
15
|
protected timeout: number;
|
|
@@ -11,22 +20,124 @@ export default class BaseHttpClient {
|
|
|
11
20
|
protected messageInstance: MessageInstance;
|
|
12
21
|
protected notificationInstance: NotificationInstance;
|
|
13
22
|
protected addSign?: (config: AxiosRequestConfig) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 创建 BaseHttpClient 实例
|
|
25
|
+
* @param config - HTTP 客户端配置对象
|
|
26
|
+
*/
|
|
14
27
|
constructor(config: BaseHttpClientConfig);
|
|
28
|
+
/**
|
|
29
|
+
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
30
|
+
* @param config - 请求配置对象
|
|
31
|
+
* @returns 处理后的请求配置
|
|
32
|
+
*/
|
|
15
33
|
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
|
|
34
|
+
/**
|
|
35
|
+
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
36
|
+
* 按照标准 HTTP 结构处理响应
|
|
37
|
+
* @param response - Axios 响应对象
|
|
38
|
+
* @returns 解析后的响应数据
|
|
39
|
+
*/
|
|
16
40
|
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
41
|
+
/**
|
|
42
|
+
* 处理 HTTP 状态码
|
|
43
|
+
* 子类可重写此方法来自定义 HTTP 状态码处理逻辑
|
|
44
|
+
* @param response - Axios 响应对象
|
|
45
|
+
*/
|
|
17
46
|
protected handleHttpStatus(response: AxiosResponse): void;
|
|
47
|
+
/**
|
|
48
|
+
* 处理成功响应
|
|
49
|
+
* 子类可重写此方法来自定义成功响应的处理逻辑
|
|
50
|
+
* @param response - Axios 响应对象
|
|
51
|
+
* @returns 解析后的响应数据
|
|
52
|
+
*/
|
|
18
53
|
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
54
|
+
/**
|
|
55
|
+
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
56
|
+
* 按照标准 HTTP 错误结构处理错误
|
|
57
|
+
* @param error - Axios 错误对象
|
|
58
|
+
* @returns 处理后的错误对象
|
|
59
|
+
*/
|
|
19
60
|
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
61
|
+
/**
|
|
62
|
+
* 处理认证错误(401 - 未授权/登录失效)
|
|
63
|
+
* 子类可重写此方法来自定义认证错误处理逻辑
|
|
64
|
+
* @param error - Axios 错误对象
|
|
65
|
+
*/
|
|
20
66
|
protected handleAuthenticationError(error: AxiosError): void;
|
|
67
|
+
/**
|
|
68
|
+
* 处理超时错误
|
|
69
|
+
* 子类可重写此方法来自定义超时错误处理逻辑
|
|
70
|
+
* @param error - Axios 错误对象
|
|
71
|
+
*/
|
|
21
72
|
protected handleTimeoutError(error: AxiosError): void;
|
|
73
|
+
/**
|
|
74
|
+
* 处理网络错误(其他错误)
|
|
75
|
+
* 子类可重写此方法来自定义网络错误处理逻辑
|
|
76
|
+
* @param error - Axios 错误对象
|
|
77
|
+
*/
|
|
22
78
|
protected handleNetworkError(error: AxiosError): void;
|
|
79
|
+
/**
|
|
80
|
+
* 设置请求和响应拦截器
|
|
81
|
+
* 请求拦截器:自动添加 Token
|
|
82
|
+
* 响应拦截器:处理成功响应和错误响应(401、超时等)
|
|
83
|
+
*/
|
|
23
84
|
private setupInterceptors;
|
|
85
|
+
/**
|
|
86
|
+
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
87
|
+
* @param config - Axios 请求配置对象
|
|
88
|
+
* @returns 解析后的响应数据
|
|
89
|
+
*/
|
|
24
90
|
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
91
|
+
/**
|
|
92
|
+
* 发送 GET 请求
|
|
93
|
+
* @param url - 请求 URL 路径
|
|
94
|
+
* @param params - 查询参数对象
|
|
95
|
+
* @param config - 额外的请求配置
|
|
96
|
+
* @returns 解析后的响应数据
|
|
97
|
+
*/
|
|
25
98
|
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
99
|
+
/**
|
|
100
|
+
* 发送 POST 请求
|
|
101
|
+
* @param url - 请求 URL 路径
|
|
102
|
+
* @param data - 请求体数据
|
|
103
|
+
* @param config - 额外的请求配置
|
|
104
|
+
* @returns 解析后的响应数据
|
|
105
|
+
*/
|
|
26
106
|
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
107
|
+
/**
|
|
108
|
+
* 发送 DELETE 请求
|
|
109
|
+
* @param url - 请求 URL 路径
|
|
110
|
+
* @param params - 查询参数对象
|
|
111
|
+
* @param config - 额外的请求配置
|
|
112
|
+
* @returns 解析后的响应数据
|
|
113
|
+
*/
|
|
27
114
|
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
115
|
+
/**
|
|
116
|
+
* 发送 PUT 请求
|
|
117
|
+
* @param url - 请求 URL 路径
|
|
118
|
+
* @param data - 请求体数据
|
|
119
|
+
* @param config - 额外的请求配置
|
|
120
|
+
* @returns 解析后的响应数据
|
|
121
|
+
*/
|
|
28
122
|
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
123
|
+
/**
|
|
124
|
+
* 批量请求,并发发送多个请求
|
|
125
|
+
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
126
|
+
* @returns 所有请求的响应数据数组
|
|
127
|
+
*/
|
|
29
128
|
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
129
|
+
/**
|
|
130
|
+
* 文件上传,将文件包装为 FormData 发送
|
|
131
|
+
* @param url - 上传地址
|
|
132
|
+
* @param file - 文件对象
|
|
133
|
+
* @param config - 额外的请求配置
|
|
134
|
+
* @returns 解析后的响应数据
|
|
135
|
+
*/
|
|
30
136
|
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
137
|
+
/**
|
|
138
|
+
* 下载文件,将 Blob 对象下载到本地
|
|
139
|
+
* @param blob - Blob 对象
|
|
140
|
+
* @param filename - 文件名,如果不提供则使用时间戳
|
|
141
|
+
*/
|
|
31
142
|
downloadFile(blob: Blob, filename?: string): void;
|
|
32
143
|
}
|
package/es/_types/api.d.ts
CHANGED
|
@@ -2,44 +2,157 @@ import { AxiosRequestConfig } from 'axios';
|
|
|
2
2
|
import { App } from 'vue';
|
|
3
3
|
import { MessageInstance } from '../_utils/index.ts';
|
|
4
4
|
import { default as BaseApi } from '../class.ts';
|
|
5
|
+
/**
|
|
6
|
+
* BaseHttpClient 基础配置接口,包含最基础的 HTTP 客户端配置
|
|
7
|
+
*/
|
|
5
8
|
export interface BaseHttpClientConfig {
|
|
9
|
+
/** API 基础地址 */
|
|
6
10
|
baseURL?: string;
|
|
11
|
+
/** 请求超时时间(毫秒),默认 5000 */
|
|
7
12
|
timeout?: number;
|
|
13
|
+
/** 请求超时回调函数,接收 messageInstance 用于显示消息提示 */
|
|
8
14
|
onTimeout?: (messageInstance: MessageInstance) => void;
|
|
15
|
+
/** 获取 token 的函数,每次请求前自动调用 */
|
|
9
16
|
getToken?: () => string | null;
|
|
17
|
+
/** 登录失效回调函数,当检测到 401 错误时调用,接收 messageInstance 用于显示消息提示 */
|
|
10
18
|
onLoginRequired?: (messageInstance: MessageInstance) => void;
|
|
19
|
+
/** 允许其他任意配置项,会直接传递给 axios.create */
|
|
11
20
|
[key: string]: any;
|
|
12
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* BaseApi 配置接口,用于配置 BaseApi 实例的所有选项
|
|
24
|
+
* 继承 BaseHttpClientConfig,添加响应字段映射和系统异常弹窗配置
|
|
25
|
+
*/
|
|
13
26
|
export interface BaseApiConfig extends BaseHttpClientConfig {
|
|
27
|
+
/** 响应字段映射配置 */
|
|
14
28
|
responseFields?: {
|
|
29
|
+
/** 响应状态码字段名,默认 'Code' */
|
|
15
30
|
code?: string;
|
|
31
|
+
/** 响应消息字段名,默认 'Message' */
|
|
16
32
|
message?: string;
|
|
33
|
+
/** 响应数据字段名,默认 'data' */
|
|
17
34
|
data?: string;
|
|
35
|
+
/** 错误数组字段名 */
|
|
18
36
|
errors?: string;
|
|
37
|
+
/** 提示信息字段名 */
|
|
19
38
|
tips?: string;
|
|
20
39
|
};
|
|
40
|
+
/** 是否启用 code === -1 的系统异常弹窗,默认为 true */
|
|
21
41
|
enableSystemErrorDialog?: boolean;
|
|
42
|
+
/** 系统错误消息提示文本,默认为 '系统错误' */
|
|
22
43
|
systemErrorMessage?: string;
|
|
23
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Vue Axios 插件配置选项
|
|
47
|
+
*/
|
|
24
48
|
export interface vueAxiosPluginOptionsType {
|
|
49
|
+
/** 默认 HTTP 服务配置 */
|
|
25
50
|
default?: BaseApiConfig;
|
|
51
|
+
/** 是否在所有组件中通过 mixin 注入 $http,默认为 true */
|
|
26
52
|
globalMixin?: boolean;
|
|
27
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Vue HTTP 服务类型,在 Vue 应用中通过 this.$http 或 inject('$http') 获取
|
|
56
|
+
*/
|
|
28
57
|
export type vueHttpServiceType = BaseApi;
|
|
58
|
+
/**
|
|
59
|
+
* Vue Axios 插件类型,定义了 Vue 插件的标准接口
|
|
60
|
+
*/
|
|
29
61
|
export interface vueAxiosPluginType {
|
|
62
|
+
/**
|
|
63
|
+
* 安装插件
|
|
64
|
+
* @param app - Vue 应用实例
|
|
65
|
+
* @param options - 插件配置选项
|
|
66
|
+
*/
|
|
30
67
|
install: (app: App, options?: vueAxiosPluginOptionsType) => void;
|
|
31
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* 通知配置选项
|
|
71
|
+
*/
|
|
32
72
|
export interface NotificationOptions {
|
|
73
|
+
/**
|
|
74
|
+
* 通知标题
|
|
75
|
+
*/
|
|
33
76
|
title?: string;
|
|
77
|
+
/**
|
|
78
|
+
* 通知类型
|
|
79
|
+
*/
|
|
34
80
|
type?: 'success' | 'error' | 'warning' | 'info';
|
|
81
|
+
/**
|
|
82
|
+
* 通知持续时间(毫秒)
|
|
83
|
+
*/
|
|
35
84
|
duration?: number;
|
|
85
|
+
/**
|
|
86
|
+
* 是否显示关闭按钮
|
|
87
|
+
*/
|
|
36
88
|
showClose?: boolean;
|
|
89
|
+
/**
|
|
90
|
+
* 自定义类名
|
|
91
|
+
*/
|
|
37
92
|
customClass?: string;
|
|
93
|
+
/**
|
|
94
|
+
* 自定义样式
|
|
95
|
+
*/
|
|
38
96
|
customStyle?: string | Record<string, any>;
|
|
97
|
+
/**
|
|
98
|
+
* 其他通知选项
|
|
99
|
+
*/
|
|
39
100
|
[key: string]: any;
|
|
40
101
|
}
|
|
41
|
-
|
|
102
|
+
/**
|
|
103
|
+
* 消息配置选项
|
|
104
|
+
*/
|
|
105
|
+
export interface MessageOptions {
|
|
106
|
+
/**
|
|
107
|
+
* 消息类型
|
|
108
|
+
*/
|
|
109
|
+
type?: 'success' | 'error' | 'warning' | 'info';
|
|
110
|
+
/**
|
|
111
|
+
* 消息内容
|
|
112
|
+
*/
|
|
113
|
+
message?: string;
|
|
114
|
+
/**
|
|
115
|
+
* 消息持续时间(毫秒)
|
|
116
|
+
*/
|
|
117
|
+
duration?: number;
|
|
118
|
+
/**
|
|
119
|
+
* 是否显示关闭按钮
|
|
120
|
+
*/
|
|
121
|
+
showClose?: boolean;
|
|
122
|
+
/**
|
|
123
|
+
* 自定义类名
|
|
124
|
+
*/
|
|
125
|
+
customClass?: string;
|
|
126
|
+
/**
|
|
127
|
+
* 其他消息选项
|
|
128
|
+
*/
|
|
129
|
+
[key: string]: any;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 消息相关配置选项
|
|
133
|
+
*/
|
|
134
|
+
export interface MessageConfigs {
|
|
135
|
+
/**
|
|
136
|
+
* 错误通知配置选项,用于覆盖默认的错误通知参数
|
|
137
|
+
*/
|
|
42
138
|
errorNotificationOptions?: NotificationOptions;
|
|
43
|
-
|
|
139
|
+
/**
|
|
140
|
+
* 提示消息配置选项,用于覆盖默认的提示消息参数
|
|
141
|
+
*/
|
|
142
|
+
tipsMessageOptions?: MessageOptions;
|
|
143
|
+
/**
|
|
144
|
+
* 是否使用自定义消息处理
|
|
145
|
+
* 当为 true 时,handleBusinessError、handleErrorArray、handleTips 都不会执行
|
|
146
|
+
* 默认值为 false
|
|
147
|
+
*/
|
|
44
148
|
isCustomMessage?: boolean;
|
|
45
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* 扩展 AxiosRequestConfig,支持自定义通知配置
|
|
152
|
+
*/
|
|
153
|
+
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
154
|
+
/**
|
|
155
|
+
* 消息相关配置选项,集中管理消息、通知和自定义处理配置
|
|
156
|
+
*/
|
|
157
|
+
messageConfigs?: MessageConfigs;
|
|
158
|
+
}
|
package/es/_types/emits.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemErrorDialog 组件的 Emits 类型定义
|
|
3
|
+
*/
|
|
1
4
|
export interface SystemErrorDialogEmitsType {
|
|
5
|
+
/** v-model 更新事件 */
|
|
2
6
|
'update:modelValue': [val: boolean];
|
|
7
|
+
/** 关闭事件 */
|
|
3
8
|
'close': [];
|
|
9
|
+
/** 确认事件 */
|
|
4
10
|
'confirm': [data: any];
|
|
11
|
+
/** 上报事件 */
|
|
5
12
|
'report': [];
|
|
6
13
|
}
|
package/es/_types/props.d.ts
CHANGED
|
@@ -1,15 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemErrorDialog 组件的 Props 类型定义
|
|
3
|
+
*/
|
|
1
4
|
export interface SystemErrorDialogPropsType {
|
|
5
|
+
/** 对话框标题 */
|
|
2
6
|
title?: string;
|
|
7
|
+
/** 对话框宽度 */
|
|
3
8
|
width?: number | string;
|
|
9
|
+
/** 用户名 */
|
|
4
10
|
userName?: string;
|
|
11
|
+
/** 用户ID */
|
|
5
12
|
userId?: string;
|
|
13
|
+
/** 科室名称 */
|
|
6
14
|
deptName?: string;
|
|
15
|
+
/** 科室ID */
|
|
7
16
|
deptId?: string;
|
|
17
|
+
/** 客户端IP地址 */
|
|
8
18
|
clientIp?: string;
|
|
9
|
-
|
|
10
|
-
menuName?: string;
|
|
19
|
+
/** 请求URL路径 */
|
|
11
20
|
requestUrl?: string;
|
|
21
|
+
/** 链路追踪ID */
|
|
12
22
|
traceId?: string;
|
|
23
|
+
/** 错误消息 */
|
|
13
24
|
errorMessage?: string;
|
|
25
|
+
/** 错误代码 */
|
|
14
26
|
errorCode?: number | string;
|
|
27
|
+
/** 本地服务是否启用 */
|
|
28
|
+
isStart?: boolean;
|
|
29
|
+
/** 菜单名称 */
|
|
30
|
+
menuName?: string;
|
|
15
31
|
}
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建通知实例的包装函数(用于 errors / tips 展示)
|
|
3
|
+
* @returns 通知实例,支持 success、error、warning、info 方法
|
|
4
|
+
*/
|
|
1
5
|
export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
|
|
2
6
|
_context: import('vue').AppContext | null;
|
|
3
7
|
}) | ((options: string | {
|
|
@@ -1,7 +1,28 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SystemErrorDialogPropsType } from '../_types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* 规范化请求参数对象
|
|
5
|
+
* @param payload 请求参数
|
|
6
|
+
* @returns 规范化后的对象
|
|
7
|
+
*/
|
|
3
8
|
export declare function normalizePayload(payload: any): Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* 解析响应头中的 TraceId
|
|
11
|
+
* @param headers 响应头
|
|
12
|
+
* @returns TraceId 字符串
|
|
13
|
+
*/
|
|
4
14
|
export declare function resolveTraceId(headers: AxiosResponse['headers'] | undefined): string;
|
|
15
|
+
/**
|
|
16
|
+
* 从 localStorage 中读取 userInfo
|
|
17
|
+
* @returns userInfo 对象,如果不存在则返回空对象
|
|
18
|
+
*/
|
|
5
19
|
export declare function getUserInfoFromLocalStorage(): Record<string, any>;
|
|
6
20
|
export declare function getCurrentMenuLocalStorage(): Record<string, any>;
|
|
21
|
+
/**
|
|
22
|
+
* 从 AxiosResponse 中提取系统错误信息
|
|
23
|
+
* @param response Axios 响应对象
|
|
24
|
+
* @param code 错误代码
|
|
25
|
+
* @param message 错误消息
|
|
26
|
+
* @returns 提取的错误信息
|
|
27
|
+
*/
|
|
7
28
|
export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
|
package/es/class.d.ts
CHANGED
|
@@ -1,52 +1,225 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
|
-
import { BaseApiConfig, ExtendedAxiosRequestConfig, NotificationOptions } from './_types/index.ts';
|
|
2
|
+
import { BaseApiConfig, ExtendedAxiosRequestConfig, MessageOptions, NotificationOptions } from './_types/index.ts';
|
|
3
3
|
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
4
|
+
/**
|
|
5
|
+
* BaseApi 类
|
|
6
|
+
* 继承 BaseHttpClient,提供增强的响应解析和错误处理功能
|
|
7
|
+
* 包括:响应字段映射、错误码处理、系统异常弹窗等
|
|
8
|
+
*/
|
|
4
9
|
export default class BaseApi extends BaseHttpClient {
|
|
5
10
|
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
6
11
|
protected enableSystemErrorDialog: boolean;
|
|
7
12
|
protected systemErrorMessage: string;
|
|
13
|
+
/**
|
|
14
|
+
* 检查是否在浏览器环境(在类初始化时判断)
|
|
15
|
+
* 注意:这是静态属性,所有实例共享
|
|
16
|
+
*/
|
|
8
17
|
private static readonly hasDocument;
|
|
18
|
+
/**
|
|
19
|
+
* SystemErrorDialog 实例
|
|
20
|
+
* 注意:这是实例属性,每个实例有自己的对话框实例
|
|
21
|
+
* 在构造函数中初始化(如果启用系统错误弹窗)
|
|
22
|
+
*/
|
|
9
23
|
private systemErrorDialogInstance;
|
|
10
|
-
|
|
24
|
+
/**
|
|
25
|
+
* SystemErrorDialog 初始化 Promise
|
|
26
|
+
* 用于跟踪初始化状态,避免重复初始化
|
|
27
|
+
*/
|
|
28
|
+
private readonly systemErrorDialogInitPromise;
|
|
29
|
+
/**
|
|
30
|
+
* 系统错误信息存储,用于在点击 icon 时打开详细错误弹窗
|
|
31
|
+
* key: 错误ID,value: 错误信息对象
|
|
32
|
+
* 注意:这是静态属性,所有实例共享同一个错误信息存储
|
|
33
|
+
*/
|
|
11
34
|
private static systemErrorInfoMap;
|
|
35
|
+
/**
|
|
36
|
+
* 获取是否在浏览器环境(实例 getter)
|
|
37
|
+
* @returns 是否在浏览器环境
|
|
38
|
+
*/
|
|
12
39
|
protected get hasDocument(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 获取系统错误信息存储(实例 getter)
|
|
42
|
+
* @returns 系统错误信息存储 Map
|
|
43
|
+
*/
|
|
13
44
|
protected get systemErrorInfoMap(): Map<string, {
|
|
14
45
|
response: AxiosResponse;
|
|
15
46
|
responseData: AxiosResponse['data'];
|
|
16
47
|
code: number;
|
|
17
48
|
message: string;
|
|
18
49
|
}>;
|
|
50
|
+
/**
|
|
51
|
+
* 生成唯一错误ID(实例方法)
|
|
52
|
+
* @returns 唯一错误ID
|
|
53
|
+
*/
|
|
19
54
|
protected generateErrorId(): string;
|
|
55
|
+
/**
|
|
56
|
+
* 打开系统错误详细弹窗(实例方法)
|
|
57
|
+
* @param errorId - 错误ID
|
|
58
|
+
*/
|
|
20
59
|
private openSystemErrorDialog;
|
|
60
|
+
/**
|
|
61
|
+
* 创建 BaseApi 实例
|
|
62
|
+
* @param config - API 配置对象
|
|
63
|
+
*/
|
|
21
64
|
constructor(config: BaseApiConfig);
|
|
65
|
+
/**
|
|
66
|
+
* 初始化 SystemErrorDialog 实例
|
|
67
|
+
* 在构造函数中调用,提前加载对话框组件
|
|
68
|
+
* @returns Promise,初始化完成后 resolve
|
|
69
|
+
*/
|
|
22
70
|
private initSystemErrorDialog;
|
|
71
|
+
/**
|
|
72
|
+
* 处理成功响应
|
|
73
|
+
* 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
|
|
74
|
+
* 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
|
|
75
|
+
* 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
|
|
76
|
+
* @param response - Axios 响应对象
|
|
77
|
+
* @returns 解析后的响应数据
|
|
78
|
+
*/
|
|
23
79
|
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
80
|
+
/**
|
|
81
|
+
* 支持路径解析的辅助函数
|
|
82
|
+
* @param obj - 要解析的对象
|
|
83
|
+
* @param path - 路径字符串,支持点号分隔的嵌套路径,如 'data.errors'
|
|
84
|
+
* @returns 解析后的值,如果路径不存在则返回 undefined
|
|
85
|
+
*/
|
|
24
86
|
protected getValueByPath(obj: any, path: string | undefined): any;
|
|
87
|
+
/**
|
|
88
|
+
* 解析响应字段,支持嵌套路径解析
|
|
89
|
+
* 子类可重写此方法来自定义字段解析逻辑
|
|
90
|
+
* @param data - 响应数据对象
|
|
91
|
+
* @returns 解析后的字段值对象
|
|
92
|
+
*/
|
|
25
93
|
protected parseResponseFields(data: any): {
|
|
26
94
|
code: any;
|
|
27
95
|
message: any;
|
|
28
96
|
responseData: any;
|
|
29
97
|
};
|
|
98
|
+
/**
|
|
99
|
+
* 处理系统异常错误(-1 - 系统异常)
|
|
100
|
+
* 子类可重写此方法来自定义系统异常处理逻辑
|
|
101
|
+
* @param response - Axios 响应对象
|
|
102
|
+
* @param code - 响应状态码
|
|
103
|
+
* @param message - 错误消息
|
|
104
|
+
* @param responseData - 响应数据
|
|
105
|
+
*/
|
|
30
106
|
protected handleSystemError(response: AxiosResponse, code: any, message: any, responseData: any): void;
|
|
107
|
+
/**
|
|
108
|
+
* 显示系统错误消息(带可点击 icon)
|
|
109
|
+
* 使用 vNode 渲染,点击 icon 后打开详细错误弹窗
|
|
110
|
+
* @param response - Axios 响应对象
|
|
111
|
+
* @param responseData - 响应数据
|
|
112
|
+
* @param code - 错误状态码
|
|
113
|
+
* @param message - 错误消息
|
|
114
|
+
*/
|
|
31
115
|
private showSystemErrorMessage;
|
|
116
|
+
/**
|
|
117
|
+
* 处理业务错误(其他非200错误码)
|
|
118
|
+
* 子类可重写此方法来自定义业务错误处理逻辑
|
|
119
|
+
* @param code - 响应状态码
|
|
120
|
+
* @param message - 错误消息
|
|
121
|
+
*/
|
|
32
122
|
protected handleBusinessError(code: any, message: any): void;
|
|
123
|
+
/**
|
|
124
|
+
* 处理错误数组 errors(如果有配置)
|
|
125
|
+
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
126
|
+
* @param httpData - HTTP 响应数据
|
|
127
|
+
* @param response - Axios 响应对象
|
|
128
|
+
*/
|
|
33
129
|
protected handleErrorArray(httpData: any, response: AxiosResponse): void;
|
|
34
|
-
|
|
35
|
-
|
|
130
|
+
/**
|
|
131
|
+
* 显示错误信息(默认实现)
|
|
132
|
+
* 使用 notification 显示错误信息
|
|
133
|
+
* 子类可重写此方法来自定义错误信息显示方式
|
|
134
|
+
* @param errors - 错误数组
|
|
135
|
+
* @param notificationOptions - 通知配置选项
|
|
136
|
+
*/
|
|
137
|
+
protected showErrors(errors: Array<{
|
|
36
138
|
code: string;
|
|
37
139
|
message: string;
|
|
38
140
|
}>, notificationOptions?: NotificationOptions): void;
|
|
141
|
+
/**
|
|
142
|
+
* 处理提示信息 tips(如果有配置)
|
|
143
|
+
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
144
|
+
* @param httpData - HTTP 响应数据
|
|
145
|
+
* @param response - Axios 响应对象
|
|
146
|
+
*/
|
|
39
147
|
protected handleTips(httpData: any, response: AxiosResponse): void;
|
|
40
|
-
|
|
148
|
+
/**
|
|
149
|
+
* 显示提示信息(默认实现)
|
|
150
|
+
* 根据 messageOptions.type 指定消息类型显示,提取所有 message 并连接
|
|
151
|
+
* 子类可重写此方法来自定义提示信息显示方式
|
|
152
|
+
* @param tips - 提示信息数组
|
|
153
|
+
* @param messageOptions - 消息配置选项
|
|
154
|
+
*/
|
|
155
|
+
protected showTips(tips: Array<{
|
|
41
156
|
code: string;
|
|
42
157
|
message: string;
|
|
43
|
-
}>,
|
|
158
|
+
}>, messageOptions?: MessageOptions): void;
|
|
159
|
+
/**
|
|
160
|
+
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
161
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
162
|
+
* @param config - Axios 请求配置对象
|
|
163
|
+
* @returns 解析后的响应数据
|
|
164
|
+
*/
|
|
44
165
|
protected request<R>(config: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
166
|
+
/**
|
|
167
|
+
* 发送 GET 请求
|
|
168
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
169
|
+
* @param url - 请求 URL 路径
|
|
170
|
+
* @param params - 查询参数对象
|
|
171
|
+
* @param config - 额外的请求配置
|
|
172
|
+
* @returns 解析后的响应数据
|
|
173
|
+
*/
|
|
45
174
|
get<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
175
|
+
/**
|
|
176
|
+
* 发送 POST 请求
|
|
177
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
178
|
+
* @param url - 请求 URL 路径
|
|
179
|
+
* @param data - 请求体数据
|
|
180
|
+
* @param config - 额外的请求配置
|
|
181
|
+
* @returns 解析后的响应数据
|
|
182
|
+
*/
|
|
46
183
|
post<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
184
|
+
/**
|
|
185
|
+
* 发送 DELETE 请求
|
|
186
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
187
|
+
* @param url - 请求 URL 路径
|
|
188
|
+
* @param params - 查询参数对象
|
|
189
|
+
* @param config - 额外的请求配置
|
|
190
|
+
* @returns 解析后的响应数据
|
|
191
|
+
*/
|
|
47
192
|
delete<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
193
|
+
/**
|
|
194
|
+
* 发送 PUT 请求
|
|
195
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
196
|
+
* @param url - 请求 URL 路径
|
|
197
|
+
* @param data - 请求体数据
|
|
198
|
+
* @param config - 额外的请求配置
|
|
199
|
+
* @returns 解析后的响应数据
|
|
200
|
+
*/
|
|
48
201
|
put<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
202
|
+
/**
|
|
203
|
+
* 批量请求,并发发送多个请求
|
|
204
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
205
|
+
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
206
|
+
* @returns 所有请求的响应数据数组
|
|
207
|
+
*/
|
|
49
208
|
all<R>(requests: Array<ExtendedAxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
209
|
+
/**
|
|
210
|
+
* 文件上传,将文件包装为 FormData 发送
|
|
211
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
212
|
+
* @param url - 上传地址
|
|
213
|
+
* @param file - 文件对象
|
|
214
|
+
* @param config - 额外的请求配置
|
|
215
|
+
* @returns 解析后的响应数据
|
|
216
|
+
*/
|
|
50
217
|
uploadFile<R>(url: string, file: File | Blob, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
218
|
+
/**
|
|
219
|
+
* 下载文件,将 Blob 对象下载到本地
|
|
220
|
+
* 显式声明以确保类型一致性,子类可重写此方法
|
|
221
|
+
* @param blob - Blob 对象
|
|
222
|
+
* @param filename - 文件名,如果不提供则使用时间戳
|
|
223
|
+
*/
|
|
51
224
|
downloadFile(blob: Blob, filename?: string): void;
|
|
52
225
|
}
|