@moluoxixi/ajax-package 0.0.15 → 0.0.17-beta.1
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/_types/api.d.ts +53 -0
- package/es/class.d.ts +26 -15
- package/es/index.mjs +85 -55
- package/es/test/service.d.ts +40 -0
- package/package.json +1 -1
- package/es/test/utils/BaseRequestApi.d.ts +0 -9
- package/es/test/utils/DownloadApi.d.ts +0 -21
- package/es/test/utils/RoleApi.d.ts +0 -4
- package/es/test/utils/UserApi.d.ts +0 -4
- package/es/test/utils/index.d.ts +0 -9
package/es/_types/api.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
1
2
|
import { App } from 'vue';
|
|
2
3
|
import { MessageInstance } from '../_utils/index.ts';
|
|
3
4
|
import { default as BaseApi } from '../class.ts';
|
|
@@ -63,3 +64,55 @@ export interface vueAxiosPluginType {
|
|
|
63
64
|
*/
|
|
64
65
|
install: (app: App, options?: vueAxiosPluginOptionsType) => void;
|
|
65
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* 通知配置选项
|
|
69
|
+
*/
|
|
70
|
+
export interface NotificationOptions {
|
|
71
|
+
/**
|
|
72
|
+
* 通知标题
|
|
73
|
+
*/
|
|
74
|
+
title?: string;
|
|
75
|
+
/**
|
|
76
|
+
* 通知类型
|
|
77
|
+
*/
|
|
78
|
+
type?: 'success' | 'error' | 'warning' | 'info';
|
|
79
|
+
/**
|
|
80
|
+
* 通知持续时间(毫秒)
|
|
81
|
+
*/
|
|
82
|
+
duration?: number;
|
|
83
|
+
/**
|
|
84
|
+
* 是否显示关闭按钮
|
|
85
|
+
*/
|
|
86
|
+
showClose?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* 自定义类名
|
|
89
|
+
*/
|
|
90
|
+
customClass?: string;
|
|
91
|
+
/**
|
|
92
|
+
* 自定义样式
|
|
93
|
+
*/
|
|
94
|
+
customStyle?: string | Record<string, any>;
|
|
95
|
+
/**
|
|
96
|
+
* 其他通知选项
|
|
97
|
+
*/
|
|
98
|
+
[key: string]: any;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 扩展 AxiosRequestConfig,支持自定义通知配置
|
|
102
|
+
*/
|
|
103
|
+
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
104
|
+
/**
|
|
105
|
+
* 错误通知配置选项,用于覆盖默认的错误通知参数
|
|
106
|
+
*/
|
|
107
|
+
errorNotificationOptions?: NotificationOptions;
|
|
108
|
+
/**
|
|
109
|
+
* 提示通知配置选项,用于覆盖默认的提示通知参数
|
|
110
|
+
*/
|
|
111
|
+
tipsNotificationOptions?: NotificationOptions;
|
|
112
|
+
/**
|
|
113
|
+
* 是否使用自定义消息处理
|
|
114
|
+
* 当为 true 时,handleBusinessError、handleErrorArray、handleTips 都不会执行
|
|
115
|
+
* 默认值为 false
|
|
116
|
+
*/
|
|
117
|
+
isCustomMessage?: boolean;
|
|
118
|
+
}
|
package/es/class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AxiosError,
|
|
2
|
-
import { BaseApiConfig } from './_types/index.ts';
|
|
1
|
+
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { BaseApiConfig, ExtendedAxiosRequestConfig, NotificationOptions } from './_types/index.ts';
|
|
3
3
|
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
4
4
|
/**
|
|
5
5
|
* BaseApi 类
|
|
@@ -69,6 +69,13 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
69
69
|
* @returns 解析后的响应数据
|
|
70
70
|
*/
|
|
71
71
|
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
72
|
+
/**
|
|
73
|
+
* 支持路径解析的辅助函数
|
|
74
|
+
* @param obj
|
|
75
|
+
* @param path
|
|
76
|
+
* @protected
|
|
77
|
+
*/
|
|
78
|
+
protected getValueByPath(obj: any, path: string | undefined): any;
|
|
72
79
|
/**
|
|
73
80
|
* 解析响应字段,支持嵌套路径解析
|
|
74
81
|
* 子类可重写此方法来自定义字段解析逻辑
|
|
@@ -99,33 +106,37 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
99
106
|
/**
|
|
100
107
|
* 处理错误数组 errors(如果有配置)
|
|
101
108
|
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
102
|
-
* @param
|
|
109
|
+
* @param httpData
|
|
110
|
+
* @param response
|
|
103
111
|
*/
|
|
104
|
-
protected handleErrorArray(
|
|
112
|
+
protected handleErrorArray(httpData: any, response: AxiosResponse): void;
|
|
105
113
|
/**
|
|
106
114
|
* 显示错误数组通知
|
|
107
115
|
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
108
116
|
* @param errors - 错误数组
|
|
117
|
+
* @param notificationOptions
|
|
109
118
|
*/
|
|
110
119
|
protected showErrorArrayNotification(errors: Array<{
|
|
111
120
|
code: string;
|
|
112
121
|
message: string;
|
|
113
|
-
}
|
|
122
|
+
}>, notificationOptions?: NotificationOptions): void;
|
|
114
123
|
/**
|
|
115
124
|
* 处理提示信息 tips(如果有配置)
|
|
116
125
|
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
117
|
-
* @param
|
|
126
|
+
* @param httpData
|
|
127
|
+
* @param response
|
|
118
128
|
*/
|
|
119
|
-
protected handleTips(
|
|
129
|
+
protected handleTips(httpData: any, response: AxiosResponse): void;
|
|
120
130
|
/**
|
|
121
131
|
* 显示提示信息通知
|
|
122
132
|
* 子类可重写此方法来自定义提示信息通知显示方式
|
|
123
133
|
* @param tips - 提示信息数组
|
|
134
|
+
* @param notificationOptions
|
|
124
135
|
*/
|
|
125
136
|
protected showTipsNotification(tips: Array<{
|
|
126
137
|
code: string;
|
|
127
138
|
message: string;
|
|
128
|
-
}
|
|
139
|
+
}>, notificationOptions?: NotificationOptions): void;
|
|
129
140
|
/**
|
|
130
141
|
* 显示系统异常对话框,当响应状态码为 -1 时调用
|
|
131
142
|
* @param response - Axios 响应对象
|
|
@@ -145,7 +156,7 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
145
156
|
* @param config - Axios 请求配置对象
|
|
146
157
|
* @returns 解析后的响应数据
|
|
147
158
|
*/
|
|
148
|
-
protected request<R>(config:
|
|
159
|
+
protected request<R>(config: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
149
160
|
/**
|
|
150
161
|
* 发送 GET 请求
|
|
151
162
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
@@ -154,7 +165,7 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
154
165
|
* @param config - 额外的请求配置
|
|
155
166
|
* @returns 解析后的响应数据
|
|
156
167
|
*/
|
|
157
|
-
get<R>(url: string, params?: Record<string, any>, config?:
|
|
168
|
+
get<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
158
169
|
/**
|
|
159
170
|
* 发送 POST 请求
|
|
160
171
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
@@ -163,7 +174,7 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
163
174
|
* @param config - 额外的请求配置
|
|
164
175
|
* @returns 解析后的响应数据
|
|
165
176
|
*/
|
|
166
|
-
post<R>(url: string, data?: Record<string, any>, config?:
|
|
177
|
+
post<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
167
178
|
/**
|
|
168
179
|
* 发送 DELETE 请求
|
|
169
180
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
@@ -172,7 +183,7 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
172
183
|
* @param config - 额外的请求配置
|
|
173
184
|
* @returns 解析后的响应数据
|
|
174
185
|
*/
|
|
175
|
-
delete<R>(url: string, params?: Record<string, any>, config?:
|
|
186
|
+
delete<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
176
187
|
/**
|
|
177
188
|
* 发送 PUT 请求
|
|
178
189
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
@@ -181,14 +192,14 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
181
192
|
* @param config - 额外的请求配置
|
|
182
193
|
* @returns 解析后的响应数据
|
|
183
194
|
*/
|
|
184
|
-
put<R>(url: string, data?: Record<string, any>, config?:
|
|
195
|
+
put<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
185
196
|
/**
|
|
186
197
|
* 批量请求,并发发送多个请求
|
|
187
198
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
188
199
|
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
189
200
|
* @returns 所有请求的响应数据数组
|
|
190
201
|
*/
|
|
191
|
-
all<R>(requests: Array<
|
|
202
|
+
all<R>(requests: Array<ExtendedAxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
192
203
|
/**
|
|
193
204
|
* 文件上传,将文件包装为 FormData 发送
|
|
194
205
|
* 显式声明以确保类型一致性,子类可重写此方法
|
|
@@ -197,7 +208,7 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
197
208
|
* @param config - 额外的请求配置
|
|
198
209
|
* @returns 解析后的响应数据
|
|
199
210
|
*/
|
|
200
|
-
uploadFile<R>(url: string, file: File | Blob, config?:
|
|
211
|
+
uploadFile<R>(url: string, file: File | Blob, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
201
212
|
/**
|
|
202
213
|
* 下载文件,将 Blob 对象下载到本地
|
|
203
214
|
* 显式声明以确保类型一致性,子类可重写此方法
|
package/es/index.mjs
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
try {
|
|
4
4
|
if (typeof document !== "undefined") {
|
|
5
|
-
if (!document.getElementById("
|
|
5
|
+
if (!document.getElementById("fff2b744-05a5-42b2-a548-d0942177ace6")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "fff2b744-05a5-42b2-a548-d0942177ace6";
|
|
8
8
|
elementStyle.appendChild(document.createTextNode("._root_11p33_1 .el-dialog__header {\n padding: 0 12px 12px;\n}\n\n._root_11p33_1 .el-dialog__body {\n border-top: 1px solid #e5e7eb;\n border-bottom: 1px solid #e5e7eb;\n padding: 0 12px;\n}\n\n._root_11p33_1 .el-dialog__footer {\n padding: 0 12px;\n}"));
|
|
9
9
|
document.head.appendChild(elementStyle);
|
|
10
10
|
}
|
|
@@ -12613,8 +12613,8 @@ class BaseApi extends BaseHttpClient {
|
|
|
12613
12613
|
code: "Code",
|
|
12614
12614
|
message: "Message",
|
|
12615
12615
|
data: "data",
|
|
12616
|
-
errors: "errors",
|
|
12617
|
-
tips: "tips",
|
|
12616
|
+
errors: "data.errors",
|
|
12617
|
+
tips: "data.tips",
|
|
12618
12618
|
...responseFields
|
|
12619
12619
|
};
|
|
12620
12620
|
this.enableSystemErrorDialog = enableSystemErrorDialog;
|
|
@@ -12691,12 +12691,36 @@ class BaseApi extends BaseHttpClient {
|
|
|
12691
12691
|
const httpData = super.handleSuccessResponse(response);
|
|
12692
12692
|
const parsedFields = this.parseResponseFields(httpData);
|
|
12693
12693
|
const { code, message: message2, responseData } = parsedFields;
|
|
12694
|
+
const config = response.config;
|
|
12695
|
+
const isCustomMessage = (config == null ? void 0 : config.isCustomMessage) ?? false;
|
|
12694
12696
|
this.handleSystemError(response, code, message2, responseData);
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12697
|
+
if (!isCustomMessage) {
|
|
12698
|
+
this.handleBusinessError(code, message2, response);
|
|
12699
|
+
this.handleErrorArray(httpData, response);
|
|
12700
|
+
this.handleTips(httpData, response);
|
|
12701
|
+
}
|
|
12698
12702
|
return responseData;
|
|
12699
12703
|
}
|
|
12704
|
+
/**
|
|
12705
|
+
* 支持路径解析的辅助函数
|
|
12706
|
+
* @param obj
|
|
12707
|
+
* @param path
|
|
12708
|
+
* @protected
|
|
12709
|
+
*/
|
|
12710
|
+
getValueByPath(obj, path) {
|
|
12711
|
+
if (!path)
|
|
12712
|
+
return obj;
|
|
12713
|
+
const keys = path.split(".");
|
|
12714
|
+
let result = obj;
|
|
12715
|
+
for (const key of keys) {
|
|
12716
|
+
if (result && typeof result === "object" && key in result) {
|
|
12717
|
+
result = result[key];
|
|
12718
|
+
} else {
|
|
12719
|
+
return void 0;
|
|
12720
|
+
}
|
|
12721
|
+
}
|
|
12722
|
+
return result;
|
|
12723
|
+
}
|
|
12700
12724
|
/**
|
|
12701
12725
|
* 解析响应字段,支持嵌套路径解析
|
|
12702
12726
|
* 子类可重写此方法来自定义字段解析逻辑
|
|
@@ -12705,23 +12729,9 @@ class BaseApi extends BaseHttpClient {
|
|
|
12705
12729
|
*/
|
|
12706
12730
|
parseResponseFields(data) {
|
|
12707
12731
|
var _a2, _b, _c;
|
|
12708
|
-
const
|
|
12709
|
-
|
|
12710
|
-
|
|
12711
|
-
const keys = path.split(".");
|
|
12712
|
-
let result = obj;
|
|
12713
|
-
for (const key of keys) {
|
|
12714
|
-
if (result && typeof result === "object" && key in result) {
|
|
12715
|
-
result = result[key];
|
|
12716
|
-
} else {
|
|
12717
|
-
return void 0;
|
|
12718
|
-
}
|
|
12719
|
-
}
|
|
12720
|
-
return result;
|
|
12721
|
-
};
|
|
12722
|
-
const code = getValueByPath(data, (_a2 = this.responseFields) == null ? void 0 : _a2.code);
|
|
12723
|
-
const message2 = getValueByPath(data, (_b = this.responseFields) == null ? void 0 : _b.message);
|
|
12724
|
-
const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12732
|
+
const code = this.getValueByPath(data, (_a2 = this.responseFields) == null ? void 0 : _a2.code);
|
|
12733
|
+
const message2 = this.getValueByPath(data, (_b = this.responseFields) == null ? void 0 : _b.message);
|
|
12734
|
+
const responseData = this.getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12725
12735
|
return { code, message: message2, responseData };
|
|
12726
12736
|
}
|
|
12727
12737
|
/**
|
|
@@ -12761,15 +12771,18 @@ class BaseApi extends BaseHttpClient {
|
|
|
12761
12771
|
/**
|
|
12762
12772
|
* 处理错误数组 errors(如果有配置)
|
|
12763
12773
|
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
12764
|
-
* @param
|
|
12774
|
+
* @param httpData
|
|
12775
|
+
* @param response
|
|
12765
12776
|
*/
|
|
12766
|
-
handleErrorArray(
|
|
12777
|
+
handleErrorArray(httpData, response) {
|
|
12767
12778
|
var _a2;
|
|
12768
12779
|
const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
|
|
12769
12780
|
if (errorsField) {
|
|
12770
|
-
const errors =
|
|
12781
|
+
const errors = this.getValueByPath(httpData, errorsField);
|
|
12771
12782
|
if (Array.isArray(errors) && errors.length) {
|
|
12772
|
-
|
|
12783
|
+
const config = response.config;
|
|
12784
|
+
const notificationOptions = config == null ? void 0 : config.errorNotificationOptions;
|
|
12785
|
+
this.showErrorArrayNotification(errors, notificationOptions);
|
|
12773
12786
|
throw new Error("请求错误");
|
|
12774
12787
|
}
|
|
12775
12788
|
}
|
|
@@ -12778,37 +12791,47 @@ class BaseApi extends BaseHttpClient {
|
|
|
12778
12791
|
* 显示错误数组通知
|
|
12779
12792
|
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
12780
12793
|
* @param errors - 错误数组
|
|
12794
|
+
* @param notificationOptions
|
|
12781
12795
|
*/
|
|
12782
|
-
showErrorArrayNotification(errors) {
|
|
12796
|
+
showErrorArrayNotification(errors, notificationOptions) {
|
|
12783
12797
|
var _a2, _b;
|
|
12784
12798
|
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12799
|
+
const defaultOptions = {
|
|
12800
|
+
title: "提示",
|
|
12801
|
+
type: "error"
|
|
12802
|
+
};
|
|
12785
12803
|
if (hasDocument) {
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
}
|
|
12804
|
+
const finalOptions = {
|
|
12805
|
+
...defaultOptions,
|
|
12806
|
+
...notificationOptions,
|
|
12807
|
+
message: html
|
|
12808
|
+
};
|
|
12809
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12791
12810
|
} else {
|
|
12792
12811
|
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
}
|
|
12812
|
+
const finalOptions = {
|
|
12813
|
+
...defaultOptions,
|
|
12814
|
+
...notificationOptions,
|
|
12815
|
+
message: errorMessages
|
|
12816
|
+
};
|
|
12817
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12798
12818
|
}
|
|
12799
12819
|
}
|
|
12800
12820
|
/**
|
|
12801
12821
|
* 处理提示信息 tips(如果有配置)
|
|
12802
12822
|
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
12803
|
-
* @param
|
|
12823
|
+
* @param httpData
|
|
12824
|
+
* @param response
|
|
12804
12825
|
*/
|
|
12805
|
-
handleTips(
|
|
12826
|
+
handleTips(httpData, response) {
|
|
12806
12827
|
var _a2;
|
|
12807
12828
|
const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
|
|
12808
12829
|
if (tipsField) {
|
|
12809
|
-
const tips =
|
|
12830
|
+
const tips = this.getValueByPath(httpData, tipsField);
|
|
12810
12831
|
if (Array.isArray(tips) && tips.length) {
|
|
12811
|
-
|
|
12832
|
+
const config = response.config;
|
|
12833
|
+
const notificationOptions = config == null ? void 0 : config.tipsNotificationOptions;
|
|
12834
|
+
this.showTipsNotification(tips, notificationOptions);
|
|
12812
12835
|
}
|
|
12813
12836
|
}
|
|
12814
12837
|
}
|
|
@@ -12816,23 +12839,30 @@ class BaseApi extends BaseHttpClient {
|
|
|
12816
12839
|
* 显示提示信息通知
|
|
12817
12840
|
* 子类可重写此方法来自定义提示信息通知显示方式
|
|
12818
12841
|
* @param tips - 提示信息数组
|
|
12842
|
+
* @param notificationOptions
|
|
12819
12843
|
*/
|
|
12820
|
-
showTipsNotification(tips) {
|
|
12844
|
+
showTipsNotification(tips, notificationOptions) {
|
|
12821
12845
|
var _a2, _b;
|
|
12822
12846
|
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12847
|
+
const defaultOptions = {
|
|
12848
|
+
title: "提示",
|
|
12849
|
+
type: "warning"
|
|
12850
|
+
};
|
|
12823
12851
|
if (hasDocument) {
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
}
|
|
12852
|
+
const finalOptions = {
|
|
12853
|
+
...defaultOptions,
|
|
12854
|
+
...notificationOptions,
|
|
12855
|
+
message: html
|
|
12856
|
+
};
|
|
12857
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12829
12858
|
} else {
|
|
12830
12859
|
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
}
|
|
12860
|
+
const finalOptions = {
|
|
12861
|
+
...defaultOptions,
|
|
12862
|
+
...notificationOptions,
|
|
12863
|
+
message: tipMessages
|
|
12864
|
+
};
|
|
12865
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12836
12866
|
}
|
|
12837
12867
|
}
|
|
12838
12868
|
/**
|
|
@@ -13255,7 +13285,7 @@ const SystemErrorDialog = defineComponent({
|
|
|
13255
13285
|
// 黑色错误信息区域
|
|
13256
13286
|
h("div", { style: { backgroundColor: "#2c3e50", color: "#fff", padding: "16px 20px", fontFamily: 'Monaco, Consolas, "Courier New", monospace', fontSize: "12px", lineHeight: 1.5, maxHeight: "200px", overflowY: "auto" } }, [
|
|
13257
13287
|
h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
|
|
13258
|
-
h("div", { style: { color: "#e74c3c", fontWeight: "bold" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
|
|
13288
|
+
h("div", { style: { color: "#e74c3c", fontWeight: "bold", whiteSpace: "pre-wrap" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
|
|
13259
13289
|
])
|
|
13260
13290
|
]),
|
|
13261
13291
|
footer: () => h("div", { style: { display: "flex", justifyContent: "flex-end", alignItems: "center", paddingTop: "16px" } }, [
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export default service;
|
|
2
|
+
/**
|
|
3
|
+
* 创建 axios 实例
|
|
4
|
+
* @type {NewApi}
|
|
5
|
+
*/
|
|
6
|
+
declare const service: NewApi;
|
|
7
|
+
/**
|
|
8
|
+
* 自定义 API 类,继承自 BaseApi
|
|
9
|
+
* 实现了原有的 axios 封装功能
|
|
10
|
+
*/
|
|
11
|
+
export class NewApi {
|
|
12
|
+
constructor(config?: {});
|
|
13
|
+
/**
|
|
14
|
+
* 处理请求配置
|
|
15
|
+
* 在请求发送之前进行一些处理
|
|
16
|
+
* 对应旧代码的请求拦截器逻辑
|
|
17
|
+
*/
|
|
18
|
+
processRequestConfig(config: any): any;
|
|
19
|
+
/**
|
|
20
|
+
* 处理 HTTP 状态码
|
|
21
|
+
*/
|
|
22
|
+
handleHttpStatus(response: any): void;
|
|
23
|
+
/**
|
|
24
|
+
* 处理业务错误(重写父类方法,不抛出错误,只显示消息)
|
|
25
|
+
*/
|
|
26
|
+
handleBusinessError(code: any, message: any): void;
|
|
27
|
+
/**
|
|
28
|
+
* 处理成功响应(完全重写,符合旧代码逻辑)
|
|
29
|
+
*/
|
|
30
|
+
handleSuccessResponse(response: any): any;
|
|
31
|
+
/**
|
|
32
|
+
* 处理超时错误(重写父类方法)
|
|
33
|
+
*/
|
|
34
|
+
handleTimeoutError(error: any): void;
|
|
35
|
+
/**
|
|
36
|
+
* 处理网络错误(重写父类方法)
|
|
37
|
+
*/
|
|
38
|
+
handleNetworkError(error: any): void;
|
|
39
|
+
}
|
|
40
|
+
export function showErrorNotification(title: any, errors: any): void;
|
package/package.json
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
|
|
3
|
-
export default class BaseRequestApi extends BaseApi {
|
|
4
|
-
constructor(config?: Partial<BaseApiConfig>);
|
|
5
|
-
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
6
|
-
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
7
|
-
protected handleHttpStatus(response: AxiosResponse): void;
|
|
8
|
-
protected handleBusinessError(code: any, message: any): void;
|
|
9
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
-
import { default as BaseRequestApi } from './BaseRequestApi.ts';
|
|
3
|
-
export default class DownloadApi extends BaseRequestApi {
|
|
4
|
-
private downloadingFiles;
|
|
5
|
-
constructor();
|
|
6
|
-
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
7
|
-
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
8
|
-
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
9
|
-
downloadFileFromUrl(url: string, filename?: string, params?: Record<string, any>, data?: Record<string, any>, method?: 'get' | 'post', config?: AxiosRequestConfig): Promise<boolean>;
|
|
10
|
-
private getFilenameFromUrl;
|
|
11
|
-
downloadMultipleFiles(files: Array<{
|
|
12
|
-
url: string;
|
|
13
|
-
filename?: string;
|
|
14
|
-
params?: Record<string, any>;
|
|
15
|
-
data?: Record<string, any>;
|
|
16
|
-
method?: 'get' | 'post';
|
|
17
|
-
}>, onProgress?: (progress: number, currentFile: string) => void): Promise<{
|
|
18
|
-
success: number;
|
|
19
|
-
total: number;
|
|
20
|
-
}>;
|
|
21
|
-
}
|
package/es/test/utils/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { default as DownloadApi } from './DownloadApi.ts';
|
|
2
|
-
import { default as BaseRequestApi } from './BaseRequestApi.ts';
|
|
3
|
-
import { default as UserApi } from './UserApi.ts';
|
|
4
|
-
import { default as RoleApi } from './RoleApi.ts';
|
|
5
|
-
export declare const downloadRequest: DownloadApi;
|
|
6
|
-
export declare const userRequest: any;
|
|
7
|
-
export declare const baseRequest: any;
|
|
8
|
-
export declare const roleRequest: any;
|
|
9
|
-
export { DownloadApi, BaseRequestApi, UserApi, RoleApi, };
|