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