@moluoxixi/ajax-package 0.0.11-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1016 -0
- package/es/SystemErrorDialog.d.ts +129 -0
- package/es/_types/api.d.ts +58 -0
- package/es/_types/emits.d.ts +13 -0
- package/es/_types/index.d.ts +4 -0
- package/es/_types/props.d.ts +27 -0
- package/es/_utils/index.d.ts +3 -0
- package/es/_utils/messageWrapper.d.ts +39 -0
- package/es/_utils/notificationWrapper.d.ts +12 -0
- package/es/_utils/systemErrorInfo.d.ts +27 -0
- package/es/class.d.ts +114 -0
- package/es/index.d.ts +4 -0
- package/es/index.mjs +13005 -0
- package/es/netseriver.d.ts +26 -0
- package/package.json +33 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemErrorDialog 组件
|
|
3
|
+
* 使用 defineComponent 和 h 函数实现
|
|
4
|
+
*/
|
|
5
|
+
declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
|
|
6
|
+
title: {
|
|
7
|
+
type: StringConstructor;
|
|
8
|
+
default: string;
|
|
9
|
+
};
|
|
10
|
+
width: {
|
|
11
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
12
|
+
default: number;
|
|
13
|
+
};
|
|
14
|
+
userName: {
|
|
15
|
+
type: StringConstructor;
|
|
16
|
+
default: undefined;
|
|
17
|
+
};
|
|
18
|
+
userId: {
|
|
19
|
+
type: StringConstructor;
|
|
20
|
+
default: undefined;
|
|
21
|
+
};
|
|
22
|
+
deptName: {
|
|
23
|
+
type: StringConstructor;
|
|
24
|
+
default: undefined;
|
|
25
|
+
};
|
|
26
|
+
deptId: {
|
|
27
|
+
type: StringConstructor;
|
|
28
|
+
default: undefined;
|
|
29
|
+
};
|
|
30
|
+
clientIp: {
|
|
31
|
+
type: StringConstructor;
|
|
32
|
+
default: undefined;
|
|
33
|
+
};
|
|
34
|
+
requestUrl: {
|
|
35
|
+
type: StringConstructor;
|
|
36
|
+
default: undefined;
|
|
37
|
+
};
|
|
38
|
+
traceId: {
|
|
39
|
+
type: StringConstructor;
|
|
40
|
+
default: undefined;
|
|
41
|
+
};
|
|
42
|
+
errorMessage: {
|
|
43
|
+
type: StringConstructor;
|
|
44
|
+
default: undefined;
|
|
45
|
+
};
|
|
46
|
+
errorCode: {
|
|
47
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
48
|
+
default: undefined;
|
|
49
|
+
};
|
|
50
|
+
modelValue: {
|
|
51
|
+
type: BooleanConstructor;
|
|
52
|
+
default: boolean;
|
|
53
|
+
};
|
|
54
|
+
}>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
}>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {
|
|
57
|
+
'update:modelValue': (val: boolean) => true;
|
|
58
|
+
close: () => true;
|
|
59
|
+
confirm: (data: any) => true;
|
|
60
|
+
report: () => true;
|
|
61
|
+
}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
|
|
62
|
+
title: {
|
|
63
|
+
type: StringConstructor;
|
|
64
|
+
default: string;
|
|
65
|
+
};
|
|
66
|
+
width: {
|
|
67
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
68
|
+
default: number;
|
|
69
|
+
};
|
|
70
|
+
userName: {
|
|
71
|
+
type: StringConstructor;
|
|
72
|
+
default: undefined;
|
|
73
|
+
};
|
|
74
|
+
userId: {
|
|
75
|
+
type: StringConstructor;
|
|
76
|
+
default: undefined;
|
|
77
|
+
};
|
|
78
|
+
deptName: {
|
|
79
|
+
type: StringConstructor;
|
|
80
|
+
default: undefined;
|
|
81
|
+
};
|
|
82
|
+
deptId: {
|
|
83
|
+
type: StringConstructor;
|
|
84
|
+
default: undefined;
|
|
85
|
+
};
|
|
86
|
+
clientIp: {
|
|
87
|
+
type: StringConstructor;
|
|
88
|
+
default: undefined;
|
|
89
|
+
};
|
|
90
|
+
requestUrl: {
|
|
91
|
+
type: StringConstructor;
|
|
92
|
+
default: undefined;
|
|
93
|
+
};
|
|
94
|
+
traceId: {
|
|
95
|
+
type: StringConstructor;
|
|
96
|
+
default: undefined;
|
|
97
|
+
};
|
|
98
|
+
errorMessage: {
|
|
99
|
+
type: StringConstructor;
|
|
100
|
+
default: undefined;
|
|
101
|
+
};
|
|
102
|
+
errorCode: {
|
|
103
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
104
|
+
default: undefined;
|
|
105
|
+
};
|
|
106
|
+
modelValue: {
|
|
107
|
+
type: BooleanConstructor;
|
|
108
|
+
default: boolean;
|
|
109
|
+
};
|
|
110
|
+
}>> & Readonly<{
|
|
111
|
+
"onUpdate:modelValue"?: ((val: boolean) => any) | undefined;
|
|
112
|
+
onClose?: (() => any) | undefined;
|
|
113
|
+
onConfirm?: ((data: any) => any) | undefined;
|
|
114
|
+
onReport?: (() => any) | undefined;
|
|
115
|
+
}>, {
|
|
116
|
+
title: string;
|
|
117
|
+
width: string | number;
|
|
118
|
+
userName: string;
|
|
119
|
+
userId: string;
|
|
120
|
+
deptName: string;
|
|
121
|
+
deptId: string;
|
|
122
|
+
clientIp: string;
|
|
123
|
+
requestUrl: string;
|
|
124
|
+
traceId: string;
|
|
125
|
+
errorMessage: string;
|
|
126
|
+
errorCode: string | number;
|
|
127
|
+
modelValue: boolean;
|
|
128
|
+
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
129
|
+
export default _default;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { App } from 'vue';
|
|
2
|
+
import { default as BaseApi } from '../class.ts';
|
|
3
|
+
/**
|
|
4
|
+
* BaseApi 配置接口,用于配置 BaseApi 实例的所有选项
|
|
5
|
+
*/
|
|
6
|
+
export interface BaseApiConfig {
|
|
7
|
+
/** API 基础地址 */
|
|
8
|
+
baseURL?: string;
|
|
9
|
+
/** 请求超时时间(毫秒),默认 5000 */
|
|
10
|
+
timeout?: number;
|
|
11
|
+
/** 响应字段映射配置 */
|
|
12
|
+
responseFields?: {
|
|
13
|
+
/** 响应状态码字段名,默认 'Code' */
|
|
14
|
+
code?: string;
|
|
15
|
+
/** 响应消息字段名,默认 'Message' */
|
|
16
|
+
message?: string;
|
|
17
|
+
/** 响应数据字段名,默认 'data' */
|
|
18
|
+
data?: string;
|
|
19
|
+
/** 错误数组字段名 */
|
|
20
|
+
errors?: string;
|
|
21
|
+
/** 提示信息字段名 */
|
|
22
|
+
tips?: string;
|
|
23
|
+
};
|
|
24
|
+
/** 请求超时回调函数 */
|
|
25
|
+
onTimeout?: () => void;
|
|
26
|
+
/** 获取 token 的函数,每次请求前自动调用 */
|
|
27
|
+
getToken?: () => string | null;
|
|
28
|
+
/** 登录失效回调函数,当检测到 401 错误时调用 */
|
|
29
|
+
onLoginRequired?: () => void;
|
|
30
|
+
/** 是否启用 code === -1 的系统异常弹窗,默认为 true */
|
|
31
|
+
enableSystemErrorDialog?: boolean;
|
|
32
|
+
/** 允许其他任意配置项,会直接传递给 axios.create */
|
|
33
|
+
[key: string]: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Vue Axios 插件配置选项
|
|
37
|
+
*/
|
|
38
|
+
export interface vueAxiosPluginOptionsType {
|
|
39
|
+
/** 默认 HTTP 服务配置 */
|
|
40
|
+
default?: BaseApiConfig;
|
|
41
|
+
/** 是否在所有组件中通过 mixin 注入 $http,默认为 true */
|
|
42
|
+
globalMixin?: boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Vue HTTP 服务类型,在 Vue 应用中通过 this.$http 或 inject('$http') 获取
|
|
46
|
+
*/
|
|
47
|
+
export type vueHttpServiceType = BaseApi;
|
|
48
|
+
/**
|
|
49
|
+
* Vue Axios 插件类型,定义了 Vue 插件的标准接口
|
|
50
|
+
*/
|
|
51
|
+
export interface vueAxiosPluginType {
|
|
52
|
+
/**
|
|
53
|
+
* 安装插件
|
|
54
|
+
* @param app - Vue 应用实例
|
|
55
|
+
* @param options - 插件配置选项
|
|
56
|
+
*/
|
|
57
|
+
install: (app: App, options?: vueAxiosPluginOptionsType) => void;
|
|
58
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemErrorDialog 组件的 Emits 类型定义
|
|
3
|
+
*/
|
|
4
|
+
export interface SystemErrorDialogEmitsType {
|
|
5
|
+
/** v-model 更新事件 */
|
|
6
|
+
'update:modelValue': [val: boolean];
|
|
7
|
+
/** 关闭事件 */
|
|
8
|
+
'close': [];
|
|
9
|
+
/** 确认事件 */
|
|
10
|
+
'confirm': [data: any];
|
|
11
|
+
/** 上报事件 */
|
|
12
|
+
'report': [];
|
|
13
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SystemErrorDialog 组件的 Props 类型定义
|
|
3
|
+
*/
|
|
4
|
+
export interface SystemErrorDialogPropsType {
|
|
5
|
+
/** 对话框标题 */
|
|
6
|
+
title?: string;
|
|
7
|
+
/** 对话框宽度 */
|
|
8
|
+
width?: number | string;
|
|
9
|
+
/** 用户名 */
|
|
10
|
+
userName?: string;
|
|
11
|
+
/** 用户ID */
|
|
12
|
+
userId?: string;
|
|
13
|
+
/** 科室名称 */
|
|
14
|
+
deptName?: string;
|
|
15
|
+
/** 科室ID */
|
|
16
|
+
deptId?: string;
|
|
17
|
+
/** 客户端IP地址 */
|
|
18
|
+
clientIp?: string;
|
|
19
|
+
/** 请求URL路径 */
|
|
20
|
+
requestUrl?: string;
|
|
21
|
+
/** 链路追踪ID */
|
|
22
|
+
traceId?: string;
|
|
23
|
+
/** 错误消息 */
|
|
24
|
+
errorMessage?: string;
|
|
25
|
+
/** 错误代码 */
|
|
26
|
+
errorCode?: number | string;
|
|
27
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建消息实例的包装函数
|
|
3
|
+
* @returns 消息实例,支持 success、error、warning、info 方法
|
|
4
|
+
*/
|
|
5
|
+
export declare function createMessageWrapper(): (import('element-plus').MessageFn & {
|
|
6
|
+
primary: import('element-plus').MessageTypedFn;
|
|
7
|
+
success: import('element-plus').MessageTypedFn;
|
|
8
|
+
warning: import('element-plus').MessageTypedFn;
|
|
9
|
+
info: import('element-plus').MessageTypedFn;
|
|
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
|
+
};
|
|
39
|
+
export type MessageInstance = ReturnType<typeof createMessageWrapper>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 创建通知实例的包装函数(用于 errors / tips 展示)
|
|
3
|
+
* @returns 通知实例,支持 success、error、warning、info 方法
|
|
4
|
+
*/
|
|
5
|
+
export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
|
|
6
|
+
_context: import('vue').AppContext | null;
|
|
7
|
+
}) | ((options: string | {
|
|
8
|
+
message?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
type?: "success" | "error" | "warning" | "info";
|
|
11
|
+
}) => void);
|
|
12
|
+
export type NotificationInstance = ReturnType<typeof createNotificationWrapper>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AxiosResponse } from 'axios';
|
|
2
|
+
import { SystemErrorDialogPropsType } from '../_types/index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* 规范化请求参数对象
|
|
5
|
+
* @param payload 请求参数
|
|
6
|
+
* @returns 规范化后的对象
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizePayload(payload: any): Record<string, any>;
|
|
9
|
+
/**
|
|
10
|
+
* 解析响应头中的 TraceId
|
|
11
|
+
* @param headers 响应头
|
|
12
|
+
* @returns TraceId 字符串
|
|
13
|
+
*/
|
|
14
|
+
export declare function resolveTraceId(headers: AxiosResponse['headers'] | undefined): string;
|
|
15
|
+
/**
|
|
16
|
+
* 从 localStorage 中读取 userInfo
|
|
17
|
+
* @returns userInfo 对象,如果不存在则返回空对象
|
|
18
|
+
*/
|
|
19
|
+
export declare function getUserInfoFromLocalStorage(): Record<string, any>;
|
|
20
|
+
/**
|
|
21
|
+
* 从 AxiosResponse 中提取系统错误信息
|
|
22
|
+
* @param response Axios 响应对象
|
|
23
|
+
* @param code 错误代码
|
|
24
|
+
* @param message 错误消息
|
|
25
|
+
* @returns 提取的错误信息
|
|
26
|
+
*/
|
|
27
|
+
export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
|
package/es/class.d.ts
ADDED
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, default as axios } from 'axios';
|
|
2
|
+
import { BaseApiConfig } from './_types/index.ts';
|
|
3
|
+
import { MessageInstance, NotificationInstance } from './_utils/index.ts';
|
|
4
|
+
/**
|
|
5
|
+
* BaseApi 类
|
|
6
|
+
* 基于 axios 封装的 HTTP 请求类,提供统一的请求处理、错误处理和响应解析
|
|
7
|
+
*/
|
|
8
|
+
export default class BaseApi {
|
|
9
|
+
protected baseURL: string;
|
|
10
|
+
protected timeout: number;
|
|
11
|
+
protected responseFields: Required<BaseApiConfig['responseFields']>;
|
|
12
|
+
protected onTimeout: () => void;
|
|
13
|
+
protected getToken?: () => string | null;
|
|
14
|
+
protected onLoginRequired?: () => void;
|
|
15
|
+
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
|
+
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
|
+
*/
|
|
42
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
43
|
+
/**
|
|
44
|
+
* 设置请求和响应拦截器
|
|
45
|
+
* 请求拦截器:自动添加 Token
|
|
46
|
+
* 响应拦截器:处理成功响应和错误响应(401、超时等)
|
|
47
|
+
*/
|
|
48
|
+
private setupInterceptors;
|
|
49
|
+
/**
|
|
50
|
+
* 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
|
|
51
|
+
* @param config - Axios 请求配置对象
|
|
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
|
+
*/
|
|
108
|
+
private showSystemExceptionDialog;
|
|
109
|
+
/**
|
|
110
|
+
* 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
|
|
111
|
+
* @param errorInfo - 错误信息对象
|
|
112
|
+
*/
|
|
113
|
+
private reportError;
|
|
114
|
+
}
|
package/es/index.d.ts
ADDED