@moluoxixi/ajax-package 0.0.16 → 0.0.17
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 +31 -0
- package/es/SystemErrorDialog.d.ts +125 -0
- package/es/_types/api.d.ts +82 -0
- package/es/_types/emits.d.ts +6 -0
- package/es/_types/index.d.ts +4 -0
- package/es/_types/props.d.ts +13 -0
- package/es/_utils/index.d.ts +3 -0
- package/es/_utils/messageWrapper.d.ts +35 -0
- package/es/_utils/notificationWrapper.d.ts +8 -0
- package/es/_utils/systemErrorInfo.d.ts +6 -0
- package/es/class.d.ts +44 -0
- package/es/index.d.ts +6 -0
- package/es/index.mjs +73 -327
- package/es/netseriver.d.ts +12 -0
- package/es/test/service.d.ts +40 -0
- package/package.json +1 -1
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, default as axios } from 'axios';
|
|
2
|
+
import { BaseHttpClientConfig } from './_types/index.ts';
|
|
3
|
+
import { MessageInstance, NotificationInstance } from './_utils/index.ts';
|
|
4
|
+
export default class BaseHttpClient {
|
|
5
|
+
protected baseURL: string;
|
|
6
|
+
protected timeout: number;
|
|
7
|
+
protected onTimeout: (messageInstance: MessageInstance) => void;
|
|
8
|
+
protected getToken?: () => string | null;
|
|
9
|
+
protected onLoginRequired?: (messageInstance: MessageInstance) => void;
|
|
10
|
+
instance: ReturnType<typeof axios.create>;
|
|
11
|
+
protected messageInstance: MessageInstance;
|
|
12
|
+
protected notificationInstance: NotificationInstance;
|
|
13
|
+
constructor(config: BaseHttpClientConfig);
|
|
14
|
+
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
|
|
15
|
+
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
16
|
+
protected handleHttpStatus(response: AxiosResponse): void;
|
|
17
|
+
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
18
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
19
|
+
protected handleAuthenticationError(error: AxiosError): void;
|
|
20
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
21
|
+
protected handleNetworkError(error: AxiosError): void;
|
|
22
|
+
private setupInterceptors;
|
|
23
|
+
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
24
|
+
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
25
|
+
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
26
|
+
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
27
|
+
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
28
|
+
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
29
|
+
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
30
|
+
downloadFile(blob: Blob, filename?: string): void;
|
|
31
|
+
}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
2
|
+
title: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
default: string;
|
|
5
|
+
};
|
|
6
|
+
width: {
|
|
7
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
8
|
+
default: number;
|
|
9
|
+
};
|
|
10
|
+
userName: {
|
|
11
|
+
type: StringConstructor;
|
|
12
|
+
default: undefined;
|
|
13
|
+
};
|
|
14
|
+
userId: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
default: undefined;
|
|
17
|
+
};
|
|
18
|
+
deptName: {
|
|
19
|
+
type: StringConstructor;
|
|
20
|
+
default: undefined;
|
|
21
|
+
};
|
|
22
|
+
deptId: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
clientIp: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
requestUrl: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
default: undefined;
|
|
33
|
+
};
|
|
34
|
+
traceId: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
errorMessage: {
|
|
39
|
+
type: StringConstructor;
|
|
40
|
+
default: undefined;
|
|
41
|
+
};
|
|
42
|
+
errorCode: {
|
|
43
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
44
|
+
default: undefined;
|
|
45
|
+
};
|
|
46
|
+
modelValue: {
|
|
47
|
+
type: BooleanConstructor;
|
|
48
|
+
default: boolean;
|
|
49
|
+
};
|
|
50
|
+
}>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
}>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
53
|
+
'update:modelValue': (val: boolean) => true;
|
|
54
|
+
close: () => true;
|
|
55
|
+
confirm: (data: any) => true;
|
|
56
|
+
report: () => true;
|
|
57
|
+
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
58
|
+
title: {
|
|
59
|
+
type: StringConstructor;
|
|
60
|
+
default: string;
|
|
61
|
+
};
|
|
62
|
+
width: {
|
|
63
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
64
|
+
default: number;
|
|
65
|
+
};
|
|
66
|
+
userName: {
|
|
67
|
+
type: StringConstructor;
|
|
68
|
+
default: undefined;
|
|
69
|
+
};
|
|
70
|
+
userId: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
default: undefined;
|
|
73
|
+
};
|
|
74
|
+
deptName: {
|
|
75
|
+
type: StringConstructor;
|
|
76
|
+
default: undefined;
|
|
77
|
+
};
|
|
78
|
+
deptId: {
|
|
79
|
+
type: StringConstructor;
|
|
80
|
+
default: undefined;
|
|
81
|
+
};
|
|
82
|
+
clientIp: {
|
|
83
|
+
type: StringConstructor;
|
|
84
|
+
default: undefined;
|
|
85
|
+
};
|
|
86
|
+
requestUrl: {
|
|
87
|
+
type: StringConstructor;
|
|
88
|
+
default: undefined;
|
|
89
|
+
};
|
|
90
|
+
traceId: {
|
|
91
|
+
type: StringConstructor;
|
|
92
|
+
default: undefined;
|
|
93
|
+
};
|
|
94
|
+
errorMessage: {
|
|
95
|
+
type: StringConstructor;
|
|
96
|
+
default: undefined;
|
|
97
|
+
};
|
|
98
|
+
errorCode: {
|
|
99
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
100
|
+
default: undefined;
|
|
101
|
+
};
|
|
102
|
+
modelValue: {
|
|
103
|
+
type: BooleanConstructor;
|
|
104
|
+
default: boolean;
|
|
105
|
+
};
|
|
106
|
+
}>> & Readonly<{
|
|
107
|
+
onClose?: (() => any) | undefined;
|
|
108
|
+
onConfirm?: ((data: any) => any) | undefined;
|
|
109
|
+
"onUpdate:modelValue"?: ((val: boolean) => any) | undefined;
|
|
110
|
+
onReport?: (() => any) | undefined;
|
|
111
|
+
}>, {
|
|
112
|
+
title: string;
|
|
113
|
+
width: string | number;
|
|
114
|
+
userName: string;
|
|
115
|
+
userId: string;
|
|
116
|
+
deptName: string;
|
|
117
|
+
deptId: string;
|
|
118
|
+
clientIp: string;
|
|
119
|
+
requestUrl: string;
|
|
120
|
+
traceId: string;
|
|
121
|
+
errorMessage: string;
|
|
122
|
+
errorCode: string | number;
|
|
123
|
+
modelValue: boolean;
|
|
124
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
125
|
+
export default _default;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { App } from 'vue';
|
|
3
|
+
import { MessageInstance } from '../_utils/index.ts';
|
|
4
|
+
import { default as BaseApi } from '../class.ts';
|
|
5
|
+
export interface BaseHttpClientConfig {
|
|
6
|
+
baseURL?: string;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
onTimeout?: (messageInstance: MessageInstance) => void;
|
|
9
|
+
getToken?: () => string | null;
|
|
10
|
+
onLoginRequired?: (messageInstance: MessageInstance) => void;
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}
|
|
13
|
+
export interface BaseApiConfig extends BaseHttpClientConfig {
|
|
14
|
+
responseFields?: {
|
|
15
|
+
code?: string;
|
|
16
|
+
message?: string;
|
|
17
|
+
data?: string;
|
|
18
|
+
errors?: string;
|
|
19
|
+
tips?: string;
|
|
20
|
+
};
|
|
21
|
+
enableSystemErrorDialog?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface vueAxiosPluginOptionsType {
|
|
24
|
+
default?: BaseApiConfig;
|
|
25
|
+
globalMixin?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type vueHttpServiceType = BaseApi;
|
|
28
|
+
export interface vueAxiosPluginType {
|
|
29
|
+
install: (app: App, options?: vueAxiosPluginOptionsType) => void;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 通知配置选项
|
|
33
|
+
*/
|
|
34
|
+
export interface NotificationOptions {
|
|
35
|
+
/**
|
|
36
|
+
* 通知标题
|
|
37
|
+
*/
|
|
38
|
+
title?: string;
|
|
39
|
+
/**
|
|
40
|
+
* 通知类型
|
|
41
|
+
*/
|
|
42
|
+
type?: 'success' | 'error' | 'warning' | 'info';
|
|
43
|
+
/**
|
|
44
|
+
* 通知持续时间(毫秒)
|
|
45
|
+
*/
|
|
46
|
+
duration?: number;
|
|
47
|
+
/**
|
|
48
|
+
* 是否显示关闭按钮
|
|
49
|
+
*/
|
|
50
|
+
showClose?: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* 自定义类名
|
|
53
|
+
*/
|
|
54
|
+
customClass?: string;
|
|
55
|
+
/**
|
|
56
|
+
* 自定义样式
|
|
57
|
+
*/
|
|
58
|
+
customStyle?: string | Record<string, any>;
|
|
59
|
+
/**
|
|
60
|
+
* 其他通知选项
|
|
61
|
+
*/
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* 扩展 AxiosRequestConfig,支持自定义通知配置
|
|
66
|
+
*/
|
|
67
|
+
export interface ExtendedAxiosRequestConfig extends AxiosRequestConfig {
|
|
68
|
+
/**
|
|
69
|
+
* 错误通知配置选项,用于覆盖默认的错误通知参数
|
|
70
|
+
*/
|
|
71
|
+
errorNotificationOptions?: NotificationOptions;
|
|
72
|
+
/**
|
|
73
|
+
* 提示通知配置选项,用于覆盖默认的提示通知参数
|
|
74
|
+
*/
|
|
75
|
+
tipsNotificationOptions?: NotificationOptions;
|
|
76
|
+
/**
|
|
77
|
+
* 是否使用自定义消息处理
|
|
78
|
+
* 当为 true 时,handleBusinessError、handleErrorArray、handleTips 都不会执行
|
|
79
|
+
* 默认值为 false
|
|
80
|
+
*/
|
|
81
|
+
isCustomMessage?: boolean;
|
|
82
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface SystemErrorDialogPropsType {
|
|
2
|
+
title?: string;
|
|
3
|
+
width?: number | string;
|
|
4
|
+
userName?: string;
|
|
5
|
+
userId?: string;
|
|
6
|
+
deptName?: string;
|
|
7
|
+
deptId?: string;
|
|
8
|
+
clientIp?: string;
|
|
9
|
+
requestUrl?: string;
|
|
10
|
+
traceId?: string;
|
|
11
|
+
errorMessage?: string;
|
|
12
|
+
errorCode?: number | string;
|
|
13
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare function createMessageWrapper(): (import('element-plus').MessageFn & {
|
|
2
|
+
primary: import('element-plus').MessageTypedFn;
|
|
3
|
+
success: import('element-plus').MessageTypedFn;
|
|
4
|
+
warning: import('element-plus').MessageTypedFn;
|
|
5
|
+
info: import('element-plus').MessageTypedFn;
|
|
6
|
+
error: import('element-plus').MessageTypedFn;
|
|
7
|
+
} & import('vue').ObjectPlugin<any[]> & {
|
|
8
|
+
_context: import('vue').AppContext | null;
|
|
9
|
+
}) | (import('element-plus').MessageFn & {
|
|
10
|
+
primary: import('element-plus').MessageTypedFn;
|
|
11
|
+
success: import('element-plus').MessageTypedFn;
|
|
12
|
+
warning: import('element-plus').MessageTypedFn;
|
|
13
|
+
info: import('element-plus').MessageTypedFn;
|
|
14
|
+
error: import('element-plus').MessageTypedFn;
|
|
15
|
+
} & ((app: import('vue').App, ...options: any[]) => any) & Partial<import('vue').ObjectPlugin<any[]>> & {
|
|
16
|
+
_context: import('vue').AppContext | null;
|
|
17
|
+
}) | {
|
|
18
|
+
success: (options: string | {
|
|
19
|
+
message?: string;
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}) => void;
|
|
22
|
+
error: (options: string | {
|
|
23
|
+
message?: string;
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
}) => void;
|
|
26
|
+
warning: (options: string | {
|
|
27
|
+
message?: string;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
}) => void;
|
|
30
|
+
info: (options: string | {
|
|
31
|
+
message?: string;
|
|
32
|
+
[key: string]: any;
|
|
33
|
+
}) => void;
|
|
34
|
+
};
|
|
35
|
+
export type MessageInstance = ReturnType<typeof createMessageWrapper>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
|
|
2
|
+
_context: import('vue').AppContext | null;
|
|
3
|
+
}) | ((options: string | {
|
|
4
|
+
message?: string;
|
|
5
|
+
title?: string;
|
|
6
|
+
type?: "success" | "error" | "warning" | "info";
|
|
7
|
+
}) => void);
|
|
8
|
+
export type NotificationInstance = ReturnType<typeof createNotificationWrapper>;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { SystemErrorDialogPropsType } from '../_types/index.ts';
|
|
3
|
+
export declare function normalizePayload(payload: any): Record<string, any>;
|
|
4
|
+
export declare function resolveTraceId(headers: AxiosResponse['headers'] | undefined): string;
|
|
5
|
+
export declare function getUserInfoFromLocalStorage(): Record<string, any>;
|
|
6
|
+
export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
|
package/es/class.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { BaseApiConfig, ExtendedAxiosRequestConfig, NotificationOptions } from './_types/index.ts';
|
|
3
|
+
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
4
|
+
export default class BaseApi extends BaseHttpClient {
|
|
5
|
+
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
6
|
+
protected enableSystemErrorDialog: boolean;
|
|
7
|
+
constructor(config: BaseApiConfig);
|
|
8
|
+
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
9
|
+
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
10
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
11
|
+
protected handleHttpStatus(response: AxiosResponse): void;
|
|
12
|
+
protected handleAuthenticationError(error: AxiosError): void;
|
|
13
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
14
|
+
protected handleNetworkError(error: AxiosError): void;
|
|
15
|
+
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
16
|
+
protected getValueByPath(obj: any, path: string | undefined): any;
|
|
17
|
+
protected parseResponseFields(data: any): {
|
|
18
|
+
code: any;
|
|
19
|
+
message: any;
|
|
20
|
+
responseData: any;
|
|
21
|
+
};
|
|
22
|
+
protected handleSystemError(response: AxiosResponse, code: any, message: any, responseData: any): void;
|
|
23
|
+
protected handleBusinessError(code: any, message: any, response: AxiosResponse): void;
|
|
24
|
+
protected handleErrorArray(httpData: any, response: AxiosResponse): void;
|
|
25
|
+
protected showErrorArrayNotification(errors: Array<{
|
|
26
|
+
code: string;
|
|
27
|
+
message: string;
|
|
28
|
+
}>, notificationOptions?: NotificationOptions): void;
|
|
29
|
+
protected handleTips(httpData: any, response: AxiosResponse): void;
|
|
30
|
+
protected showTipsNotification(tips: Array<{
|
|
31
|
+
code: string;
|
|
32
|
+
message: string;
|
|
33
|
+
}>, notificationOptions?: NotificationOptions): void;
|
|
34
|
+
private showSystemExceptionDialog;
|
|
35
|
+
protected reportError(errorInfo: any): Promise<void>;
|
|
36
|
+
protected request<R>(config: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
37
|
+
get<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
38
|
+
post<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
39
|
+
delete<R>(url: string, params?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
40
|
+
put<R>(url: string, data?: Record<string, any>, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
41
|
+
all<R>(requests: Array<ExtendedAxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
42
|
+
uploadFile<R>(url: string, file: File | Blob, config?: ExtendedAxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
43
|
+
downloadFile(blob: Blob, filename?: string): void;
|
|
44
|
+
}
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
2
|
+
import { default as BaseApi } from './class.ts';
|
|
3
|
+
import { default as VueAxiosPlugin, createHttpService, getHttpService } from './netseriver.ts';
|
|
4
|
+
export { BaseApi, BaseHttpClient, createHttpService, getHttpService, VueAxiosPlugin, };
|
|
5
|
+
export type { BaseApiConfig, BaseHttpClientConfig, vueAxiosPluginOptionsType, vueAxiosPluginType, vueHttpServiceType, } from './_types/index.ts';
|
|
6
|
+
export default getHttpService;
|
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("75b05bee-ad6e-4470-b902-2118b507f825")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "75b05bee-ad6e-4470-b902-2118b507f825";
|
|
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
|
}
|
|
@@ -12183,10 +12183,6 @@ function defaultGetToken() {
|
|
|
12183
12183
|
return typeof localStorage !== "undefined" ? localStorage.getItem("token") || "" : "";
|
|
12184
12184
|
}
|
|
12185
12185
|
class BaseHttpClient {
|
|
12186
|
-
/**
|
|
12187
|
-
* 创建 BaseHttpClient 实例
|
|
12188
|
-
* @param config - HTTP 客户端配置对象
|
|
12189
|
-
*/
|
|
12190
12186
|
constructor(config) {
|
|
12191
12187
|
__publicField(this, "baseURL", "");
|
|
12192
12188
|
__publicField(this, "timeout", 5e3);
|
|
@@ -12216,86 +12212,42 @@ class BaseHttpClient {
|
|
|
12216
12212
|
baseURL: this.baseURL,
|
|
12217
12213
|
timeout: this.timeout,
|
|
12218
12214
|
...axiosConfig
|
|
12219
|
-
// 将所有剩余参数传给axios.create
|
|
12220
12215
|
});
|
|
12221
12216
|
this.setupInterceptors();
|
|
12222
12217
|
}
|
|
12223
|
-
/**
|
|
12224
|
-
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
12225
|
-
* @param config - 请求配置对象
|
|
12226
|
-
* @returns 处理后的请求配置
|
|
12227
|
-
*/
|
|
12228
12218
|
processRequestConfig(config) {
|
|
12229
12219
|
return config;
|
|
12230
12220
|
}
|
|
12231
|
-
/**
|
|
12232
|
-
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
12233
|
-
* 按照标准 HTTP 结构处理响应
|
|
12234
|
-
* @param response - Axios 响应对象
|
|
12235
|
-
* @returns 解析后的响应数据
|
|
12236
|
-
*/
|
|
12237
12221
|
processResponseConfig(response) {
|
|
12238
12222
|
this.handleHttpStatus(response);
|
|
12239
12223
|
return this.handleSuccessResponse(response);
|
|
12240
12224
|
}
|
|
12241
|
-
/**
|
|
12242
|
-
* 处理 HTTP 状态码
|
|
12243
|
-
* 子类可重写此方法来自定义 HTTP 状态码处理逻辑
|
|
12244
|
-
* @param response - Axios 响应对象
|
|
12245
|
-
*/
|
|
12246
12225
|
handleHttpStatus(response) {
|
|
12247
12226
|
var _a2;
|
|
12248
12227
|
if (response.status !== 200) {
|
|
12249
12228
|
throw new Error(((_a2 = response.data) == null ? void 0 : _a2.message) || `HTTP Error: ${response.status}`);
|
|
12250
12229
|
}
|
|
12251
12230
|
}
|
|
12252
|
-
/**
|
|
12253
|
-
* 处理成功响应
|
|
12254
|
-
* 子类可重写此方法来自定义成功响应的处理逻辑
|
|
12255
|
-
* @param response - Axios 响应对象
|
|
12256
|
-
* @returns 解析后的响应数据
|
|
12257
|
-
*/
|
|
12258
12231
|
handleSuccessResponse(response) {
|
|
12259
12232
|
return response.data;
|
|
12260
12233
|
}
|
|
12261
|
-
/**
|
|
12262
|
-
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
12263
|
-
* 按照标准 HTTP 错误结构处理错误
|
|
12264
|
-
* @param error - Axios 错误对象
|
|
12265
|
-
* @returns 处理后的错误对象
|
|
12266
|
-
*/
|
|
12267
12234
|
async processResponseError(error) {
|
|
12268
12235
|
this.handleAuthenticationError(error);
|
|
12269
12236
|
this.handleTimeoutError(error);
|
|
12270
12237
|
this.handleNetworkError(error);
|
|
12271
12238
|
return error;
|
|
12272
12239
|
}
|
|
12273
|
-
/**
|
|
12274
|
-
* 处理认证错误(401 - 未授权/登录失效)
|
|
12275
|
-
* 子类可重写此方法来自定义认证错误处理逻辑
|
|
12276
|
-
* @param error - Axios 错误对象
|
|
12277
|
-
*/
|
|
12278
12240
|
handleAuthenticationError(error) {
|
|
12279
12241
|
var _a2, _b;
|
|
12280
12242
|
if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
|
|
12281
12243
|
(_b = this.onLoginRequired) == null ? void 0 : _b.call(this, this.messageInstance);
|
|
12282
12244
|
}
|
|
12283
12245
|
}
|
|
12284
|
-
/**
|
|
12285
|
-
* 处理超时错误
|
|
12286
|
-
* 子类可重写此方法来自定义超时错误处理逻辑
|
|
12287
|
-
* @param error - Axios 错误对象
|
|
12288
|
-
*/
|
|
12289
12246
|
handleTimeoutError(error) {
|
|
12290
12247
|
if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
|
|
12291
12248
|
this.onTimeout(this.messageInstance);
|
|
12292
12249
|
}
|
|
12293
12250
|
}
|
|
12294
|
-
/**
|
|
12295
|
-
* 处理网络错误(其他错误)
|
|
12296
|
-
* 子类可重写此方法来自定义网络错误处理逻辑
|
|
12297
|
-
* @param error - Axios 错误对象
|
|
12298
|
-
*/
|
|
12299
12251
|
handleNetworkError(error) {
|
|
12300
12252
|
var _a2, _b, _c;
|
|
12301
12253
|
if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
|
|
@@ -12306,11 +12258,6 @@ class BaseHttpClient {
|
|
|
12306
12258
|
});
|
|
12307
12259
|
}
|
|
12308
12260
|
}
|
|
12309
|
-
/**
|
|
12310
|
-
* 设置请求和响应拦截器
|
|
12311
|
-
* 请求拦截器:自动添加 Token
|
|
12312
|
-
* 响应拦截器:处理成功响应和错误响应(401、超时等)
|
|
12313
|
-
*/
|
|
12314
12261
|
setupInterceptors() {
|
|
12315
12262
|
this.instance.interceptors.request.use(
|
|
12316
12263
|
(config) => {
|
|
@@ -12337,59 +12284,21 @@ class BaseHttpClient {
|
|
|
12337
12284
|
}
|
|
12338
12285
|
);
|
|
12339
12286
|
}
|
|
12340
|
-
/**
|
|
12341
|
-
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
12342
|
-
* @param config - Axios 请求配置对象
|
|
12343
|
-
* @returns 解析后的响应数据
|
|
12344
|
-
*/
|
|
12345
12287
|
async request(config) {
|
|
12346
12288
|
return this.instance.request(config);
|
|
12347
12289
|
}
|
|
12348
|
-
/**
|
|
12349
|
-
* 发送 GET 请求
|
|
12350
|
-
* @param url - 请求 URL 路径
|
|
12351
|
-
* @param params - 查询参数对象
|
|
12352
|
-
* @param config - 额外的请求配置
|
|
12353
|
-
* @returns 解析后的响应数据
|
|
12354
|
-
*/
|
|
12355
12290
|
async get(url, params, config) {
|
|
12356
12291
|
return this.request({ ...config, url, method: "get", params });
|
|
12357
12292
|
}
|
|
12358
|
-
/**
|
|
12359
|
-
* 发送 POST 请求
|
|
12360
|
-
* @param url - 请求 URL 路径
|
|
12361
|
-
* @param data - 请求体数据
|
|
12362
|
-
* @param config - 额外的请求配置
|
|
12363
|
-
* @returns 解析后的响应数据
|
|
12364
|
-
*/
|
|
12365
12293
|
async post(url, data, config) {
|
|
12366
12294
|
return this.request({ ...config, url, method: "post", data });
|
|
12367
12295
|
}
|
|
12368
|
-
/**
|
|
12369
|
-
* 发送 DELETE 请求
|
|
12370
|
-
* @param url - 请求 URL 路径
|
|
12371
|
-
* @param params - 查询参数对象
|
|
12372
|
-
* @param config - 额外的请求配置
|
|
12373
|
-
* @returns 解析后的响应数据
|
|
12374
|
-
*/
|
|
12375
12296
|
async delete(url, params, config) {
|
|
12376
12297
|
return this.request({ ...config, url, method: "delete", params });
|
|
12377
12298
|
}
|
|
12378
|
-
/**
|
|
12379
|
-
* 发送 PUT 请求
|
|
12380
|
-
* @param url - 请求 URL 路径
|
|
12381
|
-
* @param data - 请求体数据
|
|
12382
|
-
* @param config - 额外的请求配置
|
|
12383
|
-
* @returns 解析后的响应数据
|
|
12384
|
-
*/
|
|
12385
12299
|
async put(url, data, config) {
|
|
12386
12300
|
return this.request({ ...config, url, method: "put", data });
|
|
12387
12301
|
}
|
|
12388
|
-
/**
|
|
12389
|
-
* 批量请求,并发发送多个请求
|
|
12390
|
-
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
12391
|
-
* @returns 所有请求的响应数据数组
|
|
12392
|
-
*/
|
|
12393
12302
|
async all(requests) {
|
|
12394
12303
|
if (!requests.length)
|
|
12395
12304
|
return [];
|
|
@@ -12402,13 +12311,6 @@ class BaseHttpClient {
|
|
|
12402
12311
|
const promises = requests.map((config) => this.request(config));
|
|
12403
12312
|
return await Promise.all(promises);
|
|
12404
12313
|
}
|
|
12405
|
-
/**
|
|
12406
|
-
* 文件上传,将文件包装为 FormData 发送
|
|
12407
|
-
* @param url - 上传地址
|
|
12408
|
-
* @param file - 文件对象
|
|
12409
|
-
* @param config - 额外的请求配置
|
|
12410
|
-
* @returns 解析后的响应数据
|
|
12411
|
-
*/
|
|
12412
12314
|
async uploadFile(url, file, config) {
|
|
12413
12315
|
const formData = new FormData();
|
|
12414
12316
|
formData.append("file", file);
|
|
@@ -12420,11 +12322,6 @@ class BaseHttpClient {
|
|
|
12420
12322
|
}
|
|
12421
12323
|
});
|
|
12422
12324
|
}
|
|
12423
|
-
/**
|
|
12424
|
-
* 下载文件,将 Blob 对象下载到本地
|
|
12425
|
-
* @param blob - Blob 对象
|
|
12426
|
-
* @param filename - 文件名,如果不提供则使用时间戳
|
|
12427
|
-
*/
|
|
12428
12325
|
downloadFile(blob, filename) {
|
|
12429
12326
|
if (typeof window === "undefined") {
|
|
12430
12327
|
console.warn("downloadFile: 非浏览器环境,无法下载文件");
|
|
@@ -12540,12 +12437,10 @@ function createApiDialog(DialogComponent) {
|
|
|
12540
12437
|
cleanup();
|
|
12541
12438
|
}
|
|
12542
12439
|
},
|
|
12543
|
-
// 监听关闭事件
|
|
12544
12440
|
onClose: () => {
|
|
12545
12441
|
reject(new Error("对话框已关闭"));
|
|
12546
12442
|
cleanup();
|
|
12547
12443
|
},
|
|
12548
|
-
// 监听确认事件(如有)
|
|
12549
12444
|
onConfirm: (data) => {
|
|
12550
12445
|
resolve(data);
|
|
12551
12446
|
cleanup();
|
|
@@ -12596,10 +12491,6 @@ function createApiDialog(DialogComponent) {
|
|
|
12596
12491
|
const hasDocument = typeof document !== "undefined";
|
|
12597
12492
|
let systemErrorDialogInstance = null;
|
|
12598
12493
|
class BaseApi extends BaseHttpClient {
|
|
12599
|
-
/**
|
|
12600
|
-
* 创建 BaseApi 实例
|
|
12601
|
-
* @param config - API 配置对象
|
|
12602
|
-
*/
|
|
12603
12494
|
constructor(config) {
|
|
12604
12495
|
const {
|
|
12605
12496
|
responseFields,
|
|
@@ -12613,125 +12504,68 @@ class BaseApi extends BaseHttpClient {
|
|
|
12613
12504
|
code: "Code",
|
|
12614
12505
|
message: "Message",
|
|
12615
12506
|
data: "data",
|
|
12616
|
-
errors: "errors",
|
|
12617
|
-
tips: "tips",
|
|
12507
|
+
errors: "data.errors",
|
|
12508
|
+
tips: "data.tips",
|
|
12618
12509
|
...responseFields
|
|
12619
12510
|
};
|
|
12620
12511
|
this.enableSystemErrorDialog = enableSystemErrorDialog;
|
|
12621
12512
|
}
|
|
12622
|
-
/**
|
|
12623
|
-
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
12624
|
-
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12625
|
-
* @param config - 请求配置对象
|
|
12626
|
-
* @returns 处理后的请求配置
|
|
12627
|
-
*/
|
|
12628
12513
|
processRequestConfig(config) {
|
|
12629
12514
|
return super.processRequestConfig(config);
|
|
12630
12515
|
}
|
|
12631
|
-
/**
|
|
12632
|
-
* 处理响应配置,子类可重写此方法自定义响应处理
|
|
12633
|
-
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12634
|
-
* @param response - Axios 响应对象
|
|
12635
|
-
* @returns 解析后的响应数据
|
|
12636
|
-
*/
|
|
12637
12516
|
processResponseConfig(response) {
|
|
12638
12517
|
return super.processResponseConfig(response);
|
|
12639
12518
|
}
|
|
12640
|
-
/**
|
|
12641
|
-
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
12642
|
-
* 显式声明以确保类型一致性,避免打包后的类型不兼容问题
|
|
12643
|
-
* @param error - Axios 错误对象
|
|
12644
|
-
* @returns 处理后的错误对象
|
|
12645
|
-
*/
|
|
12646
12519
|
async processResponseError(error) {
|
|
12647
12520
|
return super.processResponseError(error);
|
|
12648
12521
|
}
|
|
12649
|
-
/**
|
|
12650
|
-
* 处理 HTTP 状态码
|
|
12651
|
-
* 重写父类方法,确保子类可以重写此方法
|
|
12652
|
-
* @param response - Axios 响应对象
|
|
12653
|
-
*/
|
|
12654
12522
|
handleHttpStatus(response) {
|
|
12655
12523
|
return super.handleHttpStatus(response);
|
|
12656
12524
|
}
|
|
12657
|
-
/**
|
|
12658
|
-
* 处理认证错误(401 - 未授权/登录失效)
|
|
12659
|
-
* 重写父类方法,处理 HTTP 401 错误
|
|
12660
|
-
* 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
|
|
12661
|
-
* @param error - Axios 错误对象
|
|
12662
|
-
*/
|
|
12663
12525
|
handleAuthenticationError(error) {
|
|
12664
12526
|
super.handleAuthenticationError(error);
|
|
12665
12527
|
}
|
|
12666
|
-
/**
|
|
12667
|
-
* 处理超时错误
|
|
12668
|
-
* 重写父类方法,确保子类可以重写此方法
|
|
12669
|
-
* @param error - Axios 错误对象
|
|
12670
|
-
*/
|
|
12671
12528
|
handleTimeoutError(error) {
|
|
12672
12529
|
return super.handleTimeoutError(error);
|
|
12673
12530
|
}
|
|
12674
|
-
/**
|
|
12675
|
-
* 处理网络错误(其他错误)
|
|
12676
|
-
* 重写父类方法,确保子类可以重写此方法
|
|
12677
|
-
* @param error - Axios 错误对象
|
|
12678
|
-
*/
|
|
12679
12531
|
handleNetworkError(error) {
|
|
12680
12532
|
return super.handleNetworkError(error);
|
|
12681
12533
|
}
|
|
12682
|
-
/**
|
|
12683
|
-
* 处理成功响应
|
|
12684
|
-
* 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
|
|
12685
|
-
* 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
|
|
12686
|
-
* 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
|
|
12687
|
-
* @param response - Axios 响应对象
|
|
12688
|
-
* @returns 解析后的响应数据
|
|
12689
|
-
*/
|
|
12690
12534
|
handleSuccessResponse(response) {
|
|
12691
12535
|
const httpData = super.handleSuccessResponse(response);
|
|
12692
12536
|
const parsedFields = this.parseResponseFields(httpData);
|
|
12693
12537
|
const { code, message: message2, responseData } = parsedFields;
|
|
12538
|
+
const config = response.config;
|
|
12539
|
+
const isCustomMessage = (config == null ? void 0 : config.isCustomMessage) ?? false;
|
|
12694
12540
|
this.handleSystemError(response, code, message2, responseData);
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12541
|
+
if (!isCustomMessage) {
|
|
12542
|
+
this.handleBusinessError(code, message2, response);
|
|
12543
|
+
this.handleErrorArray(httpData, response);
|
|
12544
|
+
this.handleTips(httpData, response);
|
|
12545
|
+
}
|
|
12698
12546
|
return responseData;
|
|
12699
12547
|
}
|
|
12700
|
-
|
|
12701
|
-
|
|
12702
|
-
|
|
12703
|
-
|
|
12704
|
-
|
|
12705
|
-
|
|
12548
|
+
getValueByPath(obj, path) {
|
|
12549
|
+
if (!path)
|
|
12550
|
+
return obj;
|
|
12551
|
+
const keys = path.split(".");
|
|
12552
|
+
let result = obj;
|
|
12553
|
+
for (const key of keys) {
|
|
12554
|
+
if (result && typeof result === "object" && key in result) {
|
|
12555
|
+
result = result[key];
|
|
12556
|
+
} else {
|
|
12557
|
+
return void 0;
|
|
12558
|
+
}
|
|
12559
|
+
}
|
|
12560
|
+
return result;
|
|
12561
|
+
}
|
|
12706
12562
|
parseResponseFields(data) {
|
|
12707
12563
|
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);
|
|
12564
|
+
const code = this.getValueByPath(data, (_a2 = this.responseFields) == null ? void 0 : _a2.code);
|
|
12565
|
+
const message2 = this.getValueByPath(data, (_b = this.responseFields) == null ? void 0 : _b.message);
|
|
12566
|
+
const responseData = this.getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12725
12567
|
return { code, message: message2, responseData };
|
|
12726
12568
|
}
|
|
12727
|
-
/**
|
|
12728
|
-
* 处理系统异常错误(-1 - 系统异常)
|
|
12729
|
-
* 子类可重写此方法来自定义系统异常处理逻辑
|
|
12730
|
-
* @param response - Axios 响应对象
|
|
12731
|
-
* @param code - 响应状态码
|
|
12732
|
-
* @param message - 错误消息
|
|
12733
|
-
* @param responseData - 响应数据
|
|
12734
|
-
*/
|
|
12735
12569
|
handleSystemError(response, code, message2, responseData) {
|
|
12736
12570
|
if (code === -1) {
|
|
12737
12571
|
if (this.enableSystemErrorDialog) {
|
|
@@ -12742,13 +12576,7 @@ class BaseApi extends BaseHttpClient {
|
|
|
12742
12576
|
throw new Error(message2 || "系统异常");
|
|
12743
12577
|
}
|
|
12744
12578
|
}
|
|
12745
|
-
|
|
12746
|
-
* 处理业务错误(其他非200错误码)
|
|
12747
|
-
* 子类可重写此方法来自定义业务错误处理逻辑
|
|
12748
|
-
* @param code - 响应状态码
|
|
12749
|
-
* @param message - 错误消息
|
|
12750
|
-
*/
|
|
12751
|
-
handleBusinessError(code, message2) {
|
|
12579
|
+
handleBusinessError(code, message2, response) {
|
|
12752
12580
|
var _a2;
|
|
12753
12581
|
if (code && code !== 200) {
|
|
12754
12582
|
(_a2 = this.messageInstance) == null ? void 0 : _a2.error({
|
|
@@ -12758,90 +12586,79 @@ class BaseApi extends BaseHttpClient {
|
|
|
12758
12586
|
throw new Error(message2 || "请求失败");
|
|
12759
12587
|
}
|
|
12760
12588
|
}
|
|
12761
|
-
|
|
12762
|
-
* 处理错误数组 errors(如果有配置)
|
|
12763
|
-
* 子类可重写此方法来自定义错误数组处理逻辑
|
|
12764
|
-
* @param responseData - 响应数据
|
|
12765
|
-
*/
|
|
12766
|
-
handleErrorArray(responseData) {
|
|
12589
|
+
handleErrorArray(httpData, response) {
|
|
12767
12590
|
var _a2;
|
|
12768
12591
|
const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
|
|
12769
12592
|
if (errorsField) {
|
|
12770
|
-
const errors =
|
|
12593
|
+
const errors = this.getValueByPath(httpData, errorsField);
|
|
12771
12594
|
if (Array.isArray(errors) && errors.length) {
|
|
12772
|
-
|
|
12595
|
+
const config = response.config;
|
|
12596
|
+
const notificationOptions = config == null ? void 0 : config.errorNotificationOptions;
|
|
12597
|
+
this.showErrorArrayNotification(errors, notificationOptions);
|
|
12773
12598
|
throw new Error("请求错误");
|
|
12774
12599
|
}
|
|
12775
12600
|
}
|
|
12776
12601
|
}
|
|
12777
|
-
|
|
12778
|
-
* 显示错误数组通知
|
|
12779
|
-
* 子类可重写此方法来自定义错误数组通知显示方式
|
|
12780
|
-
* @param errors - 错误数组
|
|
12781
|
-
*/
|
|
12782
|
-
showErrorArrayNotification(errors) {
|
|
12602
|
+
showErrorArrayNotification(errors, notificationOptions) {
|
|
12783
12603
|
var _a2, _b;
|
|
12784
12604
|
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12605
|
+
const defaultOptions = {
|
|
12606
|
+
title: "提示",
|
|
12607
|
+
type: "error"
|
|
12608
|
+
};
|
|
12785
12609
|
if (hasDocument) {
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
}
|
|
12610
|
+
const finalOptions = {
|
|
12611
|
+
...defaultOptions,
|
|
12612
|
+
...notificationOptions,
|
|
12613
|
+
message: html
|
|
12614
|
+
};
|
|
12615
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12791
12616
|
} else {
|
|
12792
12617
|
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
}
|
|
12618
|
+
const finalOptions = {
|
|
12619
|
+
...defaultOptions,
|
|
12620
|
+
...notificationOptions,
|
|
12621
|
+
message: errorMessages
|
|
12622
|
+
};
|
|
12623
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12798
12624
|
}
|
|
12799
12625
|
}
|
|
12800
|
-
|
|
12801
|
-
* 处理提示信息 tips(如果有配置)
|
|
12802
|
-
* 子类可重写此方法来自定义提示信息处理逻辑
|
|
12803
|
-
* @param responseData - 响应数据
|
|
12804
|
-
*/
|
|
12805
|
-
handleTips(responseData) {
|
|
12626
|
+
handleTips(httpData, response) {
|
|
12806
12627
|
var _a2;
|
|
12807
12628
|
const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
|
|
12808
12629
|
if (tipsField) {
|
|
12809
|
-
const tips =
|
|
12630
|
+
const tips = this.getValueByPath(httpData, tipsField);
|
|
12810
12631
|
if (Array.isArray(tips) && tips.length) {
|
|
12811
|
-
|
|
12632
|
+
const config = response.config;
|
|
12633
|
+
const notificationOptions = config == null ? void 0 : config.tipsNotificationOptions;
|
|
12634
|
+
this.showTipsNotification(tips, notificationOptions);
|
|
12812
12635
|
}
|
|
12813
12636
|
}
|
|
12814
12637
|
}
|
|
12815
|
-
|
|
12816
|
-
* 显示提示信息通知
|
|
12817
|
-
* 子类可重写此方法来自定义提示信息通知显示方式
|
|
12818
|
-
* @param tips - 提示信息数组
|
|
12819
|
-
*/
|
|
12820
|
-
showTipsNotification(tips) {
|
|
12638
|
+
showTipsNotification(tips, notificationOptions) {
|
|
12821
12639
|
var _a2, _b;
|
|
12822
12640
|
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12641
|
+
const defaultOptions = {
|
|
12642
|
+
title: "提示",
|
|
12643
|
+
type: "warning"
|
|
12644
|
+
};
|
|
12823
12645
|
if (hasDocument) {
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
}
|
|
12646
|
+
const finalOptions = {
|
|
12647
|
+
...defaultOptions,
|
|
12648
|
+
...notificationOptions,
|
|
12649
|
+
message: html
|
|
12650
|
+
};
|
|
12651
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, finalOptions);
|
|
12829
12652
|
} else {
|
|
12830
12653
|
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
}
|
|
12654
|
+
const finalOptions = {
|
|
12655
|
+
...defaultOptions,
|
|
12656
|
+
...notificationOptions,
|
|
12657
|
+
message: tipMessages
|
|
12658
|
+
};
|
|
12659
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, finalOptions);
|
|
12836
12660
|
}
|
|
12837
12661
|
}
|
|
12838
|
-
/**
|
|
12839
|
-
* 显示系统异常对话框,当响应状态码为 -1 时调用
|
|
12840
|
-
* @param response - Axios 响应对象
|
|
12841
|
-
* @param responseData - 响应数据
|
|
12842
|
-
* @param code - 错误状态码
|
|
12843
|
-
* @param message - 错误消息
|
|
12844
|
-
*/
|
|
12845
12662
|
async showSystemExceptionDialog(response, responseData, code, message2) {
|
|
12846
12663
|
if (!hasDocument) {
|
|
12847
12664
|
console.error("系统异常信息:", responseData);
|
|
@@ -12880,10 +12697,6 @@ class BaseApi extends BaseHttpClient {
|
|
|
12880
12697
|
console.error("系统异常信息:", responseData);
|
|
12881
12698
|
}
|
|
12882
12699
|
}
|
|
12883
|
-
/**
|
|
12884
|
-
* 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
|
|
12885
|
-
* @param errorInfo - 错误信息对象
|
|
12886
|
-
*/
|
|
12887
12700
|
async reportError(errorInfo) {
|
|
12888
12701
|
var _a2, _b;
|
|
12889
12702
|
try {
|
|
@@ -12901,85 +12714,27 @@ class BaseApi extends BaseHttpClient {
|
|
|
12901
12714
|
});
|
|
12902
12715
|
}
|
|
12903
12716
|
}
|
|
12904
|
-
/**
|
|
12905
|
-
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
12906
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12907
|
-
* @param config - Axios 请求配置对象
|
|
12908
|
-
* @returns 解析后的响应数据
|
|
12909
|
-
*/
|
|
12910
12717
|
async request(config) {
|
|
12911
12718
|
return super.request(config);
|
|
12912
12719
|
}
|
|
12913
|
-
/**
|
|
12914
|
-
* 发送 GET 请求
|
|
12915
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12916
|
-
* @param url - 请求 URL 路径
|
|
12917
|
-
* @param params - 查询参数对象
|
|
12918
|
-
* @param config - 额外的请求配置
|
|
12919
|
-
* @returns 解析后的响应数据
|
|
12920
|
-
*/
|
|
12921
12720
|
async get(url, params, config) {
|
|
12922
12721
|
return super.get(url, params, config);
|
|
12923
12722
|
}
|
|
12924
|
-
/**
|
|
12925
|
-
* 发送 POST 请求
|
|
12926
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12927
|
-
* @param url - 请求 URL 路径
|
|
12928
|
-
* @param data - 请求体数据
|
|
12929
|
-
* @param config - 额外的请求配置
|
|
12930
|
-
* @returns 解析后的响应数据
|
|
12931
|
-
*/
|
|
12932
12723
|
async post(url, data, config) {
|
|
12933
12724
|
return super.post(url, data, config);
|
|
12934
12725
|
}
|
|
12935
|
-
/**
|
|
12936
|
-
* 发送 DELETE 请求
|
|
12937
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12938
|
-
* @param url - 请求 URL 路径
|
|
12939
|
-
* @param params - 查询参数对象
|
|
12940
|
-
* @param config - 额外的请求配置
|
|
12941
|
-
* @returns 解析后的响应数据
|
|
12942
|
-
*/
|
|
12943
12726
|
async delete(url, params, config) {
|
|
12944
12727
|
return super.delete(url, params, config);
|
|
12945
12728
|
}
|
|
12946
|
-
/**
|
|
12947
|
-
* 发送 PUT 请求
|
|
12948
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12949
|
-
* @param url - 请求 URL 路径
|
|
12950
|
-
* @param data - 请求体数据
|
|
12951
|
-
* @param config - 额外的请求配置
|
|
12952
|
-
* @returns 解析后的响应数据
|
|
12953
|
-
*/
|
|
12954
12729
|
async put(url, data, config) {
|
|
12955
12730
|
return super.put(url, data, config);
|
|
12956
12731
|
}
|
|
12957
|
-
/**
|
|
12958
|
-
* 批量请求,并发发送多个请求
|
|
12959
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12960
|
-
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
12961
|
-
* @returns 所有请求的响应数据数组
|
|
12962
|
-
*/
|
|
12963
12732
|
async all(requests) {
|
|
12964
12733
|
return super.all(requests);
|
|
12965
12734
|
}
|
|
12966
|
-
/**
|
|
12967
|
-
* 文件上传,将文件包装为 FormData 发送
|
|
12968
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12969
|
-
* @param url - 上传地址
|
|
12970
|
-
* @param file - 文件对象
|
|
12971
|
-
* @param config - 额外的请求配置
|
|
12972
|
-
* @returns 解析后的响应数据
|
|
12973
|
-
*/
|
|
12974
12735
|
async uploadFile(url, file, config) {
|
|
12975
12736
|
return super.uploadFile(url, file, config);
|
|
12976
12737
|
}
|
|
12977
|
-
/**
|
|
12978
|
-
* 下载文件,将 Blob 对象下载到本地
|
|
12979
|
-
* 显式声明以确保类型一致性,子类可重写此方法
|
|
12980
|
-
* @param blob - Blob 对象
|
|
12981
|
-
* @param filename - 文件名,如果不提供则使用时间戳
|
|
12982
|
-
*/
|
|
12983
12738
|
downloadFile(blob, filename) {
|
|
12984
12739
|
return super.downloadFile(blob, filename);
|
|
12985
12740
|
}
|
|
@@ -12988,11 +12743,6 @@ function createHttpService(options = {}) {
|
|
|
12988
12743
|
return new BaseApi(options);
|
|
12989
12744
|
}
|
|
12990
12745
|
const VueAxiosPlugin = {
|
|
12991
|
-
/**
|
|
12992
|
-
* 安装插件
|
|
12993
|
-
* @param app - Vue 应用实例
|
|
12994
|
-
* @param options - 插件配置选项
|
|
12995
|
-
*/
|
|
12996
12746
|
install(app, options = {}) {
|
|
12997
12747
|
const httpService = createHttpService(options.default ?? {});
|
|
12998
12748
|
app.config.globalProperties.$http = httpService;
|
|
@@ -13173,12 +12923,10 @@ const SystemErrorDialog = defineComponent({
|
|
|
13173
12923
|
h("span", { style: { fontWeight: "bold", fontSize: "16px" } }, props.title || "系统异常信息")
|
|
13174
12924
|
]),
|
|
13175
12925
|
default: () => h("div", { style: { padding: 0, maxHeight: "500px", overflowY: "auto" } }, [
|
|
13176
|
-
// 第一块:无法完成您的请求
|
|
13177
12926
|
h("div", { style: { padding: "20px", borderBottom: "1px solid #ebeef5" } }, [
|
|
13178
12927
|
h("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: "bold", color: "#303133" } }, "无法完成您的请求"),
|
|
13179
12928
|
h("p", { style: { margin: 0, color: "#606266", lineHeight: 1.5 } }, "系统在处理您的请求时遇到了问题,可能是由于服务暂时不可用。")
|
|
13180
12929
|
]),
|
|
13181
|
-
// 第二块:技术摘要(可展开)
|
|
13182
12930
|
h("div", { style: { borderBottom: "1px solid #ebeef5" } }, [
|
|
13183
12931
|
h(
|
|
13184
12932
|
"div",
|
|
@@ -13240,7 +12988,6 @@ const SystemErrorDialog = defineComponent({
|
|
|
13240
12988
|
)
|
|
13241
12989
|
) : null
|
|
13242
12990
|
]),
|
|
13243
|
-
// SkyWalking 按钮
|
|
13244
12991
|
h("div", { style: { padding: "16px 20px", borderBottom: "1px solid #ebeef5" } }, [
|
|
13245
12992
|
h(
|
|
13246
12993
|
ElButton,
|
|
@@ -13252,7 +12999,6 @@ const SystemErrorDialog = defineComponent({
|
|
|
13252
12999
|
{ default: () => "📊 在SkyWalking中查看详情" }
|
|
13253
13000
|
)
|
|
13254
13001
|
]),
|
|
13255
|
-
// 黑色错误信息区域
|
|
13256
13002
|
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
13003
|
h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
|
|
13258
13004
|
h("div", { style: { color: "#e74c3c", fontWeight: "bold", whiteSpace: "pre-wrap" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseApiConfig, vueAxiosPluginType, vueHttpServiceType } from './_types/index.ts';
|
|
2
|
+
import { default as BaseApi } from './class.ts';
|
|
3
|
+
declare global {
|
|
4
|
+
interface Window {
|
|
5
|
+
$http?: vueHttpServiceType;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
declare function createHttpService(options?: BaseApiConfig): BaseApi;
|
|
9
|
+
declare const VueAxiosPlugin: vueAxiosPluginType;
|
|
10
|
+
declare function getHttpService(options?: BaseApiConfig): BaseApi;
|
|
11
|
+
export default VueAxiosPlugin;
|
|
12
|
+
export { createHttpService, getHttpService };
|
|
@@ -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;
|