@moluoxixi/ajax-package 0.0.33 → 0.0.35
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 +25 -0
- package/es/_types/api.d.ts +42 -4
- package/es/_utils/messageWrapper.d.ts +8 -35
- package/es/_utils/notificationWrapper.d.ts +9 -4
- package/es/class.d.ts +11 -27
- package/es/index.mjs +221 -91
- package/package.json +1 -1
package/es/BaseHttpClient.d.ts
CHANGED
|
@@ -20,6 +20,31 @@ export default class BaseHttpClient {
|
|
|
20
20
|
protected messageInstance: MessageInstance;
|
|
21
21
|
protected notificationInstance: NotificationInstance;
|
|
22
22
|
protected addSign?: (config: AxiosRequestConfig) => void;
|
|
23
|
+
/**
|
|
24
|
+
* 检查是否在浏览器环境(在类初始化时判断)
|
|
25
|
+
* 注意:这是静态属性,所有实例共享
|
|
26
|
+
*/
|
|
27
|
+
protected static readonly hasDocument: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* 获取是否在浏览器环境(实例 getter)
|
|
30
|
+
* @returns 是否在浏览器环境
|
|
31
|
+
*/
|
|
32
|
+
protected get hasDocument(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* 获取或创建 ajaxPackage-container 容器元素
|
|
35
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
36
|
+
*/
|
|
37
|
+
protected getContainer(): HTMLElement | null;
|
|
38
|
+
/**
|
|
39
|
+
* 获取或创建 ajaxPackage-popover 容器元素(用于 Dialog)
|
|
40
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
41
|
+
*/
|
|
42
|
+
protected getPopoverContainer(): HTMLElement | null;
|
|
43
|
+
/**
|
|
44
|
+
* 获取或创建 ajaxPackage-message 容器元素(用于 Message 和 Notification)
|
|
45
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
46
|
+
*/
|
|
47
|
+
protected getMessageContainer(): HTMLElement | null;
|
|
23
48
|
/**
|
|
24
49
|
* 创建 BaseHttpClient 实例
|
|
25
50
|
* @param config - HTTP 客户端配置对象
|
package/es/_types/api.d.ts
CHANGED
|
@@ -100,17 +100,46 @@ export interface NotificationOptions {
|
|
|
100
100
|
[key: string]: any;
|
|
101
101
|
}
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* 消息配置选项
|
|
104
104
|
*/
|
|
105
|
-
export interface
|
|
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 {
|
|
106
135
|
/**
|
|
107
136
|
* 错误通知配置选项,用于覆盖默认的错误通知参数
|
|
108
137
|
*/
|
|
109
138
|
errorNotificationOptions?: NotificationOptions;
|
|
110
139
|
/**
|
|
111
|
-
*
|
|
140
|
+
* 提示消息配置选项,用于覆盖默认的提示消息参数
|
|
112
141
|
*/
|
|
113
|
-
|
|
142
|
+
tipsMessageOptions?: MessageOptions;
|
|
114
143
|
/**
|
|
115
144
|
* 是否使用自定义消息处理
|
|
116
145
|
* 当为 true 时,handleBusinessError、handleErrorArray、handleTips 都不会执行
|
|
@@ -118,3 +147,12 @@ export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
|
118
147
|
*/
|
|
119
148
|
isCustomMessage?: boolean;
|
|
120
149
|
}
|
|
150
|
+
/**
|
|
151
|
+
* 扩展 AxiosRequestConfig,支持自定义通知配置
|
|
152
|
+
*/
|
|
153
|
+
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
154
|
+
/**
|
|
155
|
+
* 消息相关配置选项,集中管理消息、通知和自定义处理配置
|
|
156
|
+
*/
|
|
157
|
+
messageConfigs?: MessageConfigs;
|
|
158
|
+
}
|
|
@@ -1,39 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 创建消息实例的包装函数
|
|
3
|
-
* @
|
|
3
|
+
* @param hasDocument - 是否在浏览器环境
|
|
4
|
+
* @param container - 容器元素,如果提供则消息将挂载到该容器中
|
|
5
|
+
* @returns 消息函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
|
|
4
6
|
*/
|
|
5
|
-
export declare function createMessageWrapper(): (
|
|
6
|
-
|
|
7
|
-
success
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
error: import('element-plus').MessageTypedFn;
|
|
11
|
-
} & import('vue').ObjectPlugin<any[]> & {
|
|
12
|
-
_context: import('vue').AppContext | null;
|
|
13
|
-
}) | (import('element-plus').MessageFn & {
|
|
14
|
-
primary: import('element-plus').MessageTypedFn;
|
|
15
|
-
success: import('element-plus').MessageTypedFn;
|
|
16
|
-
warning: import('element-plus').MessageTypedFn;
|
|
17
|
-
info: import('element-plus').MessageTypedFn;
|
|
18
|
-
error: import('element-plus').MessageTypedFn;
|
|
19
|
-
} & ((app: import('vue').App, ...options: any[]) => any) & Partial<import('vue').ObjectPlugin<any[]>> & {
|
|
20
|
-
_context: import('vue').AppContext | null;
|
|
21
|
-
}) | {
|
|
22
|
-
success: (options: string | {
|
|
23
|
-
message?: string;
|
|
24
|
-
[key: string]: any;
|
|
25
|
-
}) => void;
|
|
26
|
-
error: (options: string | {
|
|
27
|
-
message?: string;
|
|
28
|
-
[key: string]: any;
|
|
29
|
-
}) => void;
|
|
30
|
-
warning: (options: string | {
|
|
31
|
-
message?: string;
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}) => void;
|
|
34
|
-
info: (options: string | {
|
|
35
|
-
message?: string;
|
|
36
|
-
[key: string]: any;
|
|
37
|
-
}) => void;
|
|
38
|
-
};
|
|
7
|
+
export declare function createMessageWrapper(hasDocument: boolean, container?: HTMLElement | null): (options: string | {
|
|
8
|
+
message?: string;
|
|
9
|
+
type?: "success" | "error" | "warning" | "info";
|
|
10
|
+
[key: string]: any;
|
|
11
|
+
}) => void;
|
|
39
12
|
export type MessageInstance = ReturnType<typeof createMessageWrapper>;
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 创建通知实例的包装函数(用于 errors / tips 展示)
|
|
3
|
-
* @
|
|
3
|
+
* @param hasDocument - 是否在浏览器环境
|
|
4
|
+
* @param container - 容器元素,如果提供则通知将挂载到该容器中
|
|
5
|
+
* @returns 通知函数实例,直接调用即可,支持传入 type: 'success' | 'error' | 'warning' | 'info'
|
|
4
6
|
*/
|
|
5
|
-
export declare function createNotificationWrapper(): ((
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
export declare function createNotificationWrapper(hasDocument: boolean, container?: HTMLElement | null): ((options: string | {
|
|
8
|
+
message?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
type?: "success" | "error" | "warning" | "info";
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}) => import('element-plus').NotificationHandle) | ((options: string | {
|
|
8
13
|
message?: string;
|
|
9
14
|
title?: string;
|
|
10
15
|
type?: "success" | "error" | "warning" | "info";
|
package/es/class.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
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
4
|
/**
|
|
5
5
|
* BaseApi 类
|
|
@@ -10,11 +10,6 @@ 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;
|
|
18
13
|
/**
|
|
19
14
|
* SystemErrorDialog 实例
|
|
20
15
|
* 注意:这是实例属性,每个实例有自己的对话框实例
|
|
@@ -32,11 +27,6 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
32
27
|
* 注意:这是静态属性,所有实例共享同一个错误信息存储
|
|
33
28
|
*/
|
|
34
29
|
private static systemErrorInfoMap;
|
|
35
|
-
/**
|
|
36
|
-
* 获取是否在浏览器环境(实例 getter)
|
|
37
|
-
* @returns 是否在浏览器环境
|
|
38
|
-
*/
|
|
39
|
-
protected get hasDocument(): boolean;
|
|
40
30
|
/**
|
|
41
31
|
* 获取系统错误信息存储(实例 getter)
|
|
42
32
|
* @returns 系统错误信息存储 Map
|
|
@@ -128,20 +118,13 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
128
118
|
*/
|
|
129
119
|
protected handleErrorArray(httpData: any, response: AxiosResponse): void;
|
|
130
120
|
/**
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* @param color - HTML 颜色
|
|
135
|
-
* @param notificationOptions - 通知配置选项
|
|
136
|
-
*/
|
|
137
|
-
private showNotification;
|
|
138
|
-
/**
|
|
139
|
-
* 显示错误数组通知
|
|
140
|
-
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
121
|
+
* 显示错误信息(默认实现)
|
|
122
|
+
* 使用 notification 显示错误信息
|
|
123
|
+
* 子类可重写此方法来自定义错误信息显示方式
|
|
141
124
|
* @param errors - 错误数组
|
|
142
125
|
* @param notificationOptions - 通知配置选项
|
|
143
126
|
*/
|
|
144
|
-
protected
|
|
127
|
+
protected showErrors(errors: Array<{
|
|
145
128
|
code: string;
|
|
146
129
|
message: string;
|
|
147
130
|
}>, notificationOptions?: NotificationOptions): void;
|
|
@@ -153,15 +136,16 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
153
136
|
*/
|
|
154
137
|
protected handleTips(httpData: any, response: AxiosResponse): void;
|
|
155
138
|
/**
|
|
156
|
-
*
|
|
157
|
-
*
|
|
139
|
+
* 显示提示信息(默认实现)
|
|
140
|
+
* 根据 messageOptions.type 指定消息类型显示,提取所有 message 并连接
|
|
141
|
+
* 子类可重写此方法来自定义提示信息显示方式
|
|
158
142
|
* @param tips - 提示信息数组
|
|
159
|
-
* @param
|
|
143
|
+
* @param messageOptions - 消息配置选项
|
|
160
144
|
*/
|
|
161
|
-
protected
|
|
145
|
+
protected showTips(tips: Array<{
|
|
162
146
|
code: string;
|
|
163
147
|
message: string;
|
|
164
|
-
}>,
|
|
148
|
+
}>, messageOptions?: MessageOptions): void;
|
|
165
149
|
/**
|
|
166
150
|
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
167
151
|
* 显式声明以确保类型一致性,子类可重写此方法
|
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("59b794d1-a3ef-4b37-9b28-cc9399203b57")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "59b794d1-a3ef-4b37-9b28-cc9399203b57";
|
|
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,32 +12049,38 @@ notify.closeAll = closeAll;
|
|
|
12049
12049
|
notify.updateOffsets = updateOffsets;
|
|
12050
12050
|
notify._context = null;
|
|
12051
12051
|
const ElNotification = withInstallFunction(notify, "$notify");
|
|
12052
|
-
|
|
12053
|
-
|
|
12054
|
-
|
|
12055
|
-
|
|
12052
|
+
function createMessageWrapper(hasDocument, container) {
|
|
12053
|
+
if (hasDocument) {
|
|
12054
|
+
return (options) => {
|
|
12055
|
+
const opts = typeof options === "string" ? { message: options } : options;
|
|
12056
|
+
const finalOptions = container ? { ...opts, appendTo: container } : opts;
|
|
12057
|
+
return ElMessage(finalOptions);
|
|
12058
|
+
};
|
|
12056
12059
|
}
|
|
12057
|
-
return {
|
|
12058
|
-
|
|
12059
|
-
|
|
12060
|
-
|
|
12061
|
-
|
|
12062
|
-
|
|
12063
|
-
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12068
|
-
|
|
12069
|
-
|
|
12070
|
-
|
|
12060
|
+
return (options) => {
|
|
12061
|
+
const opts = typeof options === "string" ? { message: options } : options;
|
|
12062
|
+
const message2 = (opts == null ? void 0 : opts.message) || "";
|
|
12063
|
+
const type = (opts == null ? void 0 : opts.type) || "info";
|
|
12064
|
+
const logMessage = `[Message ${type}] ${message2}`;
|
|
12065
|
+
switch (type) {
|
|
12066
|
+
case "success":
|
|
12067
|
+
break;
|
|
12068
|
+
case "error":
|
|
12069
|
+
console.error(logMessage);
|
|
12070
|
+
break;
|
|
12071
|
+
case "warning":
|
|
12072
|
+
console.warn(logMessage);
|
|
12073
|
+
break;
|
|
12071
12074
|
}
|
|
12072
12075
|
};
|
|
12073
12076
|
}
|
|
12074
|
-
|
|
12075
|
-
function createNotificationWrapper() {
|
|
12077
|
+
function createNotificationWrapper(hasDocument, container) {
|
|
12076
12078
|
if (hasDocument) {
|
|
12077
|
-
return
|
|
12079
|
+
return (options) => {
|
|
12080
|
+
const opts = typeof options === "string" ? { message: options } : options;
|
|
12081
|
+
const finalOptions = container ? { ...opts, appendTo: container } : opts;
|
|
12082
|
+
return ElNotification(finalOptions);
|
|
12083
|
+
};
|
|
12078
12084
|
}
|
|
12079
12085
|
const consoleNotification = (options, level = "info") => {
|
|
12080
12086
|
const opts = typeof options === "string" ? { message: options } : options;
|
|
@@ -12188,7 +12194,8 @@ function extractSystemErrorInfo(response, code, message2) {
|
|
|
12188
12194
|
};
|
|
12189
12195
|
}
|
|
12190
12196
|
function defaultOnLoginRequired(messageInstance) {
|
|
12191
|
-
messageInstance == null ? void 0 : messageInstance
|
|
12197
|
+
messageInstance == null ? void 0 : messageInstance({
|
|
12198
|
+
type: "error",
|
|
12192
12199
|
message: "登录已过期,请重新登录",
|
|
12193
12200
|
duration: 5 * 1e3
|
|
12194
12201
|
});
|
|
@@ -12199,7 +12206,7 @@ function defaultOnLoginRequired(messageInstance) {
|
|
|
12199
12206
|
function defaultGetToken() {
|
|
12200
12207
|
return typeof localStorage !== "undefined" ? localStorage.getItem("token") || "" : "";
|
|
12201
12208
|
}
|
|
12202
|
-
class
|
|
12209
|
+
const _BaseHttpClient = class _BaseHttpClient {
|
|
12203
12210
|
/**
|
|
12204
12211
|
* 创建 BaseHttpClient 实例
|
|
12205
12212
|
* @param config - HTTP 客户端配置对象
|
|
@@ -12226,8 +12233,10 @@ class BaseHttpClient {
|
|
|
12226
12233
|
} = config;
|
|
12227
12234
|
this.baseURL = baseURL;
|
|
12228
12235
|
this.timeout = timeout;
|
|
12229
|
-
this.
|
|
12230
|
-
|
|
12236
|
+
this.getContainer();
|
|
12237
|
+
const messageContainer = this.getMessageContainer();
|
|
12238
|
+
this.messageInstance = createMessageWrapper(this.hasDocument, messageContainer);
|
|
12239
|
+
this.notificationInstance = createNotificationWrapper(this.hasDocument, messageContainer);
|
|
12231
12240
|
this.onTimeout = onTimeout;
|
|
12232
12241
|
this.getToken = getToken;
|
|
12233
12242
|
this.onLoginRequired = onLoginRequired;
|
|
@@ -12240,6 +12249,58 @@ class BaseHttpClient {
|
|
|
12240
12249
|
});
|
|
12241
12250
|
this.setupInterceptors();
|
|
12242
12251
|
}
|
|
12252
|
+
/**
|
|
12253
|
+
* 获取是否在浏览器环境(实例 getter)
|
|
12254
|
+
* @returns 是否在浏览器环境
|
|
12255
|
+
*/
|
|
12256
|
+
get hasDocument() {
|
|
12257
|
+
return _BaseHttpClient.hasDocument;
|
|
12258
|
+
}
|
|
12259
|
+
/**
|
|
12260
|
+
* 获取或创建 ajaxPackage-container 容器元素
|
|
12261
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
12262
|
+
*/
|
|
12263
|
+
getContainer() {
|
|
12264
|
+
if (!this.hasDocument) {
|
|
12265
|
+
return null;
|
|
12266
|
+
}
|
|
12267
|
+
let container = document.getElementById("ajaxPackage-container");
|
|
12268
|
+
if (!container) {
|
|
12269
|
+
container = document.createElement("div");
|
|
12270
|
+
container.id = "ajaxPackage-container";
|
|
12271
|
+
document.body.appendChild(container);
|
|
12272
|
+
const popoverContainer = document.createElement("div");
|
|
12273
|
+
popoverContainer.id = "ajaxPackage-popover";
|
|
12274
|
+
container.appendChild(popoverContainer);
|
|
12275
|
+
const messageContainer = document.createElement("div");
|
|
12276
|
+
messageContainer.id = "ajaxPackage-message";
|
|
12277
|
+
messageContainer.style.zIndex = "99999999";
|
|
12278
|
+
container.appendChild(messageContainer);
|
|
12279
|
+
}
|
|
12280
|
+
return container;
|
|
12281
|
+
}
|
|
12282
|
+
/**
|
|
12283
|
+
* 获取或创建 ajaxPackage-popover 容器元素(用于 Dialog)
|
|
12284
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
12285
|
+
*/
|
|
12286
|
+
getPopoverContainer() {
|
|
12287
|
+
if (!this.hasDocument) {
|
|
12288
|
+
return null;
|
|
12289
|
+
}
|
|
12290
|
+
this.getContainer();
|
|
12291
|
+
return document.getElementById("ajaxPackage-popover");
|
|
12292
|
+
}
|
|
12293
|
+
/**
|
|
12294
|
+
* 获取或创建 ajaxPackage-message 容器元素(用于 Message 和 Notification)
|
|
12295
|
+
* @returns 容器元素,如果不是浏览器环境则返回 null
|
|
12296
|
+
*/
|
|
12297
|
+
getMessageContainer() {
|
|
12298
|
+
if (!this.hasDocument) {
|
|
12299
|
+
return null;
|
|
12300
|
+
}
|
|
12301
|
+
this.getContainer();
|
|
12302
|
+
return document.getElementById("ajaxPackage-message");
|
|
12303
|
+
}
|
|
12243
12304
|
/**
|
|
12244
12305
|
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
12245
12306
|
* @param config - 请求配置对象
|
|
@@ -12323,7 +12384,8 @@ class BaseHttpClient {
|
|
|
12323
12384
|
var _a2, _b, _c;
|
|
12324
12385
|
if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
|
|
12325
12386
|
const fallbackError = error;
|
|
12326
|
-
(_c = this.messageInstance) == null ? void 0 : _c.
|
|
12387
|
+
(_c = this.messageInstance) == null ? void 0 : _c.call(this, {
|
|
12388
|
+
type: "error",
|
|
12327
12389
|
message: ((_b = fallbackError.response) == null ? void 0 : _b.data) || fallbackError.message || "网络错误",
|
|
12328
12390
|
duration: 5 * 1e3
|
|
12329
12391
|
});
|
|
@@ -12462,6 +12524,42 @@ class BaseHttpClient {
|
|
|
12462
12524
|
link.remove();
|
|
12463
12525
|
window.URL.revokeObjectURL(url);
|
|
12464
12526
|
}
|
|
12527
|
+
};
|
|
12528
|
+
/**
|
|
12529
|
+
* 检查是否在浏览器环境(在类初始化时判断)
|
|
12530
|
+
* 注意:这是静态属性,所有实例共享
|
|
12531
|
+
*/
|
|
12532
|
+
__publicField(_BaseHttpClient, "hasDocument", typeof document !== "undefined");
|
|
12533
|
+
let BaseHttpClient = _BaseHttpClient;
|
|
12534
|
+
async function copyToClipboard(text) {
|
|
12535
|
+
if (!text) {
|
|
12536
|
+
console.warn("复制文本为空");
|
|
12537
|
+
return false;
|
|
12538
|
+
}
|
|
12539
|
+
try {
|
|
12540
|
+
if (navigator.clipboard && navigator.clipboard.writeText) {
|
|
12541
|
+
await navigator.clipboard.writeText(text);
|
|
12542
|
+
return true;
|
|
12543
|
+
} else {
|
|
12544
|
+
const textArea = document.createElement("textarea");
|
|
12545
|
+
textArea.value = text;
|
|
12546
|
+
textArea.style.position = "fixed";
|
|
12547
|
+
textArea.style.left = "-999999px";
|
|
12548
|
+
textArea.style.top = "-999999px";
|
|
12549
|
+
document.body.appendChild(textArea);
|
|
12550
|
+
textArea.select();
|
|
12551
|
+
if (document.execCommand("copy")) {
|
|
12552
|
+
document.body.removeChild(textArea);
|
|
12553
|
+
return true;
|
|
12554
|
+
} else {
|
|
12555
|
+
document.body.removeChild(textArea);
|
|
12556
|
+
return false;
|
|
12557
|
+
}
|
|
12558
|
+
}
|
|
12559
|
+
} catch (error) {
|
|
12560
|
+
console.error("复制到剪贴板失败:", error);
|
|
12561
|
+
return false;
|
|
12562
|
+
}
|
|
12465
12563
|
}
|
|
12466
12564
|
async function dynamicImport(modulePromise, exportName = "default") {
|
|
12467
12565
|
const module = await modulePromise;
|
|
@@ -12483,7 +12581,7 @@ async function dynamicImports(modulePromise, exportNames) {
|
|
|
12483
12581
|
}
|
|
12484
12582
|
return result;
|
|
12485
12583
|
}
|
|
12486
|
-
function createApiDialog(DialogComponent) {
|
|
12584
|
+
function createApiDialog(DialogComponent, parentContainer) {
|
|
12487
12585
|
let container = null;
|
|
12488
12586
|
let vnode = null;
|
|
12489
12587
|
let isOpen = false;
|
|
@@ -12518,6 +12616,8 @@ function createApiDialog(DialogComponent) {
|
|
|
12518
12616
|
"modelValue": props.modelValue,
|
|
12519
12617
|
"title": props.title,
|
|
12520
12618
|
"width": props.width,
|
|
12619
|
+
// 如果提供了父容器,则挂载到父容器中
|
|
12620
|
+
"appendTo": parentContainer || void 0,
|
|
12521
12621
|
"onUpdate:modelValue": (val) => {
|
|
12522
12622
|
emit("update:modelValue", val);
|
|
12523
12623
|
if (!val) {
|
|
@@ -12545,7 +12645,8 @@ function createApiDialog(DialogComponent) {
|
|
|
12545
12645
|
const FinalDialogComponent = DialogComponent || DefaultDialog;
|
|
12546
12646
|
function createContainer() {
|
|
12547
12647
|
const el = document.createElement("div");
|
|
12548
|
-
document.body
|
|
12648
|
+
const mountTarget = parentContainer || document.body;
|
|
12649
|
+
mountTarget.appendChild(el);
|
|
12549
12650
|
return el;
|
|
12550
12651
|
}
|
|
12551
12652
|
function show(options = {}) {
|
|
@@ -12629,7 +12730,7 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12629
12730
|
const {
|
|
12630
12731
|
responseFields,
|
|
12631
12732
|
enableSystemErrorDialog = true,
|
|
12632
|
-
systemErrorMessage = "
|
|
12733
|
+
systemErrorMessage = "系统异常,点击看详情",
|
|
12633
12734
|
...baseConfig
|
|
12634
12735
|
} = config;
|
|
12635
12736
|
super(baseConfig);
|
|
@@ -12661,13 +12762,6 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12661
12762
|
this.systemErrorDialogInitPromise = this.initSystemErrorDialog();
|
|
12662
12763
|
}
|
|
12663
12764
|
}
|
|
12664
|
-
/**
|
|
12665
|
-
* 获取是否在浏览器环境(实例 getter)
|
|
12666
|
-
* @returns 是否在浏览器环境
|
|
12667
|
-
*/
|
|
12668
|
-
get hasDocument() {
|
|
12669
|
-
return _BaseApi.hasDocument;
|
|
12670
|
-
}
|
|
12671
12765
|
/**
|
|
12672
12766
|
* 获取系统错误信息存储(实例 getter)
|
|
12673
12767
|
* @returns 系统错误信息存储 Map
|
|
@@ -12748,7 +12842,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12748
12842
|
async initSystemErrorDialog() {
|
|
12749
12843
|
try {
|
|
12750
12844
|
const { default: SystemErrorDialog2 } = await dynamicImports(Promise.resolve().then(() => SystemErrorDialog$1), ["default"]);
|
|
12751
|
-
|
|
12845
|
+
const popoverContainer = this.getPopoverContainer();
|
|
12846
|
+
this.systemErrorDialogInstance = createApiDialog(SystemErrorDialog2, popoverContainer);
|
|
12752
12847
|
} catch (error) {
|
|
12753
12848
|
console.warn("Failed to load SystemErrorDialog:", error);
|
|
12754
12849
|
throw error;
|
|
@@ -12767,7 +12862,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12767
12862
|
const parsedFields = this.parseResponseFields(httpData);
|
|
12768
12863
|
const { code, message: message2, responseData } = parsedFields;
|
|
12769
12864
|
const config = response.config;
|
|
12770
|
-
const
|
|
12865
|
+
const messageConfigs = config == null ? void 0 : config.messageConfigs;
|
|
12866
|
+
const isCustomMessage = (messageConfigs == null ? void 0 : messageConfigs.isCustomMessage) ?? false;
|
|
12771
12867
|
this.handleSystemError(response, code, message2, responseData);
|
|
12772
12868
|
if (!isCustomMessage) {
|
|
12773
12869
|
this.handleBusinessError(code, message2);
|
|
@@ -12887,25 +12983,13 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12887
12983
|
})
|
|
12888
12984
|
])
|
|
12889
12985
|
]);
|
|
12890
|
-
(_a2 = this.messageInstance) == null ? void 0 : _a2.
|
|
12986
|
+
(_a2 = this.messageInstance) == null ? void 0 : _a2.call(this, {
|
|
12987
|
+
type: "error",
|
|
12891
12988
|
message: messageVNode,
|
|
12892
12989
|
duration: 5 * 1e3,
|
|
12893
12990
|
customClass: "system-error-message"
|
|
12894
12991
|
// 添加自定义类名
|
|
12895
12992
|
});
|
|
12896
|
-
if (typeof document !== "undefined") {
|
|
12897
|
-
let styleElement = document.getElementById("system-error-message-style");
|
|
12898
|
-
if (!styleElement) {
|
|
12899
|
-
styleElement = document.createElement("style");
|
|
12900
|
-
styleElement.id = "system-error-message-style";
|
|
12901
|
-
document.head.appendChild(styleElement);
|
|
12902
|
-
}
|
|
12903
|
-
styleElement.textContent = `
|
|
12904
|
-
.system-error-message {
|
|
12905
|
-
z-index: 99999998 !important;
|
|
12906
|
-
}
|
|
12907
|
-
`;
|
|
12908
|
-
}
|
|
12909
12993
|
}
|
|
12910
12994
|
/**
|
|
12911
12995
|
* 处理业务错误(其他非200错误码)
|
|
@@ -12916,7 +13000,8 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12916
13000
|
handleBusinessError(code, message2) {
|
|
12917
13001
|
var _a2;
|
|
12918
13002
|
if (code && code !== 200) {
|
|
12919
|
-
(_a2 = this.messageInstance) == null ? void 0 : _a2.
|
|
13003
|
+
(_a2 = this.messageInstance) == null ? void 0 : _a2.call(this, {
|
|
13004
|
+
type: "error",
|
|
12920
13005
|
message: message2 || "请求失败",
|
|
12921
13006
|
duration: 5 * 1e3
|
|
12922
13007
|
});
|
|
@@ -12930,33 +13015,33 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12930
13015
|
* @param response - Axios 响应对象
|
|
12931
13016
|
*/
|
|
12932
13017
|
handleErrorArray(httpData, response) {
|
|
12933
|
-
var _a2;
|
|
13018
|
+
var _a2, _b;
|
|
12934
13019
|
const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
|
|
12935
13020
|
if (errorsField) {
|
|
12936
13021
|
const errors = this.getValueByPath(httpData, errorsField);
|
|
12937
13022
|
if (Array.isArray(errors) && errors.length) {
|
|
12938
13023
|
const config = response.config;
|
|
12939
|
-
const notificationOptions = config == null ? void 0 : config.errorNotificationOptions;
|
|
12940
|
-
this.
|
|
13024
|
+
const notificationOptions = (_b = config == null ? void 0 : config.messageConfigs) == null ? void 0 : _b.errorNotificationOptions;
|
|
13025
|
+
this.showErrors(errors, notificationOptions);
|
|
12941
13026
|
throw new Error("请求错误");
|
|
12942
13027
|
}
|
|
12943
13028
|
}
|
|
12944
13029
|
}
|
|
12945
13030
|
/**
|
|
12946
|
-
*
|
|
12947
|
-
*
|
|
12948
|
-
*
|
|
12949
|
-
* @param
|
|
13031
|
+
* 显示错误信息(默认实现)
|
|
13032
|
+
* 使用 notification 显示错误信息
|
|
13033
|
+
* 子类可重写此方法来自定义错误信息显示方式
|
|
13034
|
+
* @param errors - 错误数组
|
|
12950
13035
|
* @param notificationOptions - 通知配置选项
|
|
12951
13036
|
*/
|
|
12952
|
-
|
|
13037
|
+
showErrors(errors, notificationOptions) {
|
|
12953
13038
|
var _a2, _b;
|
|
12954
13039
|
const defaultOptions = {
|
|
12955
13040
|
title: "提示",
|
|
12956
|
-
type
|
|
13041
|
+
type: "error"
|
|
12957
13042
|
};
|
|
12958
13043
|
if (this.hasDocument) {
|
|
12959
|
-
const html =
|
|
13044
|
+
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12960
13045
|
const finalOptions = {
|
|
12961
13046
|
...defaultOptions,
|
|
12962
13047
|
...notificationOptions,
|
|
@@ -12965,7 +13050,7 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12965
13050
|
};
|
|
12966
13051
|
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12967
13052
|
} else {
|
|
12968
|
-
const messages =
|
|
13053
|
+
const messages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12969
13054
|
const finalOptions = {
|
|
12970
13055
|
...defaultOptions,
|
|
12971
13056
|
...notificationOptions,
|
|
@@ -12974,15 +13059,6 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12974
13059
|
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12975
13060
|
}
|
|
12976
13061
|
}
|
|
12977
|
-
/**
|
|
12978
|
-
* 显示错误数组通知
|
|
12979
|
-
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
12980
|
-
* @param errors - 错误数组
|
|
12981
|
-
* @param notificationOptions - 通知配置选项
|
|
12982
|
-
*/
|
|
12983
|
-
showErrorArrayNotification(errors, notificationOptions) {
|
|
12984
|
-
this.showNotification(errors, "error", "red", notificationOptions);
|
|
12985
|
-
}
|
|
12986
13062
|
/**
|
|
12987
13063
|
* 处理提示信息 tips(如果有配置)
|
|
12988
13064
|
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
@@ -12990,25 +13066,41 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
12990
13066
|
* @param response - Axios 响应对象
|
|
12991
13067
|
*/
|
|
12992
13068
|
handleTips(httpData, response) {
|
|
12993
|
-
var _a2;
|
|
13069
|
+
var _a2, _b;
|
|
12994
13070
|
const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
|
|
12995
13071
|
if (tipsField) {
|
|
12996
13072
|
const tips = this.getValueByPath(httpData, tipsField);
|
|
12997
13073
|
if (Array.isArray(tips) && tips.length) {
|
|
12998
13074
|
const config = response.config;
|
|
12999
|
-
const
|
|
13000
|
-
this.
|
|
13075
|
+
const messageOptions = (_b = config == null ? void 0 : config.messageConfigs) == null ? void 0 : _b.tipsMessageOptions;
|
|
13076
|
+
this.showTips(tips, messageOptions);
|
|
13001
13077
|
}
|
|
13002
13078
|
}
|
|
13003
13079
|
}
|
|
13004
13080
|
/**
|
|
13005
|
-
*
|
|
13006
|
-
*
|
|
13081
|
+
* 显示提示信息(默认实现)
|
|
13082
|
+
* 根据 messageOptions.type 指定消息类型显示,提取所有 message 并连接
|
|
13083
|
+
* 子类可重写此方法来自定义提示信息显示方式
|
|
13007
13084
|
* @param tips - 提示信息数组
|
|
13008
|
-
* @param
|
|
13085
|
+
* @param messageOptions - 消息配置选项
|
|
13009
13086
|
*/
|
|
13010
|
-
|
|
13011
|
-
|
|
13087
|
+
showTips(tips, messageOptions) {
|
|
13088
|
+
const tipsMessage = tips.map((item) => item.message).join("");
|
|
13089
|
+
const defaultOptions = {
|
|
13090
|
+
type: "success",
|
|
13091
|
+
duration: 3e3,
|
|
13092
|
+
showClose: true,
|
|
13093
|
+
message: tipsMessage
|
|
13094
|
+
};
|
|
13095
|
+
const finalOptions = {
|
|
13096
|
+
...defaultOptions,
|
|
13097
|
+
...messageOptions,
|
|
13098
|
+
message: (messageOptions == null ? void 0 : messageOptions.message) ?? tipsMessage
|
|
13099
|
+
};
|
|
13100
|
+
const messageInstance = this.messageInstance;
|
|
13101
|
+
if (!messageInstance)
|
|
13102
|
+
return;
|
|
13103
|
+
messageInstance(finalOptions);
|
|
13012
13104
|
}
|
|
13013
13105
|
/**
|
|
13014
13106
|
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
@@ -13093,11 +13185,6 @@ const _BaseApi = class _BaseApi extends BaseHttpClient {
|
|
|
13093
13185
|
return super.downloadFile(blob, filename);
|
|
13094
13186
|
}
|
|
13095
13187
|
};
|
|
13096
|
-
/**
|
|
13097
|
-
* 检查是否在浏览器环境(在类初始化时判断)
|
|
13098
|
-
* 注意:这是静态属性,所有实例共享
|
|
13099
|
-
*/
|
|
13100
|
-
__publicField(_BaseApi, "hasDocument", typeof document !== "undefined");
|
|
13101
13188
|
/**
|
|
13102
13189
|
* 系统错误信息存储,用于在点击 icon 时打开详细错误弹窗
|
|
13103
13190
|
* key: 错误ID,value: 错误信息对象
|
|
@@ -13240,6 +13327,22 @@ const SystemErrorDialog = defineComponent({
|
|
|
13240
13327
|
function handleModelValueChange(val) {
|
|
13241
13328
|
emit("update:modelValue", val);
|
|
13242
13329
|
}
|
|
13330
|
+
function getAjaxPackageMessageContainer() {
|
|
13331
|
+
if (typeof document === "undefined")
|
|
13332
|
+
return null;
|
|
13333
|
+
return document.getElementById("ajaxPackage-message");
|
|
13334
|
+
}
|
|
13335
|
+
function getAjaxPackagePopoverContainer() {
|
|
13336
|
+
if (typeof document === "undefined")
|
|
13337
|
+
return null;
|
|
13338
|
+
return document.getElementById("ajaxPackage-popover");
|
|
13339
|
+
}
|
|
13340
|
+
function showMessage(options) {
|
|
13341
|
+
const container = getAjaxPackageMessageContainer();
|
|
13342
|
+
const { type = "info", message: message2 } = options;
|
|
13343
|
+
const finalOptions = container ? { type, message: message2, appendTo: container } : { type, message: message2 };
|
|
13344
|
+
ElMessage(finalOptions);
|
|
13345
|
+
}
|
|
13243
13346
|
async function handleReport() {
|
|
13244
13347
|
await baseApi.post("/upgGlobalExceptionReports", {
|
|
13245
13348
|
username: userInfo.value.userName,
|
|
@@ -13253,7 +13356,7 @@ const SystemErrorDialog = defineComponent({
|
|
|
13253
13356
|
menuUrl: currentUrl,
|
|
13254
13357
|
errorMessage: props.errorMessage
|
|
13255
13358
|
});
|
|
13256
|
-
|
|
13359
|
+
showMessage({ type: "success", message: "上报成功" });
|
|
13257
13360
|
handleClose();
|
|
13258
13361
|
}
|
|
13259
13362
|
function toggleTechSummary() {
|
|
@@ -13272,6 +13375,19 @@ const SystemErrorDialog = defineComponent({
|
|
|
13272
13375
|
const skyWalkingUrl = `${origin2}/middle/skywalking/trace/Trace?traceId=${encodeURIComponent(props.traceId)}`;
|
|
13273
13376
|
window.open(skyWalkingUrl, "_blank");
|
|
13274
13377
|
}
|
|
13378
|
+
async function handleCopyTraceId() {
|
|
13379
|
+
const traceId = props.traceId;
|
|
13380
|
+
if (!traceId) {
|
|
13381
|
+
showMessage({ type: "warning", message: "TraceId 不存在" });
|
|
13382
|
+
return;
|
|
13383
|
+
}
|
|
13384
|
+
const success = await copyToClipboard(traceId);
|
|
13385
|
+
if (success) {
|
|
13386
|
+
showMessage({ type: "success", message: "复制 traceId 成功" });
|
|
13387
|
+
} else {
|
|
13388
|
+
showMessage({ type: "error", message: "复制 traceId 失败" });
|
|
13389
|
+
}
|
|
13390
|
+
}
|
|
13275
13391
|
function close2() {
|
|
13276
13392
|
handleClose();
|
|
13277
13393
|
}
|
|
@@ -13282,6 +13398,7 @@ const SystemErrorDialog = defineComponent({
|
|
|
13282
13398
|
return typeof props.width === "number" ? `${props.width}px` : props.width;
|
|
13283
13399
|
});
|
|
13284
13400
|
return () => {
|
|
13401
|
+
const popoverContainer = getAjaxPackagePopoverContainer();
|
|
13285
13402
|
return h(
|
|
13286
13403
|
ElDialog,
|
|
13287
13404
|
{
|
|
@@ -13291,8 +13408,8 @@ const SystemErrorDialog = defineComponent({
|
|
|
13291
13408
|
"showClose": true,
|
|
13292
13409
|
"closeOnClickModal": false,
|
|
13293
13410
|
"closeOnPressEscape": false,
|
|
13294
|
-
"zIndex": 99999999,
|
|
13295
13411
|
"style": { padding: "16px 0" },
|
|
13412
|
+
"appendTo": popoverContainer || void 0,
|
|
13296
13413
|
"onUpdate:modelValue": handleModelValueChange
|
|
13297
13414
|
},
|
|
13298
13415
|
{
|
|
@@ -13381,7 +13498,20 @@ const SystemErrorDialog = defineComponent({
|
|
|
13381
13498
|
)
|
|
13382
13499
|
]),
|
|
13383
13500
|
// 黑色错误信息区域
|
|
13384
|
-
h("div", {
|
|
13501
|
+
h("div", {
|
|
13502
|
+
style: {
|
|
13503
|
+
backgroundColor: "#2c3e50",
|
|
13504
|
+
color: "#fff",
|
|
13505
|
+
padding: "16px 20px",
|
|
13506
|
+
fontFamily: 'Monaco, Consolas, "Courier New", monospace',
|
|
13507
|
+
fontSize: "12px",
|
|
13508
|
+
lineHeight: 1.5,
|
|
13509
|
+
maxHeight: "200px",
|
|
13510
|
+
overflowY: "auto",
|
|
13511
|
+
cursor: "pointer"
|
|
13512
|
+
},
|
|
13513
|
+
onClick: handleCopyTraceId
|
|
13514
|
+
}, [
|
|
13385
13515
|
h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
|
|
13386
13516
|
h("div", { style: { color: "#e74c3c", fontWeight: "bold", whiteSpace: "pre-wrap" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
|
|
13387
13517
|
])
|