@moluoxixi/ajax-package 0.0.20 → 0.0.23
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 +0 -2
- package/es/class.d.ts +58 -70
- package/es/index.mjs +180 -222
- package/package.json +1 -1
package/es/_types/api.d.ts
CHANGED
package/es/class.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AxiosResponse } from 'axios';
|
|
1
|
+
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
2
|
import { BaseApiConfig, ExtendedAxiosRequestConfig, NotificationOptions } from './_types/index.ts';
|
|
3
3
|
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
4
4
|
/**
|
|
@@ -9,65 +9,57 @@ import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
|
9
9
|
export default class BaseApi extends BaseHttpClient {
|
|
10
10
|
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
11
11
|
protected enableSystemErrorDialog: boolean;
|
|
12
|
-
protected systemErrorMessage: string;
|
|
13
12
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
private static readonly hasDocument;
|
|
18
|
-
/**
|
|
19
|
-
* SystemErrorDialog 实例
|
|
20
|
-
* 注意:这是实例属性,每个实例有自己的对话框实例
|
|
21
|
-
* 在构造函数中初始化(如果启用系统错误弹窗)
|
|
22
|
-
*/
|
|
23
|
-
private systemErrorDialogInstance;
|
|
24
|
-
/**
|
|
25
|
-
* SystemErrorDialog 初始化 Promise
|
|
26
|
-
* 用于跟踪初始化状态,避免重复初始化
|
|
13
|
+
* 创建 BaseApi 实例
|
|
14
|
+
* @param config - API 配置对象
|
|
27
15
|
*/
|
|
28
|
-
|
|
16
|
+
constructor(config: BaseApiConfig);
|
|
29
17
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
18
|
+
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
19
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
20
|
+
* @param config - 请求配置对象
|
|
21
|
+
* @returns 处理后的请求配置
|
|
33
22
|
*/
|
|
34
|
-
|
|
23
|
+
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
35
24
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
25
|
+
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
26
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
27
|
+
* @param response - Axios 响应对象
|
|
28
|
+
* @returns 解析后的响应数据
|
|
38
29
|
*/
|
|
39
|
-
|
|
30
|
+
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
40
31
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
32
|
+
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
33
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
34
|
+
* @param error - Axios 错误对象
|
|
35
|
+
* @returns 处理后的错误对象
|
|
43
36
|
*/
|
|
44
|
-
|
|
45
|
-
response: AxiosResponse;
|
|
46
|
-
responseData: AxiosResponse['data'];
|
|
47
|
-
code: number;
|
|
48
|
-
message: string;
|
|
49
|
-
}>;
|
|
37
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
50
38
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
39
|
+
* 处理 HTTP 状态码
|
|
40
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
41
|
+
* @param response - Axios 响应对象
|
|
53
42
|
*/
|
|
54
|
-
protected
|
|
43
|
+
protected handleHttpStatus(response: AxiosResponse): void;
|
|
55
44
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
45
|
+
* 处理认证错误(401 - 未授权/登录失效)
|
|
46
|
+
* 重写父类方法,处理 HTTP 401 错误
|
|
47
|
+
* 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
|
|
48
|
+
* @param error - Axios 错误对象
|
|
58
49
|
*/
|
|
59
|
-
|
|
50
|
+
protected handleAuthenticationError(error: AxiosError): void;
|
|
60
51
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
52
|
+
* 处理超时错误
|
|
53
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
54
|
+
* @param error - Axios 错误对象
|
|
63
55
|
*/
|
|
64
|
-
|
|
56
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
65
57
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
* @
|
|
58
|
+
* 处理网络错误(其他错误)
|
|
59
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
60
|
+
* @param error - Axios 错误对象
|
|
69
61
|
*/
|
|
70
|
-
|
|
62
|
+
protected handleNetworkError(error: AxiosError): void;
|
|
71
63
|
/**
|
|
72
64
|
* 处理成功响应
|
|
73
65
|
* 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
|
|
@@ -79,9 +71,9 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
79
71
|
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
80
72
|
/**
|
|
81
73
|
* 支持路径解析的辅助函数
|
|
82
|
-
* @param obj
|
|
83
|
-
* @param path
|
|
84
|
-
* @
|
|
74
|
+
* @param obj
|
|
75
|
+
* @param path
|
|
76
|
+
* @protected
|
|
85
77
|
*/
|
|
86
78
|
protected getValueByPath(obj: any, path: string | undefined): any;
|
|
87
79
|
/**
|
|
@@ -104,15 +96,6 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
104
96
|
* @param responseData - 响应数据
|
|
105
97
|
*/
|
|
106
98
|
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
|
-
*/
|
|
115
|
-
private showSystemErrorMessage;
|
|
116
99
|
/**
|
|
117
100
|
* 处理业务错误(其他非200错误码)
|
|
118
101
|
* 子类可重写此方法来自定义业务错误处理逻辑
|
|
@@ -123,23 +106,15 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
123
106
|
/**
|
|
124
107
|
* 处理错误数组 errors(如果有配置)
|
|
125
108
|
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
126
|
-
* @param httpData
|
|
127
|
-
* @param response
|
|
109
|
+
* @param httpData
|
|
110
|
+
* @param response
|
|
128
111
|
*/
|
|
129
112
|
protected handleErrorArray(httpData: any, response: AxiosResponse): void;
|
|
130
|
-
/**
|
|
131
|
-
* 显示通知的通用方法
|
|
132
|
-
* @param items - 通知项数组
|
|
133
|
-
* @param type - 通知类型
|
|
134
|
-
* @param color - HTML 颜色
|
|
135
|
-
* @param notificationOptions - 通知配置选项
|
|
136
|
-
*/
|
|
137
|
-
private showNotification;
|
|
138
113
|
/**
|
|
139
114
|
* 显示错误数组通知
|
|
140
115
|
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
141
116
|
* @param errors - 错误数组
|
|
142
|
-
* @param notificationOptions
|
|
117
|
+
* @param notificationOptions
|
|
143
118
|
*/
|
|
144
119
|
protected showErrorArrayNotification(errors: Array<{
|
|
145
120
|
code: string;
|
|
@@ -148,20 +123,33 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
148
123
|
/**
|
|
149
124
|
* 处理提示信息 tips(如果有配置)
|
|
150
125
|
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
151
|
-
* @param httpData
|
|
152
|
-
* @param response
|
|
126
|
+
* @param httpData
|
|
127
|
+
* @param response
|
|
153
128
|
*/
|
|
154
129
|
protected handleTips(httpData: any, response: AxiosResponse): void;
|
|
155
130
|
/**
|
|
156
131
|
* 显示提示信息通知
|
|
157
132
|
* 子类可重写此方法来自定义提示信息通知显示方式
|
|
158
133
|
* @param tips - 提示信息数组
|
|
159
|
-
* @param notificationOptions
|
|
134
|
+
* @param notificationOptions
|
|
160
135
|
*/
|
|
161
136
|
protected showTipsNotification(tips: Array<{
|
|
162
137
|
code: string;
|
|
163
138
|
message: string;
|
|
164
139
|
}>, 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>;
|
|
165
153
|
/**
|
|
166
154
|
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
167
155
|
* 显式声明以确保类型一致性,子类可重写此方法
|
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("15f3588e-db6a-462d-bd63-229ddf648054")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "15f3588e-db6a-462d-bd63-229ddf648054";
|
|
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
|
}
|
|
@@ -12049,9 +12049,9 @@ notify.closeAll = closeAll;
|
|
|
12049
12049
|
notify.updateOffsets = updateOffsets;
|
|
12050
12050
|
notify._context = null;
|
|
12051
12051
|
const ElNotification = withInstallFunction(notify, "$notify");
|
|
12052
|
-
const hasDocument$
|
|
12052
|
+
const hasDocument$2 = typeof document !== "undefined";
|
|
12053
12053
|
function createMessageWrapper() {
|
|
12054
|
-
if (hasDocument$
|
|
12054
|
+
if (hasDocument$2) {
|
|
12055
12055
|
return ElMessage;
|
|
12056
12056
|
}
|
|
12057
12057
|
return {
|
|
@@ -12071,9 +12071,9 @@ function createMessageWrapper() {
|
|
|
12071
12071
|
}
|
|
12072
12072
|
};
|
|
12073
12073
|
}
|
|
12074
|
-
const hasDocument = typeof document !== "undefined";
|
|
12074
|
+
const hasDocument$1 = typeof document !== "undefined";
|
|
12075
12075
|
function createNotificationWrapper() {
|
|
12076
|
-
if (hasDocument) {
|
|
12076
|
+
if (hasDocument$1) {
|
|
12077
12077
|
return ElNotification;
|
|
12078
12078
|
}
|
|
12079
12079
|
const consoleNotification = (options, level = "info") => {
|
|
@@ -12440,18 +12440,22 @@ class BaseHttpClient {
|
|
|
12440
12440
|
window.URL.revokeObjectURL(url);
|
|
12441
12441
|
}
|
|
12442
12442
|
}
|
|
12443
|
-
async function
|
|
12443
|
+
async function dynamicImport(modulePromise, exportName = "default") {
|
|
12444
12444
|
const module = await modulePromise;
|
|
12445
|
+
if (exportName === "default") {
|
|
12446
|
+
return module.default ?? module;
|
|
12447
|
+
}
|
|
12448
|
+
if (!(exportName in module)) {
|
|
12449
|
+
throw new Error(`模块中不存在导出 "${exportName}"`);
|
|
12450
|
+
}
|
|
12451
|
+
return module[exportName];
|
|
12452
|
+
}
|
|
12453
|
+
async function dynamicImports(modulePromise, exportNames) {
|
|
12445
12454
|
const result = {};
|
|
12446
|
-
for (const
|
|
12447
|
-
const
|
|
12448
|
-
if (
|
|
12449
|
-
result[name] =
|
|
12450
|
-
} else {
|
|
12451
|
-
if (!(name in module)) {
|
|
12452
|
-
throw new Error(`模块中不存在导出 "${name}"`);
|
|
12453
|
-
}
|
|
12454
|
-
result[name] = module[name];
|
|
12455
|
+
for (const name of exportNames) {
|
|
12456
|
+
const exportCode = await dynamicImport(modulePromise, name);
|
|
12457
|
+
if (exportCode) {
|
|
12458
|
+
result[name] = exportCode;
|
|
12455
12459
|
}
|
|
12456
12460
|
}
|
|
12457
12461
|
return result;
|
|
@@ -12593,7 +12597,9 @@ function createApiDialog(DialogComponent) {
|
|
|
12593
12597
|
close: close2
|
|
12594
12598
|
};
|
|
12595
12599
|
}
|
|
12596
|
-
const
|
|
12600
|
+
const hasDocument = typeof document !== "undefined";
|
|
12601
|
+
let systemErrorDialogInstance = null;
|
|
12602
|
+
class BaseApi extends BaseHttpClient {
|
|
12597
12603
|
/**
|
|
12598
12604
|
* 创建 BaseApi 实例
|
|
12599
12605
|
* @param config - API 配置对象
|
|
@@ -12602,24 +12608,11 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12602
12608
|
const {
|
|
12603
12609
|
responseFields,
|
|
12604
12610
|
enableSystemErrorDialog = true,
|
|
12605
|
-
systemErrorMessage = "系统错误",
|
|
12606
12611
|
...baseConfig
|
|
12607
12612
|
} = config;
|
|
12608
12613
|
super(baseConfig);
|
|
12609
12614
|
__publicField(this, "responseFields");
|
|
12610
12615
|
__publicField(this, "enableSystemErrorDialog");
|
|
12611
|
-
__publicField(this, "systemErrorMessage");
|
|
12612
|
-
/**
|
|
12613
|
-
* SystemErrorDialog 实例
|
|
12614
|
-
* 注意:这是实例属性,每个实例有自己的对话框实例
|
|
12615
|
-
* 在构造函数中初始化(如果启用系统错误弹窗)
|
|
12616
|
-
*/
|
|
12617
|
-
__publicField(this, "systemErrorDialogInstance", null);
|
|
12618
|
-
/**
|
|
12619
|
-
* SystemErrorDialog 初始化 Promise
|
|
12620
|
-
* 用于跟踪初始化状态,避免重复初始化
|
|
12621
|
-
*/
|
|
12622
|
-
__publicField(this, "systemErrorDialogInitPromise", null);
|
|
12623
12616
|
this.responseFields = {
|
|
12624
12617
|
code: "Code",
|
|
12625
12618
|
message: "Message",
|
|
@@ -12629,103 +12622,66 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12629
12622
|
...responseFields
|
|
12630
12623
|
};
|
|
12631
12624
|
this.enableSystemErrorDialog = enableSystemErrorDialog;
|
|
12632
|
-
this.systemErrorMessage = systemErrorMessage;
|
|
12633
|
-
if (this.enableSystemErrorDialog && this.hasDocument) {
|
|
12634
|
-
this.systemErrorDialogInitPromise = this.initSystemErrorDialog();
|
|
12635
|
-
}
|
|
12636
12625
|
}
|
|
12637
12626
|
/**
|
|
12638
|
-
*
|
|
12639
|
-
*
|
|
12627
|
+
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
12628
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12629
|
+
* @param config - 请求配置对象
|
|
12630
|
+
* @returns 处理后的请求配置
|
|
12640
12631
|
*/
|
|
12641
|
-
|
|
12642
|
-
return
|
|
12632
|
+
processRequestConfig(config) {
|
|
12633
|
+
return super.processRequestConfig(config);
|
|
12643
12634
|
}
|
|
12644
12635
|
/**
|
|
12645
|
-
*
|
|
12646
|
-
*
|
|
12636
|
+
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
12637
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12638
|
+
* @param response - Axios 响应对象
|
|
12639
|
+
* @returns 解析后的响应数据
|
|
12647
12640
|
*/
|
|
12648
|
-
|
|
12649
|
-
return
|
|
12641
|
+
processResponseConfig(response) {
|
|
12642
|
+
return super.processResponseConfig(response);
|
|
12650
12643
|
}
|
|
12651
12644
|
/**
|
|
12652
|
-
*
|
|
12653
|
-
*
|
|
12645
|
+
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
12646
|
+
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12647
|
+
* @param error - Axios 错误对象
|
|
12648
|
+
* @returns 处理后的错误对象
|
|
12654
12649
|
*/
|
|
12655
|
-
|
|
12656
|
-
return
|
|
12650
|
+
async processResponseError(error) {
|
|
12651
|
+
return super.processResponseError(error);
|
|
12657
12652
|
}
|
|
12658
12653
|
/**
|
|
12659
|
-
*
|
|
12660
|
-
*
|
|
12654
|
+
* 处理 HTTP 状态码
|
|
12655
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
12656
|
+
* @param response - Axios 响应对象
|
|
12661
12657
|
*/
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
if (!errorInfo) {
|
|
12665
|
-
console.warn("未找到错误信息,ID:", errorId);
|
|
12666
|
-
return;
|
|
12667
|
-
}
|
|
12668
|
-
this.systemErrorInfoMap.delete(errorId);
|
|
12669
|
-
try {
|
|
12670
|
-
if (!this.systemErrorDialogInstance) {
|
|
12671
|
-
if (this.systemErrorDialogInitPromise) {
|
|
12672
|
-
try {
|
|
12673
|
-
await this.systemErrorDialogInitPromise;
|
|
12674
|
-
} catch {
|
|
12675
|
-
console.error("系统异常信息:", errorInfo.responseData);
|
|
12676
|
-
return;
|
|
12677
|
-
}
|
|
12678
|
-
} else {
|
|
12679
|
-
try {
|
|
12680
|
-
await this.initSystemErrorDialog();
|
|
12681
|
-
} catch {
|
|
12682
|
-
console.error("系统异常信息:", errorInfo.responseData);
|
|
12683
|
-
return;
|
|
12684
|
-
}
|
|
12685
|
-
}
|
|
12686
|
-
if (!this.systemErrorDialogInstance) {
|
|
12687
|
-
console.error("系统异常信息:", errorInfo.responseData);
|
|
12688
|
-
return;
|
|
12689
|
-
}
|
|
12690
|
-
}
|
|
12691
|
-
const errorInfoData = extractSystemErrorInfo(
|
|
12692
|
-
errorInfo.response,
|
|
12693
|
-
errorInfo.code,
|
|
12694
|
-
errorInfo.message
|
|
12695
|
-
);
|
|
12696
|
-
this.systemErrorDialogInstance.show({
|
|
12697
|
-
props: {
|
|
12698
|
-
title: "系统异常信息",
|
|
12699
|
-
width: 600,
|
|
12700
|
-
...errorInfoData
|
|
12701
|
-
}
|
|
12702
|
-
}).then((result) => {
|
|
12703
|
-
if (result == null ? void 0 : result.reported) {
|
|
12704
|
-
/* @__PURE__ */ console.log("系统异常已上报:", result);
|
|
12705
|
-
} else {
|
|
12706
|
-
/* @__PURE__ */ console.log("系统异常对话框已确认");
|
|
12707
|
-
}
|
|
12708
|
-
}).catch((e) => {
|
|
12709
|
-
/* @__PURE__ */ console.log("系统异常对话框已关闭", e);
|
|
12710
|
-
});
|
|
12711
|
-
} catch (error) {
|
|
12712
|
-
console.error("显示系统异常对话框失败:", error);
|
|
12713
|
-
console.error("系统异常信息:", errorInfo.responseData);
|
|
12714
|
-
}
|
|
12658
|
+
handleHttpStatus(response) {
|
|
12659
|
+
return super.handleHttpStatus(response);
|
|
12715
12660
|
}
|
|
12716
12661
|
/**
|
|
12717
|
-
*
|
|
12718
|
-
*
|
|
12719
|
-
*
|
|
12662
|
+
* 处理认证错误(401 - 未授权/登录失效)
|
|
12663
|
+
* 重写父类方法,处理 HTTP 401 错误
|
|
12664
|
+
* 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
|
|
12665
|
+
* @param error - Axios 错误对象
|
|
12720
12666
|
*/
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12727
|
-
|
|
12728
|
-
|
|
12667
|
+
handleAuthenticationError(error) {
|
|
12668
|
+
super.handleAuthenticationError(error);
|
|
12669
|
+
}
|
|
12670
|
+
/**
|
|
12671
|
+
* 处理超时错误
|
|
12672
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
12673
|
+
* @param error - Axios 错误对象
|
|
12674
|
+
*/
|
|
12675
|
+
handleTimeoutError(error) {
|
|
12676
|
+
return super.handleTimeoutError(error);
|
|
12677
|
+
}
|
|
12678
|
+
/**
|
|
12679
|
+
* 处理网络错误(其他错误)
|
|
12680
|
+
* 重写父类方法,确保子类可以重写此方法
|
|
12681
|
+
* @param error - Axios 错误对象
|
|
12682
|
+
*/
|
|
12683
|
+
handleNetworkError(error) {
|
|
12684
|
+
return super.handleNetworkError(error);
|
|
12729
12685
|
}
|
|
12730
12686
|
/**
|
|
12731
12687
|
* 处理成功响应
|
|
@@ -12751,9 +12707,9 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12751
12707
|
}
|
|
12752
12708
|
/**
|
|
12753
12709
|
* 支持路径解析的辅助函数
|
|
12754
|
-
* @param obj
|
|
12755
|
-
* @param path
|
|
12756
|
-
* @
|
|
12710
|
+
* @param obj
|
|
12711
|
+
* @param path
|
|
12712
|
+
* @protected
|
|
12757
12713
|
*/
|
|
12758
12714
|
getValueByPath(obj, path) {
|
|
12759
12715
|
if (!path)
|
|
@@ -12793,77 +12749,13 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12793
12749
|
handleSystemError(response, code, message2, responseData) {
|
|
12794
12750
|
if (code === -1) {
|
|
12795
12751
|
if (this.enableSystemErrorDialog) {
|
|
12796
|
-
this.
|
|
12752
|
+
this.showSystemExceptionDialog(response, responseData, code, message2).catch((error) => {
|
|
12753
|
+
console.error("显示系统异常对话框失败:", error);
|
|
12754
|
+
});
|
|
12797
12755
|
}
|
|
12798
12756
|
throw new Error(message2 || "系统异常");
|
|
12799
12757
|
}
|
|
12800
12758
|
}
|
|
12801
|
-
/**
|
|
12802
|
-
* 显示系统错误消息(带可点击 icon)
|
|
12803
|
-
* 使用 vNode 渲染,点击 icon 后打开详细错误弹窗
|
|
12804
|
-
* @param response - Axios 响应对象
|
|
12805
|
-
* @param responseData - 响应数据
|
|
12806
|
-
* @param code - 错误状态码
|
|
12807
|
-
* @param message - 错误消息
|
|
12808
|
-
*/
|
|
12809
|
-
showSystemErrorMessage(response, responseData, code, message2) {
|
|
12810
|
-
var _a2;
|
|
12811
|
-
if (!this.hasDocument) {
|
|
12812
|
-
console.error("系统异常信息:", responseData);
|
|
12813
|
-
return;
|
|
12814
|
-
}
|
|
12815
|
-
const errorId = this.generateErrorId();
|
|
12816
|
-
this.systemErrorInfoMap.set(errorId, {
|
|
12817
|
-
response,
|
|
12818
|
-
responseData,
|
|
12819
|
-
code,
|
|
12820
|
-
message: message2
|
|
12821
|
-
});
|
|
12822
|
-
setTimeout(() => {
|
|
12823
|
-
this.systemErrorInfoMap.delete(errorId);
|
|
12824
|
-
}, 5 * 60 * 1e3);
|
|
12825
|
-
const handleIconClick = () => {
|
|
12826
|
-
this.openSystemErrorDialog(errorId).catch((error) => {
|
|
12827
|
-
console.error("打开系统错误对话框失败:", error);
|
|
12828
|
-
});
|
|
12829
|
-
};
|
|
12830
|
-
const messageVNode = h("div", {
|
|
12831
|
-
style: {
|
|
12832
|
-
display: "flex",
|
|
12833
|
-
alignItems: "center",
|
|
12834
|
-
gap: "8px",
|
|
12835
|
-
maxWidth: "100%"
|
|
12836
|
-
}
|
|
12837
|
-
}, [
|
|
12838
|
-
h("div", {
|
|
12839
|
-
style: {
|
|
12840
|
-
color: "var(--el-message-text-color)",
|
|
12841
|
-
lineHeight: "24px"
|
|
12842
|
-
}
|
|
12843
|
-
}, message2 || this.systemErrorMessage),
|
|
12844
|
-
h("svg", {
|
|
12845
|
-
onClick: handleIconClick,
|
|
12846
|
-
style: {
|
|
12847
|
-
cursor: "pointer",
|
|
12848
|
-
color: "#F56C6C",
|
|
12849
|
-
width: "16px",
|
|
12850
|
-
height: "16px",
|
|
12851
|
-
flexShrink: 0
|
|
12852
|
-
},
|
|
12853
|
-
viewBox: "0 0 1024 1024",
|
|
12854
|
-
fill: "currentColor",
|
|
12855
|
-
xmlns: "http://www.w3.org/2000/svg"
|
|
12856
|
-
}, [
|
|
12857
|
-
h("path", {
|
|
12858
|
-
d: "M512 64C264.6 64 64 264.6 64 512s200.6 448 448 448 448-200.6 448-448S759.4 64 512 64zm32 664c0 4.4-3.6 8-8 8h-48c-4.4 0-8-3.6-8-8V456c0-4.4 3.6-8 8-8h48c4.4 0 8 3.6 8 8v272zm-32-344a48.01 48.01 0 0 1 0-96 48.01 48.01 0 0 1 0 96z"
|
|
12859
|
-
})
|
|
12860
|
-
])
|
|
12861
|
-
]);
|
|
12862
|
-
(_a2 = this.messageInstance) == null ? void 0 : _a2.error({
|
|
12863
|
-
message: messageVNode,
|
|
12864
|
-
duration: 5 * 1e3
|
|
12865
|
-
});
|
|
12866
|
-
}
|
|
12867
12759
|
/**
|
|
12868
12760
|
* 处理业务错误(其他非200错误码)
|
|
12869
12761
|
* 子类可重写此方法来自定义业务错误处理逻辑
|
|
@@ -12883,8 +12775,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12883
12775
|
/**
|
|
12884
12776
|
* 处理错误数组 errors(如果有配置)
|
|
12885
12777
|
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
12886
|
-
* @param httpData
|
|
12887
|
-
* @param response
|
|
12778
|
+
* @param httpData
|
|
12779
|
+
* @param response
|
|
12888
12780
|
*/
|
|
12889
12781
|
handleErrorArray(httpData, response) {
|
|
12890
12782
|
var _a2;
|
|
@@ -12900,20 +12792,19 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12900
12792
|
}
|
|
12901
12793
|
}
|
|
12902
12794
|
/**
|
|
12903
|
-
*
|
|
12904
|
-
*
|
|
12905
|
-
* @param
|
|
12906
|
-
* @param
|
|
12907
|
-
* @param notificationOptions - 通知配置选项
|
|
12795
|
+
* 显示错误数组通知
|
|
12796
|
+
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
12797
|
+
* @param errors - 错误数组
|
|
12798
|
+
* @param notificationOptions
|
|
12908
12799
|
*/
|
|
12909
|
-
|
|
12800
|
+
showErrorArrayNotification(errors, notificationOptions) {
|
|
12910
12801
|
var _a2, _b;
|
|
12802
|
+
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12911
12803
|
const defaultOptions = {
|
|
12912
12804
|
title: "提示",
|
|
12913
|
-
type
|
|
12805
|
+
type: "error"
|
|
12914
12806
|
};
|
|
12915
|
-
if (
|
|
12916
|
-
const html = items.map((item) => `<div style="font-size: 14px;color:${color}">${item.code}:${item.message}</div>`).join("");
|
|
12807
|
+
if (hasDocument) {
|
|
12917
12808
|
const finalOptions = {
|
|
12918
12809
|
...defaultOptions,
|
|
12919
12810
|
...notificationOptions,
|
|
@@ -12921,29 +12812,20 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12921
12812
|
};
|
|
12922
12813
|
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12923
12814
|
} else {
|
|
12924
|
-
const
|
|
12815
|
+
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12925
12816
|
const finalOptions = {
|
|
12926
12817
|
...defaultOptions,
|
|
12927
12818
|
...notificationOptions,
|
|
12928
|
-
message:
|
|
12819
|
+
message: errorMessages
|
|
12929
12820
|
};
|
|
12930
12821
|
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12931
12822
|
}
|
|
12932
12823
|
}
|
|
12933
|
-
/**
|
|
12934
|
-
* 显示错误数组通知
|
|
12935
|
-
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
12936
|
-
* @param errors - 错误数组
|
|
12937
|
-
* @param notificationOptions - 通知配置选项
|
|
12938
|
-
*/
|
|
12939
|
-
showErrorArrayNotification(errors, notificationOptions) {
|
|
12940
|
-
this.showNotification(errors, "error", "red", notificationOptions);
|
|
12941
|
-
}
|
|
12942
12824
|
/**
|
|
12943
12825
|
* 处理提示信息 tips(如果有配置)
|
|
12944
12826
|
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
12945
|
-
* @param httpData
|
|
12946
|
-
* @param response
|
|
12827
|
+
* @param httpData
|
|
12828
|
+
* @param response
|
|
12947
12829
|
*/
|
|
12948
12830
|
handleTips(httpData, response) {
|
|
12949
12831
|
var _a2;
|
|
@@ -12961,10 +12843,97 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12961
12843
|
* 显示提示信息通知
|
|
12962
12844
|
* 子类可重写此方法来自定义提示信息通知显示方式
|
|
12963
12845
|
* @param tips - 提示信息数组
|
|
12964
|
-
* @param notificationOptions
|
|
12846
|
+
* @param notificationOptions
|
|
12965
12847
|
*/
|
|
12966
12848
|
showTipsNotification(tips, notificationOptions) {
|
|
12967
|
-
|
|
12849
|
+
var _a2, _b;
|
|
12850
|
+
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12851
|
+
const defaultOptions = {
|
|
12852
|
+
title: "提示",
|
|
12853
|
+
type: "warning"
|
|
12854
|
+
};
|
|
12855
|
+
if (hasDocument) {
|
|
12856
|
+
const finalOptions = {
|
|
12857
|
+
...defaultOptions,
|
|
12858
|
+
...notificationOptions,
|
|
12859
|
+
message: html
|
|
12860
|
+
};
|
|
12861
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12862
|
+
} else {
|
|
12863
|
+
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12864
|
+
const finalOptions = {
|
|
12865
|
+
...defaultOptions,
|
|
12866
|
+
...notificationOptions,
|
|
12867
|
+
message: tipMessages
|
|
12868
|
+
};
|
|
12869
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12870
|
+
}
|
|
12871
|
+
}
|
|
12872
|
+
/**
|
|
12873
|
+
* 显示系统异常对话框,当响应状态码为 -1 时调用
|
|
12874
|
+
* @param response - Axios 响应对象
|
|
12875
|
+
* @param responseData - 响应数据
|
|
12876
|
+
* @param code - 错误状态码
|
|
12877
|
+
* @param message - 错误消息
|
|
12878
|
+
*/
|
|
12879
|
+
async showSystemExceptionDialog(response, responseData, code, message2) {
|
|
12880
|
+
if (!hasDocument) {
|
|
12881
|
+
console.error("系统异常信息:", responseData);
|
|
12882
|
+
return;
|
|
12883
|
+
}
|
|
12884
|
+
try {
|
|
12885
|
+
if (!systemErrorDialogInstance) {
|
|
12886
|
+
try {
|
|
12887
|
+
const { default: SystemErrorDialog2 } = await dynamicImports(Promise.resolve().then(() => SystemErrorDialog$1), ["default"]);
|
|
12888
|
+
systemErrorDialogInstance = createApiDialog(SystemErrorDialog2);
|
|
12889
|
+
} catch (error) {
|
|
12890
|
+
console.warn("Failed to load SystemErrorDialog:", error);
|
|
12891
|
+
console.error("系统异常信息:", responseData);
|
|
12892
|
+
return;
|
|
12893
|
+
}
|
|
12894
|
+
}
|
|
12895
|
+
const errorInfo = extractSystemErrorInfo(response, code, message2);
|
|
12896
|
+
systemErrorDialogInstance.show({
|
|
12897
|
+
props: {
|
|
12898
|
+
title: "系统异常信息",
|
|
12899
|
+
width: 600,
|
|
12900
|
+
...errorInfo
|
|
12901
|
+
}
|
|
12902
|
+
}).then((result) => {
|
|
12903
|
+
if (result == null ? void 0 : result.reported) {
|
|
12904
|
+
/* @__PURE__ */ console.log("系统异常已上报:", result);
|
|
12905
|
+
this.reportError(result.errorInfo);
|
|
12906
|
+
} else {
|
|
12907
|
+
/* @__PURE__ */ console.log("系统异常对话框已确认");
|
|
12908
|
+
}
|
|
12909
|
+
}).catch((e) => {
|
|
12910
|
+
/* @__PURE__ */ console.log("系统异常对话框已关闭", e);
|
|
12911
|
+
});
|
|
12912
|
+
} catch (error) {
|
|
12913
|
+
console.error("显示系统异常对话框失败:", error);
|
|
12914
|
+
console.error("系统异常信息:", responseData);
|
|
12915
|
+
}
|
|
12916
|
+
}
|
|
12917
|
+
/**
|
|
12918
|
+
* 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
|
|
12919
|
+
* @param errorInfo - 错误信息对象
|
|
12920
|
+
*/
|
|
12921
|
+
async reportError(errorInfo) {
|
|
12922
|
+
var _a2, _b;
|
|
12923
|
+
try {
|
|
12924
|
+
/* @__PURE__ */ console.log("🚀 开始上报错误信息:", errorInfo);
|
|
12925
|
+
/* @__PURE__ */ console.log("✅ 错误信息上报成功");
|
|
12926
|
+
(_a2 = this.messageInstance) == null ? void 0 : _a2.success({
|
|
12927
|
+
message: "错误信息已成功上报",
|
|
12928
|
+
duration: 3 * 1e3
|
|
12929
|
+
});
|
|
12930
|
+
} catch (error) {
|
|
12931
|
+
console.error("❌ 错误信息上报失败:", error);
|
|
12932
|
+
(_b = this.messageInstance) == null ? void 0 : _b.error({
|
|
12933
|
+
message: "错误信息上报失败,请稍后重试",
|
|
12934
|
+
duration: 5 * 1e3
|
|
12935
|
+
});
|
|
12936
|
+
}
|
|
12968
12937
|
}
|
|
12969
12938
|
/**
|
|
12970
12939
|
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
@@ -13048,19 +13017,7 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
13048
13017
|
downloadFile(blob, filename) {
|
|
13049
13018
|
return super.downloadFile(blob, filename);
|
|
13050
13019
|
}
|
|
13051
|
-
}
|
|
13052
|
-
/**
|
|
13053
|
-
* 检查是否在浏览器环境(在类初始化时判断)
|
|
13054
|
-
* 注意:这是静态属性,所有实例共享
|
|
13055
|
-
*/
|
|
13056
|
-
__publicField(_BaseApi, "hasDocument", typeof document !== "undefined");
|
|
13057
|
-
/**
|
|
13058
|
-
* 系统错误信息存储,用于在点击 icon 时打开详细错误弹窗
|
|
13059
|
-
* key: 错误ID,value: 错误信息对象
|
|
13060
|
-
* 注意:这是静态属性,所有实例共享同一个错误信息存储
|
|
13061
|
-
*/
|
|
13062
|
-
__publicField(_BaseApi, "systemErrorInfoMap", /* @__PURE__ */ new Map());
|
|
13063
|
-
let BaseApi = _BaseApi;
|
|
13020
|
+
}
|
|
13064
13021
|
function createHttpService(options = {}) {
|
|
13065
13022
|
return new BaseApi(options);
|
|
13066
13023
|
}
|
|
@@ -13159,7 +13116,8 @@ const SystemErrorDialog = defineComponent({
|
|
|
13159
13116
|
const localUserInfo = getUserInfoFromLocalStorage();
|
|
13160
13117
|
return {
|
|
13161
13118
|
userName: localUserInfo.username ?? props.userName,
|
|
13162
|
-
userId: localUserInfo.id ?? props.userId,
|
|
13119
|
+
// userId: localUserInfo.id ?? props.userId,
|
|
13120
|
+
userId: localUserInfo.usercode ?? props.userId,
|
|
13163
13121
|
deptName: localUserInfo.workDeptName ?? props.deptName,
|
|
13164
13122
|
deptId: localUserInfo.workDeptId ?? props.deptId,
|
|
13165
13123
|
clientIp: localUserInfo.loginip ?? props.clientIp
|