@moluoxixi/ajax-package 0.0.11-beta.2 → 0.0.12
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/SystemErrorDialog.d.ts +5 -9
- package/es/_types/api.d.ts +7 -37
- package/es/_types/emits.d.ts +0 -7
- package/es/_types/props.d.ts +0 -14
- package/es/_utils/messageWrapper.d.ts +0 -4
- package/es/_utils/notificationWrapper.d.ts +0 -4
- package/es/_utils/systemErrorInfo.d.ts +0 -21
- package/es/class.d.ts +14 -107
- package/es/index.d.ts +2 -1
- package/es/index.mjs +284 -343
- package/es/netseriver.d.ts +0 -14
- package/package.json +1 -1
|
@@ -0,0 +1,25 @@
|
|
|
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: () => void;
|
|
8
|
+
protected getToken?: () => string | null;
|
|
9
|
+
protected onLoginRequired?: () => 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
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
17
|
+
private setupInterceptors;
|
|
18
|
+
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
19
|
+
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
20
|
+
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
21
|
+
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
22
|
+
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
23
|
+
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
24
|
+
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
25
|
+
}
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SystemErrorDialog 组件
|
|
3
|
-
* 使用 defineComponent 和 h 函数实现
|
|
4
|
-
*/
|
|
5
1
|
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
6
2
|
title: {
|
|
7
3
|
type: StringConstructor;
|
|
8
4
|
default: string;
|
|
9
5
|
};
|
|
10
6
|
width: {
|
|
11
|
-
type: (
|
|
7
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
12
8
|
default: number;
|
|
13
9
|
};
|
|
14
10
|
userName: {
|
|
@@ -44,7 +40,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
44
40
|
default: undefined;
|
|
45
41
|
};
|
|
46
42
|
errorCode: {
|
|
47
|
-
type: (
|
|
43
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
48
44
|
default: undefined;
|
|
49
45
|
};
|
|
50
46
|
modelValue: {
|
|
@@ -64,7 +60,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
64
60
|
default: string;
|
|
65
61
|
};
|
|
66
62
|
width: {
|
|
67
|
-
type: (
|
|
63
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
68
64
|
default: number;
|
|
69
65
|
};
|
|
70
66
|
userName: {
|
|
@@ -100,7 +96,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
100
96
|
default: undefined;
|
|
101
97
|
};
|
|
102
98
|
errorCode: {
|
|
103
|
-
type: (
|
|
99
|
+
type: (NumberConstructor | StringConstructor)[];
|
|
104
100
|
default: undefined;
|
|
105
101
|
};
|
|
106
102
|
modelValue: {
|
|
@@ -114,6 +110,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
114
110
|
onReport?: (() => any) | undefined;
|
|
115
111
|
}>, {
|
|
116
112
|
title: string;
|
|
113
|
+
modelValue: boolean;
|
|
117
114
|
width: string | number;
|
|
118
115
|
userName: string;
|
|
119
116
|
userId: string;
|
|
@@ -124,6 +121,5 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
124
121
|
traceId: string;
|
|
125
122
|
errorMessage: string;
|
|
126
123
|
errorCode: string | number;
|
|
127
|
-
modelValue: boolean;
|
|
128
124
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
129
125
|
export default _default;
|
package/es/_types/api.d.ts
CHANGED
|
@@ -1,58 +1,28 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
2
|
import { default as BaseApi } from '../class.ts';
|
|
3
|
-
|
|
4
|
-
* BaseApi 配置接口,用于配置 BaseApi 实例的所有选项
|
|
5
|
-
*/
|
|
6
|
-
export interface BaseApiConfig {
|
|
7
|
-
/** API 基础地址 */
|
|
3
|
+
export interface BaseHttpClientConfig {
|
|
8
4
|
baseURL?: string;
|
|
9
|
-
/** 请求超时时间(毫秒),默认 5000 */
|
|
10
5
|
timeout?: number;
|
|
11
|
-
|
|
6
|
+
onTimeout?: () => void;
|
|
7
|
+
getToken?: () => string | null;
|
|
8
|
+
onLoginRequired?: () => void;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface BaseApiConfig extends BaseHttpClientConfig {
|
|
12
12
|
responseFields?: {
|
|
13
|
-
/** 响应状态码字段名,默认 'Code' */
|
|
14
13
|
code?: string;
|
|
15
|
-
/** 响应消息字段名,默认 'Message' */
|
|
16
14
|
message?: string;
|
|
17
|
-
/** 响应数据字段名,默认 'data' */
|
|
18
15
|
data?: string;
|
|
19
|
-
/** 错误数组字段名 */
|
|
20
16
|
errors?: string;
|
|
21
|
-
/** 提示信息字段名 */
|
|
22
17
|
tips?: string;
|
|
23
18
|
};
|
|
24
|
-
/** 请求超时回调函数 */
|
|
25
|
-
onTimeout?: () => void;
|
|
26
|
-
/** 获取 token 的函数,每次请求前自动调用 */
|
|
27
|
-
getToken?: () => string | null;
|
|
28
|
-
/** 登录失效回调函数,当检测到 401 错误时调用 */
|
|
29
|
-
onLoginRequired?: () => void;
|
|
30
|
-
/** 是否启用 code === -1 的系统异常弹窗,默认为 true */
|
|
31
19
|
enableSystemErrorDialog?: boolean;
|
|
32
|
-
/** 允许其他任意配置项,会直接传递给 axios.create */
|
|
33
|
-
[key: string]: any;
|
|
34
20
|
}
|
|
35
|
-
/**
|
|
36
|
-
* Vue Axios 插件配置选项
|
|
37
|
-
*/
|
|
38
21
|
export interface vueAxiosPluginOptionsType {
|
|
39
|
-
/** 默认 HTTP 服务配置 */
|
|
40
22
|
default?: BaseApiConfig;
|
|
41
|
-
/** 是否在所有组件中通过 mixin 注入 $http,默认为 true */
|
|
42
23
|
globalMixin?: boolean;
|
|
43
24
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Vue HTTP 服务类型,在 Vue 应用中通过 this.$http 或 inject('$http') 获取
|
|
46
|
-
*/
|
|
47
25
|
export type vueHttpServiceType = BaseApi;
|
|
48
|
-
/**
|
|
49
|
-
* Vue Axios 插件类型,定义了 Vue 插件的标准接口
|
|
50
|
-
*/
|
|
51
26
|
export interface vueAxiosPluginType {
|
|
52
|
-
/**
|
|
53
|
-
* 安装插件
|
|
54
|
-
* @param app - Vue 应用实例
|
|
55
|
-
* @param options - 插件配置选项
|
|
56
|
-
*/
|
|
57
27
|
install: (app: App, options?: vueAxiosPluginOptionsType) => void;
|
|
58
28
|
}
|
package/es/_types/emits.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SystemErrorDialog 组件的 Emits 类型定义
|
|
3
|
-
*/
|
|
4
1
|
export interface SystemErrorDialogEmitsType {
|
|
5
|
-
/** v-model 更新事件 */
|
|
6
2
|
'update:modelValue': [val: boolean];
|
|
7
|
-
/** 关闭事件 */
|
|
8
3
|
'close': [];
|
|
9
|
-
/** 确认事件 */
|
|
10
4
|
'confirm': [data: any];
|
|
11
|
-
/** 上报事件 */
|
|
12
5
|
'report': [];
|
|
13
6
|
}
|
package/es/_types/props.d.ts
CHANGED
|
@@ -1,27 +1,13 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SystemErrorDialog 组件的 Props 类型定义
|
|
3
|
-
*/
|
|
4
1
|
export interface SystemErrorDialogPropsType {
|
|
5
|
-
/** 对话框标题 */
|
|
6
2
|
title?: string;
|
|
7
|
-
/** 对话框宽度 */
|
|
8
3
|
width?: number | string;
|
|
9
|
-
/** 用户名 */
|
|
10
4
|
userName?: string;
|
|
11
|
-
/** 用户ID */
|
|
12
5
|
userId?: string;
|
|
13
|
-
/** 科室名称 */
|
|
14
6
|
deptName?: string;
|
|
15
|
-
/** 科室ID */
|
|
16
7
|
deptId?: string;
|
|
17
|
-
/** 客户端IP地址 */
|
|
18
8
|
clientIp?: string;
|
|
19
|
-
/** 请求URL路径 */
|
|
20
9
|
requestUrl?: string;
|
|
21
|
-
/** 链路追踪ID */
|
|
22
10
|
traceId?: string;
|
|
23
|
-
/** 错误消息 */
|
|
24
11
|
errorMessage?: string;
|
|
25
|
-
/** 错误代码 */
|
|
26
12
|
errorCode?: number | string;
|
|
27
13
|
}
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 创建通知实例的包装函数(用于 errors / tips 展示)
|
|
3
|
-
* @returns 通知实例,支持 success、error、warning、info 方法
|
|
4
|
-
*/
|
|
5
1
|
export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
|
|
6
2
|
_context: import('vue').AppContext | null;
|
|
7
3
|
}) | ((options: string | {
|
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
import { AxiosResponse } from 'axios';
|
|
2
2
|
import { SystemErrorDialogPropsType } from '../_types/index.ts';
|
|
3
|
-
/**
|
|
4
|
-
* 规范化请求参数对象
|
|
5
|
-
* @param payload 请求参数
|
|
6
|
-
* @returns 规范化后的对象
|
|
7
|
-
*/
|
|
8
3
|
export declare function normalizePayload(payload: any): Record<string, any>;
|
|
9
|
-
/**
|
|
10
|
-
* 解析响应头中的 TraceId
|
|
11
|
-
* @param headers 响应头
|
|
12
|
-
* @returns TraceId 字符串
|
|
13
|
-
*/
|
|
14
4
|
export declare function resolveTraceId(headers: AxiosResponse['headers'] | undefined): string;
|
|
15
|
-
/**
|
|
16
|
-
* 从 localStorage 中读取 userInfo
|
|
17
|
-
* @returns userInfo 对象,如果不存在则返回空对象
|
|
18
|
-
*/
|
|
19
5
|
export declare function getUserInfoFromLocalStorage(): Record<string, any>;
|
|
20
|
-
/**
|
|
21
|
-
* 从 AxiosResponse 中提取系统错误信息
|
|
22
|
-
* @param response Axios 响应对象
|
|
23
|
-
* @param code 错误代码
|
|
24
|
-
* @param message 错误消息
|
|
25
|
-
* @returns 提取的错误信息
|
|
26
|
-
*/
|
|
27
6
|
export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
|
package/es/class.d.ts
CHANGED
|
@@ -1,114 +1,21 @@
|
|
|
1
|
-
import { AxiosError,
|
|
1
|
+
import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
|
|
2
2
|
import { BaseApiConfig } from './_types/index.ts';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
* BaseApi 类
|
|
6
|
-
* 基于 axios 封装的 HTTP 请求类,提供统一的请求处理、错误处理和响应解析
|
|
7
|
-
*/
|
|
8
|
-
export default class BaseApi {
|
|
9
|
-
protected baseURL: string;
|
|
10
|
-
protected timeout: number;
|
|
3
|
+
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
4
|
+
export default class BaseApi extends BaseHttpClient {
|
|
11
5
|
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
12
|
-
protected onTimeout: () => void;
|
|
13
|
-
protected getToken?: () => string | null;
|
|
14
|
-
protected onLoginRequired?: () => void;
|
|
15
6
|
protected enableSystemErrorDialog: boolean;
|
|
16
|
-
instance: ReturnType<typeof axios.create>;
|
|
17
|
-
protected messageInstance: MessageInstance;
|
|
18
|
-
protected notificationInstance: NotificationInstance;
|
|
19
|
-
/**
|
|
20
|
-
* 创建 BaseApi 实例
|
|
21
|
-
* @param config - API 配置对象
|
|
22
|
-
*/
|
|
23
7
|
constructor(config: BaseApiConfig);
|
|
24
|
-
|
|
25
|
-
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
26
|
-
* @param config - 请求配置对象
|
|
27
|
-
* @returns 处理后的请求配置
|
|
28
|
-
*/
|
|
29
|
-
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
|
|
30
|
-
/**
|
|
31
|
-
* 处理响应配置,解析响应数据并处理错误
|
|
32
|
-
* 支持嵌套路径解析,自动处理登录失效、系统异常等错误
|
|
33
|
-
* @param response - Axios 响应对象
|
|
34
|
-
* @returns 解析后的响应数据
|
|
35
|
-
*/
|
|
36
|
-
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
37
|
-
/**
|
|
38
|
-
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
39
|
-
* @param error - Axios 错误对象
|
|
40
|
-
* @returns 处理后的错误对象
|
|
41
|
-
*/
|
|
8
|
+
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
42
9
|
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
* @returns 解析后的响应数据
|
|
53
|
-
*/
|
|
54
|
-
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
55
|
-
/**
|
|
56
|
-
* 发送 GET 请求
|
|
57
|
-
* @param url - 请求 URL 路径
|
|
58
|
-
* @param params - 查询参数对象
|
|
59
|
-
* @param config - 额外的请求配置
|
|
60
|
-
* @returns 解析后的响应数据
|
|
61
|
-
*/
|
|
62
|
-
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
63
|
-
/**
|
|
64
|
-
* 发送 POST 请求
|
|
65
|
-
* @param url - 请求 URL 路径
|
|
66
|
-
* @param data - 请求体数据
|
|
67
|
-
* @param config - 额外的请求配置
|
|
68
|
-
* @returns 解析后的响应数据
|
|
69
|
-
*/
|
|
70
|
-
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
71
|
-
/**
|
|
72
|
-
* 发送 DELETE 请求
|
|
73
|
-
* @param url - 请求 URL 路径
|
|
74
|
-
* @param params - 查询参数对象
|
|
75
|
-
* @param config - 额外的请求配置
|
|
76
|
-
* @returns 解析后的响应数据
|
|
77
|
-
*/
|
|
78
|
-
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
79
|
-
/**
|
|
80
|
-
* 发送 PUT 请求
|
|
81
|
-
* @param url - 请求 URL 路径
|
|
82
|
-
* @param data - 请求体数据
|
|
83
|
-
* @param config - 额外的请求配置
|
|
84
|
-
* @returns 解析后的响应数据
|
|
85
|
-
*/
|
|
86
|
-
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
87
|
-
/**
|
|
88
|
-
* 批量请求,并发发送多个请求
|
|
89
|
-
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
90
|
-
* @returns 所有请求的响应数据数组
|
|
91
|
-
*/
|
|
92
|
-
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
93
|
-
/**
|
|
94
|
-
* 文件上传,将文件包装为 FormData 发送
|
|
95
|
-
* @param url - 上传地址
|
|
96
|
-
* @param file - 文件对象
|
|
97
|
-
* @param config - 额外的请求配置
|
|
98
|
-
* @returns 解析后的响应数据
|
|
99
|
-
*/
|
|
100
|
-
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
101
|
-
/**
|
|
102
|
-
* 显示系统异常对话框,当响应状态码为 -1 时调用
|
|
103
|
-
* @param response - Axios 响应对象
|
|
104
|
-
* @param responseData - 响应数据
|
|
105
|
-
* @param code - 错误状态码
|
|
106
|
-
* @param message - 错误消息
|
|
107
|
-
*/
|
|
10
|
+
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
11
|
+
protected parseResponseFields(data: any): {
|
|
12
|
+
code: any;
|
|
13
|
+
message: any;
|
|
14
|
+
responseData: any;
|
|
15
|
+
};
|
|
16
|
+
protected handleErrorCode(response: AxiosResponse, code: any, message: any, responseData: any): void;
|
|
17
|
+
protected handleErrors(responseData: any): void;
|
|
18
|
+
protected handleTips(responseData: any): void;
|
|
108
19
|
private showSystemExceptionDialog;
|
|
109
|
-
|
|
110
|
-
* 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
|
|
111
|
-
* @param errorInfo - 错误信息对象
|
|
112
|
-
*/
|
|
113
|
-
private reportError;
|
|
20
|
+
protected reportError(errorInfo: any): Promise<void>;
|
|
114
21
|
}
|
package/es/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import { default as BaseHttpClient } from './BaseHttpClient.ts';
|
|
1
2
|
import { default as BaseApi } from './class.ts';
|
|
2
3
|
import { default as VueAxiosPlugin, createHttpService, getHttpService } from './netseriver.ts';
|
|
3
|
-
export { BaseApi, createHttpService, getHttpService, VueAxiosPlugin, };
|
|
4
|
+
export { BaseApi, BaseHttpClient, createHttpService, getHttpService, VueAxiosPlugin, };
|
|
4
5
|
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("c6a35fc5-e19d-40c8-8129-fe6481835a30")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "c6a35fc5-e19d-40c8-8129-fe6481835a30";
|
|
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
|
}
|
|
@@ -2483,22 +2483,6 @@ const {
|
|
|
2483
2483
|
getAdapter,
|
|
2484
2484
|
mergeConfig: mergeConfig$1
|
|
2485
2485
|
} = axios;
|
|
2486
|
-
async function dynamicImports(modulePromise, exportNames) {
|
|
2487
|
-
const module = await modulePromise;
|
|
2488
|
-
const result = {};
|
|
2489
|
-
for (const _name of exportNames) {
|
|
2490
|
-
const name = _name || "default";
|
|
2491
|
-
if (name === "default") {
|
|
2492
|
-
result[name] = module.default ?? module;
|
|
2493
|
-
} else {
|
|
2494
|
-
if (!(name in module)) {
|
|
2495
|
-
throw new Error(`模块中不存在导出 "${name}"`);
|
|
2496
|
-
}
|
|
2497
|
-
result[name] = module[name];
|
|
2498
|
-
}
|
|
2499
|
-
}
|
|
2500
|
-
return result;
|
|
2501
|
-
}
|
|
2502
2486
|
const configProviderContextKey = Symbol();
|
|
2503
2487
|
const defaultNamespace = "el";
|
|
2504
2488
|
const statePrefix = "is-";
|
|
@@ -12065,143 +12049,6 @@ notify.closeAll = closeAll;
|
|
|
12065
12049
|
notify.updateOffsets = updateOffsets;
|
|
12066
12050
|
notify._context = null;
|
|
12067
12051
|
const ElNotification = withInstallFunction(notify, "$notify");
|
|
12068
|
-
function createApiDialog(DialogComponent) {
|
|
12069
|
-
let container = null;
|
|
12070
|
-
let vnode = null;
|
|
12071
|
-
let isOpen = false;
|
|
12072
|
-
let currentReject = null;
|
|
12073
|
-
const DefaultDialog = defineComponent({
|
|
12074
|
-
name: "DefaultApiDialog",
|
|
12075
|
-
props: {
|
|
12076
|
-
modelValue: {
|
|
12077
|
-
type: Boolean,
|
|
12078
|
-
default: false
|
|
12079
|
-
},
|
|
12080
|
-
title: {
|
|
12081
|
-
type: String,
|
|
12082
|
-
default: "对话框"
|
|
12083
|
-
},
|
|
12084
|
-
width: {
|
|
12085
|
-
type: [String, Number],
|
|
12086
|
-
default: "50%"
|
|
12087
|
-
}
|
|
12088
|
-
},
|
|
12089
|
-
emits: ["close", "confirm", "update:modelValue"],
|
|
12090
|
-
setup(props, { slots, emit }) {
|
|
12091
|
-
const handleClose = () => {
|
|
12092
|
-
emit("close");
|
|
12093
|
-
emit("update:modelValue", false);
|
|
12094
|
-
};
|
|
12095
|
-
const handleConfirm = (data) => {
|
|
12096
|
-
emit("confirm", data);
|
|
12097
|
-
emit("update:modelValue", false);
|
|
12098
|
-
};
|
|
12099
|
-
return () => h(ElDialog, {
|
|
12100
|
-
"modelValue": props.modelValue,
|
|
12101
|
-
"title": props.title,
|
|
12102
|
-
"width": props.width,
|
|
12103
|
-
"onUpdate:modelValue": (val) => {
|
|
12104
|
-
emit("update:modelValue", val);
|
|
12105
|
-
if (!val) {
|
|
12106
|
-
handleClose();
|
|
12107
|
-
}
|
|
12108
|
-
}
|
|
12109
|
-
}, {
|
|
12110
|
-
default: () => {
|
|
12111
|
-
var _a2;
|
|
12112
|
-
return (_a2 = slots.default) == null ? void 0 : _a2.call(slots);
|
|
12113
|
-
},
|
|
12114
|
-
header: slots.header,
|
|
12115
|
-
footer: slots.footer || (() => h("div", { class: "dialog-footer" }, [
|
|
12116
|
-
h(ElButton, {
|
|
12117
|
-
onClick: () => handleClose()
|
|
12118
|
-
}, () => "取消"),
|
|
12119
|
-
h(ElButton, {
|
|
12120
|
-
type: "primary",
|
|
12121
|
-
onClick: () => handleConfirm({})
|
|
12122
|
-
}, () => "确定")
|
|
12123
|
-
]))
|
|
12124
|
-
});
|
|
12125
|
-
}
|
|
12126
|
-
});
|
|
12127
|
-
const FinalDialogComponent = DialogComponent || DefaultDialog;
|
|
12128
|
-
function createContainer() {
|
|
12129
|
-
const el = document.createElement("div");
|
|
12130
|
-
document.body.appendChild(el);
|
|
12131
|
-
return el;
|
|
12132
|
-
}
|
|
12133
|
-
function show(options = {}) {
|
|
12134
|
-
if (isOpen) {
|
|
12135
|
-
close2();
|
|
12136
|
-
}
|
|
12137
|
-
container = createContainer();
|
|
12138
|
-
const { props = {}, slots = {}, appContext } = options;
|
|
12139
|
-
return new Promise((resolve, reject) => {
|
|
12140
|
-
currentReject = reject;
|
|
12141
|
-
vnode = createVNode(
|
|
12142
|
-
FinalDialogComponent,
|
|
12143
|
-
{
|
|
12144
|
-
...props,
|
|
12145
|
-
modelValue: true,
|
|
12146
|
-
onUpdateModelValue: (val) => {
|
|
12147
|
-
if (!val) {
|
|
12148
|
-
reject(new Error("对话框已关闭"));
|
|
12149
|
-
cleanup();
|
|
12150
|
-
}
|
|
12151
|
-
},
|
|
12152
|
-
// 监听关闭事件
|
|
12153
|
-
onClose: () => {
|
|
12154
|
-
reject(new Error("对话框已关闭"));
|
|
12155
|
-
cleanup();
|
|
12156
|
-
},
|
|
12157
|
-
// 监听确认事件(如有)
|
|
12158
|
-
onConfirm: (data) => {
|
|
12159
|
-
resolve(data);
|
|
12160
|
-
cleanup();
|
|
12161
|
-
}
|
|
12162
|
-
},
|
|
12163
|
-
slots
|
|
12164
|
-
);
|
|
12165
|
-
if (appContext) {
|
|
12166
|
-
vnode.appContext = appContext;
|
|
12167
|
-
}
|
|
12168
|
-
render(vnode, container);
|
|
12169
|
-
isOpen = true;
|
|
12170
|
-
});
|
|
12171
|
-
}
|
|
12172
|
-
function close2() {
|
|
12173
|
-
if (isOpen && vnode && container) {
|
|
12174
|
-
if (vnode.component && vnode.component.exposed && typeof vnode.component.exposed.close === "function") {
|
|
12175
|
-
vnode.component.exposed.close();
|
|
12176
|
-
}
|
|
12177
|
-
if (currentReject) {
|
|
12178
|
-
currentReject(new Error("对话框被主动关闭"));
|
|
12179
|
-
currentReject = null;
|
|
12180
|
-
}
|
|
12181
|
-
cleanup();
|
|
12182
|
-
}
|
|
12183
|
-
}
|
|
12184
|
-
function cleanup() {
|
|
12185
|
-
if (container) {
|
|
12186
|
-
render(null, container);
|
|
12187
|
-
container.remove();
|
|
12188
|
-
container = null;
|
|
12189
|
-
}
|
|
12190
|
-
vnode = null;
|
|
12191
|
-
isOpen = false;
|
|
12192
|
-
}
|
|
12193
|
-
if (!DialogComponent) {
|
|
12194
|
-
return {
|
|
12195
|
-
Dialog: DefaultDialog,
|
|
12196
|
-
show,
|
|
12197
|
-
close: close2
|
|
12198
|
-
};
|
|
12199
|
-
}
|
|
12200
|
-
return {
|
|
12201
|
-
show,
|
|
12202
|
-
close: close2
|
|
12203
|
-
};
|
|
12204
|
-
}
|
|
12205
12052
|
const hasDocument$2 = typeof document !== "undefined";
|
|
12206
12053
|
function createMessageWrapper() {
|
|
12207
12054
|
if (hasDocument$2) {
|
|
@@ -12323,8 +12170,6 @@ function extractSystemErrorInfo(response, code, message2) {
|
|
|
12323
12170
|
errorMessage: message2
|
|
12324
12171
|
};
|
|
12325
12172
|
}
|
|
12326
|
-
const hasDocument = typeof document !== "undefined";
|
|
12327
|
-
let systemErrorDialogInstance = null;
|
|
12328
12173
|
function defaultOnLoginRequired() {
|
|
12329
12174
|
if (typeof window !== "undefined") {
|
|
12330
12175
|
window.location.href = `/login?redirect=${encodeURIComponent(window.location.href)}`;
|
|
@@ -12333,167 +12178,48 @@ function defaultOnLoginRequired() {
|
|
|
12333
12178
|
function defaultGetToken() {
|
|
12334
12179
|
return typeof localStorage !== "undefined" ? localStorage.getItem("token") || "" : "";
|
|
12335
12180
|
}
|
|
12336
|
-
class
|
|
12337
|
-
/**
|
|
12338
|
-
* 创建 BaseApi 实例
|
|
12339
|
-
* @param config - API 配置对象
|
|
12340
|
-
*/
|
|
12181
|
+
class BaseHttpClient {
|
|
12341
12182
|
constructor(config) {
|
|
12342
12183
|
__publicField(this, "baseURL", "");
|
|
12343
12184
|
__publicField(this, "timeout", 5e3);
|
|
12344
|
-
__publicField(this, "responseFields");
|
|
12345
12185
|
__publicField(this, "onTimeout");
|
|
12346
12186
|
__publicField(this, "getToken");
|
|
12347
12187
|
__publicField(this, "onLoginRequired");
|
|
12348
|
-
__publicField(this, "enableSystemErrorDialog");
|
|
12349
12188
|
__publicField(this, "instance");
|
|
12350
12189
|
__publicField(this, "messageInstance");
|
|
12351
12190
|
__publicField(this, "notificationInstance");
|
|
12352
12191
|
const {
|
|
12353
12192
|
baseURL = "",
|
|
12354
12193
|
timeout = 5e3,
|
|
12355
|
-
responseFields,
|
|
12356
12194
|
onTimeout = () => {
|
|
12357
12195
|
},
|
|
12358
12196
|
getToken = defaultGetToken,
|
|
12359
12197
|
onLoginRequired = defaultOnLoginRequired,
|
|
12360
|
-
enableSystemErrorDialog = true,
|
|
12361
12198
|
...axiosConfig
|
|
12362
12199
|
} = config;
|
|
12363
12200
|
this.baseURL = baseURL;
|
|
12364
12201
|
this.timeout = timeout;
|
|
12365
12202
|
this.messageInstance = createMessageWrapper();
|
|
12366
12203
|
this.notificationInstance = createNotificationWrapper();
|
|
12367
|
-
this.responseFields = {
|
|
12368
|
-
code: "Code",
|
|
12369
|
-
message: "Message",
|
|
12370
|
-
data: "data",
|
|
12371
|
-
errors: "errors",
|
|
12372
|
-
tips: "tips",
|
|
12373
|
-
...responseFields
|
|
12374
|
-
};
|
|
12375
12204
|
this.onTimeout = onTimeout;
|
|
12376
12205
|
this.getToken = getToken;
|
|
12377
12206
|
this.onLoginRequired = onLoginRequired;
|
|
12378
|
-
this.enableSystemErrorDialog = enableSystemErrorDialog;
|
|
12379
12207
|
this.instance = axios.create({
|
|
12380
12208
|
baseURL: this.baseURL,
|
|
12381
12209
|
timeout: this.timeout,
|
|
12382
12210
|
...axiosConfig
|
|
12383
|
-
// 将所有剩余参数传给axios.create
|
|
12384
12211
|
});
|
|
12385
12212
|
this.setupInterceptors();
|
|
12386
12213
|
}
|
|
12387
|
-
/**
|
|
12388
|
-
* 处理请求配置,子类可重写此方法自定义请求配置
|
|
12389
|
-
* @param config - 请求配置对象
|
|
12390
|
-
* @returns 处理后的请求配置
|
|
12391
|
-
*/
|
|
12392
12214
|
processRequestConfig(config) {
|
|
12393
12215
|
return config;
|
|
12394
12216
|
}
|
|
12395
|
-
/**
|
|
12396
|
-
* 处理响应配置,解析响应数据并处理错误
|
|
12397
|
-
* 支持嵌套路径解析,自动处理登录失效、系统异常等错误
|
|
12398
|
-
* @param response - Axios 响应对象
|
|
12399
|
-
* @returns 解析后的响应数据
|
|
12400
|
-
*/
|
|
12401
12217
|
processResponseConfig(response) {
|
|
12402
|
-
|
|
12403
|
-
const data = response.data;
|
|
12404
|
-
const getValueByPath = (obj, path) => {
|
|
12405
|
-
if (!path)
|
|
12406
|
-
return obj;
|
|
12407
|
-
const keys = path.split(".");
|
|
12408
|
-
let result = obj;
|
|
12409
|
-
for (const key of keys) {
|
|
12410
|
-
if (result && typeof result === "object" && key in result) {
|
|
12411
|
-
result = result[key];
|
|
12412
|
-
} else {
|
|
12413
|
-
return void 0;
|
|
12414
|
-
}
|
|
12415
|
-
}
|
|
12416
|
-
return result;
|
|
12417
|
-
};
|
|
12418
|
-
const code = getValueByPath(data, (_a2 = this.responseFields) == null ? void 0 : _a2.code);
|
|
12419
|
-
const message2 = getValueByPath(data, (_b = this.responseFields) == null ? void 0 : _b.message);
|
|
12420
|
-
const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12421
|
-
if (code === 401) {
|
|
12422
|
-
throw new Error("登录失效,请重新登录");
|
|
12423
|
-
}
|
|
12424
|
-
if (code === -1) {
|
|
12425
|
-
if (this.enableSystemErrorDialog) {
|
|
12426
|
-
this.showSystemExceptionDialog(response, responseData, code, message2).catch((error) => {
|
|
12427
|
-
console.error("显示系统异常对话框失败:", error);
|
|
12428
|
-
});
|
|
12429
|
-
}
|
|
12430
|
-
throw new Error(message2 || "系统异常");
|
|
12431
|
-
}
|
|
12432
|
-
if (code && code !== 200) {
|
|
12433
|
-
(_d = this.messageInstance) == null ? void 0 : _d.error({
|
|
12434
|
-
message: message2 || "请求失败",
|
|
12435
|
-
duration: 5 * 1e3
|
|
12436
|
-
});
|
|
12437
|
-
throw new Error(message2 || "请求失败");
|
|
12438
|
-
}
|
|
12439
|
-
const errorsField = (_e = this.responseFields) == null ? void 0 : _e.errors;
|
|
12440
|
-
if (errorsField) {
|
|
12441
|
-
const errors = responseData == null ? void 0 : responseData[errorsField];
|
|
12442
|
-
if (Array.isArray(errors) && errors.length) {
|
|
12443
|
-
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12444
|
-
if (hasDocument) {
|
|
12445
|
-
(_f = this.notificationInstance) == null ? void 0 : _f.call(this, {
|
|
12446
|
-
title: "提示",
|
|
12447
|
-
message: html,
|
|
12448
|
-
type: "error"
|
|
12449
|
-
});
|
|
12450
|
-
} else {
|
|
12451
|
-
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12452
|
-
(_g = this.notificationInstance) == null ? void 0 : _g.call(this, {
|
|
12453
|
-
title: "提示",
|
|
12454
|
-
message: errorMessages,
|
|
12455
|
-
type: "error"
|
|
12456
|
-
});
|
|
12457
|
-
}
|
|
12458
|
-
throw new Error("请求错误");
|
|
12459
|
-
}
|
|
12460
|
-
}
|
|
12461
|
-
const tipsField = (_h = this.responseFields) == null ? void 0 : _h.tips;
|
|
12462
|
-
if (tipsField) {
|
|
12463
|
-
const tips = responseData == null ? void 0 : responseData[tipsField];
|
|
12464
|
-
if (Array.isArray(tips) && tips.length) {
|
|
12465
|
-
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12466
|
-
if (hasDocument) {
|
|
12467
|
-
(_i = this.notificationInstance) == null ? void 0 : _i.call(this, {
|
|
12468
|
-
title: "提示",
|
|
12469
|
-
message: html,
|
|
12470
|
-
type: "warning"
|
|
12471
|
-
});
|
|
12472
|
-
} else {
|
|
12473
|
-
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12474
|
-
(_j = this.notificationInstance) == null ? void 0 : _j.call(this, {
|
|
12475
|
-
title: "提示",
|
|
12476
|
-
message: tipMessages,
|
|
12477
|
-
type: "warning"
|
|
12478
|
-
});
|
|
12479
|
-
}
|
|
12480
|
-
}
|
|
12481
|
-
}
|
|
12482
|
-
return responseData;
|
|
12218
|
+
return response.data;
|
|
12483
12219
|
}
|
|
12484
|
-
/**
|
|
12485
|
-
* 处理响应错误,子类可重写此方法自定义错误处理
|
|
12486
|
-
* @param error - Axios 错误对象
|
|
12487
|
-
* @returns 处理后的错误对象
|
|
12488
|
-
*/
|
|
12489
12220
|
async processResponseError(error) {
|
|
12490
12221
|
return error;
|
|
12491
12222
|
}
|
|
12492
|
-
/**
|
|
12493
|
-
* 设置请求和响应拦截器
|
|
12494
|
-
* 请求拦截器:自动添加 Token
|
|
12495
|
-
* 响应拦截器:处理成功响应和错误响应(401、超时等)
|
|
12496
|
-
*/
|
|
12497
12223
|
setupInterceptors() {
|
|
12498
12224
|
this.instance.interceptors.request.use(
|
|
12499
12225
|
(config) => {
|
|
@@ -12544,59 +12270,21 @@ class BaseApi {
|
|
|
12544
12270
|
}
|
|
12545
12271
|
);
|
|
12546
12272
|
}
|
|
12547
|
-
/**
|
|
12548
|
-
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
12549
|
-
* @param config - Axios 请求配置对象
|
|
12550
|
-
* @returns 解析后的响应数据
|
|
12551
|
-
*/
|
|
12552
12273
|
async request(config) {
|
|
12553
12274
|
return this.instance.request(config);
|
|
12554
12275
|
}
|
|
12555
|
-
/**
|
|
12556
|
-
* 发送 GET 请求
|
|
12557
|
-
* @param url - 请求 URL 路径
|
|
12558
|
-
* @param params - 查询参数对象
|
|
12559
|
-
* @param config - 额外的请求配置
|
|
12560
|
-
* @returns 解析后的响应数据
|
|
12561
|
-
*/
|
|
12562
12276
|
async get(url, params, config) {
|
|
12563
12277
|
return this.request({ ...config, url, method: "get", params });
|
|
12564
12278
|
}
|
|
12565
|
-
/**
|
|
12566
|
-
* 发送 POST 请求
|
|
12567
|
-
* @param url - 请求 URL 路径
|
|
12568
|
-
* @param data - 请求体数据
|
|
12569
|
-
* @param config - 额外的请求配置
|
|
12570
|
-
* @returns 解析后的响应数据
|
|
12571
|
-
*/
|
|
12572
12279
|
async post(url, data, config) {
|
|
12573
12280
|
return this.request({ ...config, url, method: "post", data });
|
|
12574
12281
|
}
|
|
12575
|
-
/**
|
|
12576
|
-
* 发送 DELETE 请求
|
|
12577
|
-
* @param url - 请求 URL 路径
|
|
12578
|
-
* @param params - 查询参数对象
|
|
12579
|
-
* @param config - 额外的请求配置
|
|
12580
|
-
* @returns 解析后的响应数据
|
|
12581
|
-
*/
|
|
12582
12282
|
async delete(url, params, config) {
|
|
12583
12283
|
return this.request({ ...config, url, method: "delete", params });
|
|
12584
12284
|
}
|
|
12585
|
-
/**
|
|
12586
|
-
* 发送 PUT 请求
|
|
12587
|
-
* @param url - 请求 URL 路径
|
|
12588
|
-
* @param data - 请求体数据
|
|
12589
|
-
* @param config - 额外的请求配置
|
|
12590
|
-
* @returns 解析后的响应数据
|
|
12591
|
-
*/
|
|
12592
12285
|
async put(url, data, config) {
|
|
12593
12286
|
return this.request({ ...config, url, method: "put", data });
|
|
12594
12287
|
}
|
|
12595
|
-
/**
|
|
12596
|
-
* 批量请求,并发发送多个请求
|
|
12597
|
-
* @param requests - 请求配置数组或已发起的请求 Promise 数组
|
|
12598
|
-
* @returns 所有请求的响应数据数组
|
|
12599
|
-
*/
|
|
12600
12288
|
async all(requests) {
|
|
12601
12289
|
if (!requests.length)
|
|
12602
12290
|
return [];
|
|
@@ -12609,13 +12297,6 @@ class BaseApi {
|
|
|
12609
12297
|
const promises = requests.map((config) => this.request(config));
|
|
12610
12298
|
return await Promise.all(promises);
|
|
12611
12299
|
}
|
|
12612
|
-
/**
|
|
12613
|
-
* 文件上传,将文件包装为 FormData 发送
|
|
12614
|
-
* @param url - 上传地址
|
|
12615
|
-
* @param file - 文件对象
|
|
12616
|
-
* @param config - 额外的请求配置
|
|
12617
|
-
* @returns 解析后的响应数据
|
|
12618
|
-
*/
|
|
12619
12300
|
async uploadFile(url, file, config) {
|
|
12620
12301
|
const formData = new FormData();
|
|
12621
12302
|
formData.append("file", file);
|
|
@@ -12627,13 +12308,285 @@ class BaseApi {
|
|
|
12627
12308
|
}
|
|
12628
12309
|
});
|
|
12629
12310
|
}
|
|
12630
|
-
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12311
|
+
}
|
|
12312
|
+
async function dynamicImports(modulePromise, exportNames) {
|
|
12313
|
+
const module = await modulePromise;
|
|
12314
|
+
const result = {};
|
|
12315
|
+
for (const _name of exportNames) {
|
|
12316
|
+
const name = _name || "default";
|
|
12317
|
+
if (name === "default") {
|
|
12318
|
+
result[name] = module.default ?? module;
|
|
12319
|
+
} else {
|
|
12320
|
+
if (!(name in module)) {
|
|
12321
|
+
throw new Error(`模块中不存在导出 "${name}"`);
|
|
12322
|
+
}
|
|
12323
|
+
result[name] = module[name];
|
|
12324
|
+
}
|
|
12325
|
+
}
|
|
12326
|
+
return result;
|
|
12327
|
+
}
|
|
12328
|
+
function createApiDialog(DialogComponent) {
|
|
12329
|
+
let container = null;
|
|
12330
|
+
let vnode = null;
|
|
12331
|
+
let isOpen = false;
|
|
12332
|
+
let currentReject = null;
|
|
12333
|
+
const DefaultDialog = defineComponent({
|
|
12334
|
+
name: "DefaultApiDialog",
|
|
12335
|
+
props: {
|
|
12336
|
+
modelValue: {
|
|
12337
|
+
type: Boolean,
|
|
12338
|
+
default: false
|
|
12339
|
+
},
|
|
12340
|
+
title: {
|
|
12341
|
+
type: String,
|
|
12342
|
+
default: "对话框"
|
|
12343
|
+
},
|
|
12344
|
+
width: {
|
|
12345
|
+
type: [String, Number],
|
|
12346
|
+
default: "50%"
|
|
12347
|
+
}
|
|
12348
|
+
},
|
|
12349
|
+
emits: ["close", "confirm", "update:modelValue"],
|
|
12350
|
+
setup(props, { slots, emit }) {
|
|
12351
|
+
const handleClose = () => {
|
|
12352
|
+
emit("close");
|
|
12353
|
+
emit("update:modelValue", false);
|
|
12354
|
+
};
|
|
12355
|
+
const handleConfirm = (data) => {
|
|
12356
|
+
emit("confirm", data);
|
|
12357
|
+
emit("update:modelValue", false);
|
|
12358
|
+
};
|
|
12359
|
+
return () => h(ElDialog, {
|
|
12360
|
+
"modelValue": props.modelValue,
|
|
12361
|
+
"title": props.title,
|
|
12362
|
+
"width": props.width,
|
|
12363
|
+
"onUpdate:modelValue": (val) => {
|
|
12364
|
+
emit("update:modelValue", val);
|
|
12365
|
+
if (!val) {
|
|
12366
|
+
handleClose();
|
|
12367
|
+
}
|
|
12368
|
+
}
|
|
12369
|
+
}, {
|
|
12370
|
+
default: () => {
|
|
12371
|
+
var _a2;
|
|
12372
|
+
return (_a2 = slots.default) == null ? void 0 : _a2.call(slots);
|
|
12373
|
+
},
|
|
12374
|
+
header: slots.header,
|
|
12375
|
+
footer: slots.footer || (() => h("div", { class: "dialog-footer" }, [
|
|
12376
|
+
h(ElButton, {
|
|
12377
|
+
onClick: () => handleClose()
|
|
12378
|
+
}, () => "取消"),
|
|
12379
|
+
h(ElButton, {
|
|
12380
|
+
type: "primary",
|
|
12381
|
+
onClick: () => handleConfirm({})
|
|
12382
|
+
}, () => "确定")
|
|
12383
|
+
]))
|
|
12384
|
+
});
|
|
12385
|
+
}
|
|
12386
|
+
});
|
|
12387
|
+
const FinalDialogComponent = DialogComponent || DefaultDialog;
|
|
12388
|
+
function createContainer() {
|
|
12389
|
+
const el = document.createElement("div");
|
|
12390
|
+
document.body.appendChild(el);
|
|
12391
|
+
return el;
|
|
12392
|
+
}
|
|
12393
|
+
function show(options = {}) {
|
|
12394
|
+
if (isOpen) {
|
|
12395
|
+
close2();
|
|
12396
|
+
}
|
|
12397
|
+
container = createContainer();
|
|
12398
|
+
const { props = {}, slots = {}, appContext } = options;
|
|
12399
|
+
return new Promise((resolve, reject) => {
|
|
12400
|
+
currentReject = reject;
|
|
12401
|
+
vnode = createVNode(
|
|
12402
|
+
FinalDialogComponent,
|
|
12403
|
+
{
|
|
12404
|
+
...props,
|
|
12405
|
+
modelValue: true,
|
|
12406
|
+
onUpdateModelValue: (val) => {
|
|
12407
|
+
if (!val) {
|
|
12408
|
+
reject(new Error("对话框已关闭"));
|
|
12409
|
+
cleanup();
|
|
12410
|
+
}
|
|
12411
|
+
},
|
|
12412
|
+
onClose: () => {
|
|
12413
|
+
reject(new Error("对话框已关闭"));
|
|
12414
|
+
cleanup();
|
|
12415
|
+
},
|
|
12416
|
+
onConfirm: (data) => {
|
|
12417
|
+
resolve(data);
|
|
12418
|
+
cleanup();
|
|
12419
|
+
}
|
|
12420
|
+
},
|
|
12421
|
+
slots
|
|
12422
|
+
);
|
|
12423
|
+
if (appContext) {
|
|
12424
|
+
vnode.appContext = appContext;
|
|
12425
|
+
}
|
|
12426
|
+
render(vnode, container);
|
|
12427
|
+
isOpen = true;
|
|
12428
|
+
});
|
|
12429
|
+
}
|
|
12430
|
+
function close2() {
|
|
12431
|
+
if (isOpen && vnode && container) {
|
|
12432
|
+
if (vnode.component && vnode.component.exposed && typeof vnode.component.exposed.close === "function") {
|
|
12433
|
+
vnode.component.exposed.close();
|
|
12434
|
+
}
|
|
12435
|
+
if (currentReject) {
|
|
12436
|
+
currentReject(new Error("对话框被主动关闭"));
|
|
12437
|
+
currentReject = null;
|
|
12438
|
+
}
|
|
12439
|
+
cleanup();
|
|
12440
|
+
}
|
|
12441
|
+
}
|
|
12442
|
+
function cleanup() {
|
|
12443
|
+
if (container) {
|
|
12444
|
+
render(null, container);
|
|
12445
|
+
container.remove();
|
|
12446
|
+
container = null;
|
|
12447
|
+
}
|
|
12448
|
+
vnode = null;
|
|
12449
|
+
isOpen = false;
|
|
12450
|
+
}
|
|
12451
|
+
if (!DialogComponent) {
|
|
12452
|
+
return {
|
|
12453
|
+
Dialog: DefaultDialog,
|
|
12454
|
+
show,
|
|
12455
|
+
close: close2
|
|
12456
|
+
};
|
|
12457
|
+
}
|
|
12458
|
+
return {
|
|
12459
|
+
show,
|
|
12460
|
+
close: close2
|
|
12461
|
+
};
|
|
12462
|
+
}
|
|
12463
|
+
const hasDocument = typeof document !== "undefined";
|
|
12464
|
+
let systemErrorDialogInstance = null;
|
|
12465
|
+
class BaseApi extends BaseHttpClient {
|
|
12466
|
+
constructor(config) {
|
|
12467
|
+
const {
|
|
12468
|
+
responseFields,
|
|
12469
|
+
enableSystemErrorDialog = true,
|
|
12470
|
+
...baseConfig
|
|
12471
|
+
} = config;
|
|
12472
|
+
super(baseConfig);
|
|
12473
|
+
__publicField(this, "responseFields");
|
|
12474
|
+
__publicField(this, "enableSystemErrorDialog");
|
|
12475
|
+
this.responseFields = {
|
|
12476
|
+
code: "Code",
|
|
12477
|
+
message: "Message",
|
|
12478
|
+
data: "data",
|
|
12479
|
+
errors: "errors",
|
|
12480
|
+
tips: "tips",
|
|
12481
|
+
...responseFields
|
|
12482
|
+
};
|
|
12483
|
+
this.enableSystemErrorDialog = enableSystemErrorDialog;
|
|
12484
|
+
}
|
|
12485
|
+
processRequestConfig(config) {
|
|
12486
|
+
return super.processRequestConfig(config);
|
|
12487
|
+
}
|
|
12488
|
+
async processResponseError(error) {
|
|
12489
|
+
return super.processResponseError(error);
|
|
12490
|
+
}
|
|
12491
|
+
processResponseConfig(response) {
|
|
12492
|
+
const data = response.data;
|
|
12493
|
+
const { code, message: message2, responseData } = this.parseResponseFields(data);
|
|
12494
|
+
this.handleErrorCode(response, code, message2, responseData);
|
|
12495
|
+
this.handleErrors(responseData);
|
|
12496
|
+
this.handleTips(responseData);
|
|
12497
|
+
return responseData;
|
|
12498
|
+
}
|
|
12499
|
+
parseResponseFields(data) {
|
|
12500
|
+
var _a2, _b, _c;
|
|
12501
|
+
const getValueByPath = (obj, path) => {
|
|
12502
|
+
if (!path)
|
|
12503
|
+
return obj;
|
|
12504
|
+
const keys = path.split(".");
|
|
12505
|
+
let result = obj;
|
|
12506
|
+
for (const key of keys) {
|
|
12507
|
+
if (result && typeof result === "object" && key in result) {
|
|
12508
|
+
result = result[key];
|
|
12509
|
+
} else {
|
|
12510
|
+
return void 0;
|
|
12511
|
+
}
|
|
12512
|
+
}
|
|
12513
|
+
return result;
|
|
12514
|
+
};
|
|
12515
|
+
const code = getValueByPath(data, (_a2 = this.responseFields) == null ? void 0 : _a2.code);
|
|
12516
|
+
const message2 = getValueByPath(data, (_b = this.responseFields) == null ? void 0 : _b.message);
|
|
12517
|
+
const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12518
|
+
return { code, message: message2, responseData };
|
|
12519
|
+
}
|
|
12520
|
+
handleErrorCode(response, code, message2, responseData) {
|
|
12521
|
+
var _a2;
|
|
12522
|
+
if (code === 401) {
|
|
12523
|
+
throw new Error("登录失效,请重新登录");
|
|
12524
|
+
}
|
|
12525
|
+
if (code === -1) {
|
|
12526
|
+
if (this.enableSystemErrorDialog) {
|
|
12527
|
+
this.showSystemExceptionDialog(response, responseData, code, message2).catch((error) => {
|
|
12528
|
+
console.error("显示系统异常对话框失败:", error);
|
|
12529
|
+
});
|
|
12530
|
+
}
|
|
12531
|
+
throw new Error(message2 || "系统异常");
|
|
12532
|
+
}
|
|
12533
|
+
if (code && code !== 200) {
|
|
12534
|
+
(_a2 = this.messageInstance) == null ? void 0 : _a2.error({
|
|
12535
|
+
message: message2 || "请求失败",
|
|
12536
|
+
duration: 5 * 1e3
|
|
12537
|
+
});
|
|
12538
|
+
throw new Error(message2 || "请求失败");
|
|
12539
|
+
}
|
|
12540
|
+
}
|
|
12541
|
+
handleErrors(responseData) {
|
|
12542
|
+
var _a2, _b, _c;
|
|
12543
|
+
const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
|
|
12544
|
+
if (errorsField) {
|
|
12545
|
+
const errors = responseData == null ? void 0 : responseData[errorsField];
|
|
12546
|
+
if (Array.isArray(errors) && errors.length) {
|
|
12547
|
+
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12548
|
+
if (hasDocument) {
|
|
12549
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
|
|
12550
|
+
title: "提示",
|
|
12551
|
+
message: html,
|
|
12552
|
+
type: "error"
|
|
12553
|
+
});
|
|
12554
|
+
} else {
|
|
12555
|
+
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12556
|
+
(_c = this.notificationInstance) == null ? void 0 : _c.call(this, {
|
|
12557
|
+
title: "提示",
|
|
12558
|
+
message: errorMessages,
|
|
12559
|
+
type: "error"
|
|
12560
|
+
});
|
|
12561
|
+
}
|
|
12562
|
+
throw new Error("请求错误");
|
|
12563
|
+
}
|
|
12564
|
+
}
|
|
12565
|
+
}
|
|
12566
|
+
handleTips(responseData) {
|
|
12567
|
+
var _a2, _b, _c;
|
|
12568
|
+
const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
|
|
12569
|
+
if (tipsField) {
|
|
12570
|
+
const tips = responseData == null ? void 0 : responseData[tipsField];
|
|
12571
|
+
if (Array.isArray(tips) && tips.length) {
|
|
12572
|
+
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12573
|
+
if (hasDocument) {
|
|
12574
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
|
|
12575
|
+
title: "提示",
|
|
12576
|
+
message: html,
|
|
12577
|
+
type: "warning"
|
|
12578
|
+
});
|
|
12579
|
+
} else {
|
|
12580
|
+
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12581
|
+
(_c = this.notificationInstance) == null ? void 0 : _c.call(this, {
|
|
12582
|
+
title: "提示",
|
|
12583
|
+
message: tipMessages,
|
|
12584
|
+
type: "warning"
|
|
12585
|
+
});
|
|
12586
|
+
}
|
|
12587
|
+
}
|
|
12588
|
+
}
|
|
12589
|
+
}
|
|
12637
12590
|
async showSystemExceptionDialog(response, responseData, code, message2) {
|
|
12638
12591
|
if (!hasDocument) {
|
|
12639
12592
|
console.error("系统异常信息:", responseData);
|
|
@@ -12672,10 +12625,6 @@ class BaseApi {
|
|
|
12672
12625
|
console.error("系统异常信息:", responseData);
|
|
12673
12626
|
}
|
|
12674
12627
|
}
|
|
12675
|
-
/**
|
|
12676
|
-
* 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
|
|
12677
|
-
* @param errorInfo - 错误信息对象
|
|
12678
|
-
*/
|
|
12679
12628
|
async reportError(errorInfo) {
|
|
12680
12629
|
var _a2, _b;
|
|
12681
12630
|
try {
|
|
@@ -12698,11 +12647,6 @@ function createHttpService(options = {}) {
|
|
|
12698
12647
|
return new BaseApi(options);
|
|
12699
12648
|
}
|
|
12700
12649
|
const VueAxiosPlugin = {
|
|
12701
|
-
/**
|
|
12702
|
-
* 安装插件
|
|
12703
|
-
* @param app - Vue 应用实例
|
|
12704
|
-
* @param options - 插件配置选项
|
|
12705
|
-
*/
|
|
12706
12650
|
install(app, options = {}) {
|
|
12707
12651
|
const httpService = createHttpService(options.default ?? {});
|
|
12708
12652
|
app.config.globalProperties.$http = httpService;
|
|
@@ -12883,12 +12827,10 @@ const SystemErrorDialog = defineComponent({
|
|
|
12883
12827
|
h("span", { style: { fontWeight: "bold", fontSize: "16px" } }, props.title || "系统异常信息")
|
|
12884
12828
|
]),
|
|
12885
12829
|
default: () => h("div", { style: { padding: 0, maxHeight: "500px", overflowY: "auto" } }, [
|
|
12886
|
-
// 第一块:无法完成您的请求
|
|
12887
12830
|
h("div", { style: { padding: "20px", borderBottom: "1px solid #ebeef5" } }, [
|
|
12888
12831
|
h("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: "bold", color: "#303133" } }, "无法完成您的请求"),
|
|
12889
12832
|
h("p", { style: { margin: 0, color: "#606266", lineHeight: 1.5 } }, "系统在处理您的请求时遇到了问题,可能是由于服务暂时不可用。")
|
|
12890
12833
|
]),
|
|
12891
|
-
// 第二块:技术摘要(可展开)
|
|
12892
12834
|
h("div", { style: { borderBottom: "1px solid #ebeef5" } }, [
|
|
12893
12835
|
h(
|
|
12894
12836
|
"div",
|
|
@@ -12950,7 +12892,6 @@ const SystemErrorDialog = defineComponent({
|
|
|
12950
12892
|
)
|
|
12951
12893
|
) : null
|
|
12952
12894
|
]),
|
|
12953
|
-
// SkyWalking 按钮
|
|
12954
12895
|
h("div", { style: { padding: "16px 20px", borderBottom: "1px solid #ebeef5" } }, [
|
|
12955
12896
|
h(
|
|
12956
12897
|
ElButton,
|
|
@@ -12962,7 +12903,6 @@ const SystemErrorDialog = defineComponent({
|
|
|
12962
12903
|
{ default: () => "📊 在SkyWalking中查看详情" }
|
|
12963
12904
|
)
|
|
12964
12905
|
]),
|
|
12965
|
-
// 黑色错误信息区域
|
|
12966
12906
|
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" } }, [
|
|
12967
12907
|
h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
|
|
12968
12908
|
h("div", { style: { color: "#e74c3c", fontWeight: "bold" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
|
|
@@ -12998,6 +12938,7 @@ const SystemErrorDialog$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object
|
|
|
12998
12938
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
12999
12939
|
export {
|
|
13000
12940
|
BaseApi,
|
|
12941
|
+
BaseHttpClient,
|
|
13001
12942
|
VueAxiosPlugin,
|
|
13002
12943
|
createHttpService,
|
|
13003
12944
|
getHttpService as default,
|
package/es/netseriver.d.ts
CHANGED
|
@@ -5,22 +5,8 @@ declare global {
|
|
|
5
5
|
$http?: vueHttpServiceType;
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
/**
|
|
9
|
-
* 创建 HTTP 服务实例
|
|
10
|
-
* @param options - API 配置对象
|
|
11
|
-
* @returns BaseApi 实例
|
|
12
|
-
*/
|
|
13
8
|
declare function createHttpService(options?: BaseApiConfig): BaseApi;
|
|
14
|
-
/**
|
|
15
|
-
* Vue Axios 插件,用于在 Vue 应用中全局注册 HTTP 服务
|
|
16
|
-
* 提供 this.$http、inject('$http') 和 window.$http 三种使用方式
|
|
17
|
-
*/
|
|
18
9
|
declare const VueAxiosPlugin: vueAxiosPluginType;
|
|
19
|
-
/**
|
|
20
|
-
* 获取 HTTP 服务实例,与 createHttpService 功能相同
|
|
21
|
-
* @param options - API 配置对象
|
|
22
|
-
* @returns BaseApi 实例
|
|
23
|
-
*/
|
|
24
10
|
declare function getHttpService(options?: BaseApiConfig): BaseApi;
|
|
25
11
|
export default VueAxiosPlugin;
|
|
26
12
|
export { createHttpService, getHttpService };
|