@moluoxixi/ajax-package 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/es/BaseHttpClient.d.ts +6 -127
- package/es/SystemErrorDialog.d.ts +0 -4
- package/es/_types/emits.d.ts +0 -7
- package/es/_utils/messageWrapper.d.ts +0 -6
- package/es/_utils/notificationWrapper.d.ts +0 -6
- package/es/_utils/systemErrorInfo.d.ts +0 -21
- package/es/class.d.ts +10 -0
- package/es/index.mjs +107 -4961
- package/es/netseriver.d.ts +0 -14
- package/package.json +2 -2
- package/README.md +0 -1016
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;
|
|
@@ -25,25 +16,15 @@ export default class BaseHttpClient {
|
|
|
25
16
|
protected messageInstance: MessageInstance;
|
|
26
17
|
protected notificationInstance: NotificationInstance;
|
|
27
18
|
protected addSign?: (config: AxiosRequestConfig) => void;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
19
|
+
protected recentErrorCache: {
|
|
20
|
+
message: string;
|
|
21
|
+
timestamp: number;
|
|
22
|
+
} | null;
|
|
23
|
+
protected errorDebounceTime: number;
|
|
24
|
+
protected errorCacheTimer: NodeJS.Timeout | null;
|
|
32
25
|
protected static readonly hasDocument: boolean;
|
|
33
|
-
/**
|
|
34
|
-
* 获取是否在浏览器环境(实例 getter)
|
|
35
|
-
* @returns 是否在浏览器环境
|
|
36
|
-
*/
|
|
37
26
|
protected get hasDocument(): boolean;
|
|
38
|
-
/**
|
|
39
|
-
* 解析 appendTo 配置,返回目标 HTMLElement
|
|
40
|
-
* @returns 目标元素,如果找不到且配置为 null 则返回 null,'body' 时返回 document.body,其他字符串作为选择器查找
|
|
41
|
-
*/
|
|
42
27
|
protected resolveAppendToTarget(): HTMLElement | null;
|
|
43
|
-
/**
|
|
44
|
-
* 获取或创建 ajaxPackage-container 容器元素
|
|
45
|
-
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
46
|
-
*/
|
|
47
28
|
protected getContainer(): HTMLElement | null;
|
|
48
29
|
/**
|
|
49
30
|
* 获取或创建 popover 容器元素(用于 Dialog)
|
|
@@ -55,124 +36,22 @@ export default class BaseHttpClient {
|
|
|
55
36
|
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
56
37
|
*/
|
|
57
38
|
getMessageContainer(): HTMLElement | null;
|
|
58
|
-
/**
|
|
59
|
-
* 创建 BaseHttpClient 实例
|
|
60
|
-
* @param config - HTTP 客户端配置对象
|
|
61
|
-
*/
|
|
62
39
|
constructor(config: BaseHttpClientConfig);
|
|
63
|
-
/**
|
|
64
|
-
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
65
|
-
* @param config - 请求配置对象
|
|
66
|
-
* @returns 处理后的请求配置
|
|
67
|
-
*/
|
|
68
40
|
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
|
|
69
|
-
/**
|
|
70
|
-
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
71
|
-
* 按照标准 HTTP 结构处理响应
|
|
72
|
-
* @param response - Axios 响应对象
|
|
73
|
-
* @returns 解析后的响应数据
|
|
74
|
-
*/
|
|
75
41
|
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
76
|
-
/**
|
|
77
|
-
* 处理 HTTP 状态码
|
|
78
|
-
* 子类可重写此方法来自定义 HTTP 状态码处理逻辑
|
|
79
|
-
* @param response - Axios 响应对象
|
|
80
|
-
*/
|
|
81
42
|
protected handleHttpStatus(response: AxiosResponse): void;
|
|
82
|
-
/**
|
|
83
|
-
* 处理成功响应
|
|
84
|
-
* 子类可重写此方法来自定义成功响应的处理逻辑
|
|
85
|
-
* @param response - Axios 响应对象
|
|
86
|
-
* @returns 解析后的响应数据
|
|
87
|
-
*/
|
|
88
43
|
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
89
|
-
/**
|
|
90
|
-
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
91
|
-
* 按照标准 HTTP 错误结构处理错误
|
|
92
|
-
* @param error - Axios 错误对象
|
|
93
|
-
* @returns 处理后的错误对象
|
|
94
|
-
*/
|
|
95
44
|
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
96
|
-
/**
|
|
97
|
-
* 处理认证错误(401 - 未授权/登录失效)
|
|
98
|
-
* 子类可重写此方法来自定义认证错误处理逻辑
|
|
99
|
-
* @param error - Axios 错误对象
|
|
100
|
-
*/
|
|
101
45
|
protected handleAuthenticationError(error: AxiosError): void;
|
|
102
|
-
/**
|
|
103
|
-
* 处理超时错误
|
|
104
|
-
* 子类可重写此方法来自定义超时错误处理逻辑
|
|
105
|
-
* @param error - Axios 错误对象
|
|
106
|
-
*/
|
|
107
46
|
protected handleTimeoutError(error: AxiosError): void;
|
|
108
|
-
/**
|
|
109
|
-
* 处理网络错误(其他错误)
|
|
110
|
-
* 子类可重写此方法来自定义网络错误处理逻辑
|
|
111
|
-
* @param error - Axios 错误对象
|
|
112
|
-
*/
|
|
113
47
|
protected handleNetworkError(error: AxiosError): void;
|
|
114
|
-
/**
|
|
115
|
-
* 设置请求和响应拦截器
|
|
116
|
-
* 请求拦截器:自动添加 Token
|
|
117
|
-
* 响应拦截器:处理成功响应和错误响应(401、超时等)
|
|
118
|
-
*/
|
|
119
48
|
private setupInterceptors;
|
|
120
|
-
/**
|
|
121
|
-
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
122
|
-
* @param config - Axios 请求配置对象
|
|
123
|
-
* @returns 解析后的响应数据
|
|
124
|
-
*/
|
|
125
49
|
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
126
|
-
/**
|
|
127
|
-
* 发送 GET 请求
|
|
128
|
-
* @param url - 请求 URL 路径
|
|
129
|
-
* @param params - 查询参数对象
|
|
130
|
-
* @param config - 额外的请求配置
|
|
131
|
-
* @returns 解析后的响应数据
|
|
132
|
-
*/
|
|
133
50
|
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
134
|
-
/**
|
|
135
|
-
* 发送 POST 请求
|
|
136
|
-
* @param url - 请求 URL 路径
|
|
137
|
-
* @param data - 请求体数据
|
|
138
|
-
* @param config - 额外的请求配置
|
|
139
|
-
* @returns 解析后的响应数据
|
|
140
|
-
*/
|
|
141
51
|
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
142
|
-
/**
|
|
143
|
-
* 发送 DELETE 请求
|
|
144
|
-
* @param url - 请求 URL 路径
|
|
145
|
-
* @param params - 查询参数对象
|
|
146
|
-
* @param config - 额外的请求配置
|
|
147
|
-
* @returns 解析后的响应数据
|
|
148
|
-
*/
|
|
149
52
|
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
150
|
-
/**
|
|
151
|
-
* 发送 PUT 请求
|
|
152
|
-
* @param url - 请求 URL 路径
|
|
153
|
-
* @param data - 请求体数据
|
|
154
|
-
* @param config - 额外的请求配置
|
|
155
|
-
* @returns 解析后的响应数据
|
|
156
|
-
*/
|
|
157
53
|
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
158
|
-
/**
|
|
159
|
-
* 批量请求,并发发送多个请求
|
|
160
|
-
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
161
|
-
* @returns 所有请求的响应数据数组
|
|
162
|
-
*/
|
|
163
54
|
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
164
|
-
/**
|
|
165
|
-
* 文件上传,将文件包装为 FormData 发送
|
|
166
|
-
* @param url - 上传地址
|
|
167
|
-
* @param file - 文件对象
|
|
168
|
-
* @param config - 额外的请求配置
|
|
169
|
-
* @returns 解析后的响应数据
|
|
170
|
-
*/
|
|
171
55
|
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
172
|
-
/**
|
|
173
|
-
* 下载文件,将 Blob 对象下载到本地
|
|
174
|
-
* @param blob - Blob 对象
|
|
175
|
-
* @param filename - 文件名,如果不提供则使用时间戳
|
|
176
|
-
*/
|
|
177
56
|
downloadFile(blob: Blob, filename?: string): void;
|
|
178
57
|
}
|
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
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建消息实例的包装函数
|
|
3
|
-
* @param hasDocument - 是否在浏览器环境
|
|
4
|
-
* @param container - 容器元素或获取容器的函数,如果提供则消息将挂载到该容器中
|
|
5
|
-
* @returns 消息函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
|
|
6
|
-
*/
|
|
7
1
|
export declare function createMessageWrapper(hasDocument: boolean, container?: HTMLElement | null | (() => HTMLElement | null)): (options: string | {
|
|
8
2
|
message?: string;
|
|
9
3
|
type?: "success" | "error" | "warning" | "info";
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建通知实例的包装函数(用于 errors / tips 展示)
|
|
3
|
-
* @param hasDocument - 是否在浏览器环境
|
|
4
|
-
* @param container - 容器元素或获取容器的函数,如果提供则通知将挂载到该容器中
|
|
5
|
-
* @returns 通知函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
|
|
6
|
-
*/
|
|
7
1
|
export declare function createNotificationWrapper(hasDocument: boolean, container?: HTMLElement | null | (() => HTMLElement | null)): ((options: string | {
|
|
8
2
|
message?: string;
|
|
9
3
|
title?: string;
|
|
@@ -1,28 +1,7 @@
|
|
|
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
6
|
export declare function getCurrentMenuLocalStorage(): Record<string, any>;
|
|
21
|
-
/**
|
|
22
|
-
* 从 AxiosResponse 中提取系统错误信息
|
|
23
|
-
* @param response Axios 响应对象
|
|
24
|
-
* @param code 错误代码
|
|
25
|
-
* @param message 错误消息
|
|
26
|
-
* @returns 提取的错误信息
|
|
27
|
-
*/
|
|
28
7
|
export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
|
package/es/class.d.ts
CHANGED
|
@@ -10,6 +10,11 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
10
10
|
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
11
11
|
protected enableSystemErrorDialog: boolean;
|
|
12
12
|
protected systemErrorMessage: string;
|
|
13
|
+
/**
|
|
14
|
+
* 检查是否在浏览器环境(在类初始化时判断)
|
|
15
|
+
* 注意:这是静态属性,所有实例共享
|
|
16
|
+
*/
|
|
17
|
+
private static readonly hasDocument;
|
|
13
18
|
/**
|
|
14
19
|
* SystemErrorDialog 实例
|
|
15
20
|
* 注意:这是实例属性,每个实例有自己的对话框实例
|
|
@@ -27,6 +32,11 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
27
32
|
* 注意:这是静态属性,所有实例共享同一个错误信息存储
|
|
28
33
|
*/
|
|
29
34
|
private static systemErrorInfoMap;
|
|
35
|
+
/**
|
|
36
|
+
* 获取是否在浏览器环境(实例 getter)
|
|
37
|
+
* @returns 是否在浏览器环境
|
|
38
|
+
*/
|
|
39
|
+
protected get hasDocument(): boolean;
|
|
30
40
|
/**
|
|
31
41
|
* 获取系统错误信息存储(实例 getter)
|
|
32
42
|
* @returns 系统错误信息存储 Map
|