@moluoxixi/ajax-package 0.0.13 → 0.0.14-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.
@@ -1,6 +1,15 @@
1
1
  import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig, default as axios } from 'axios';
2
2
  import { BaseHttpClientConfig } from './_types/index.ts';
3
3
  import { MessageInstance, NotificationInstance } from './_utils/index.ts';
4
+ /**
5
+ * BaseHttpClient 基础类
6
+ * 提供最基础的 HTTP 请求功能,包括:
7
+ * - 创建 axios 实例
8
+ * - 自动添加 Token
9
+ * - 基础错误处理(401、超时等)
10
+ * - HTTP 方法(get、post、put、delete、all)
11
+ * - 文件上传
12
+ */
4
13
  export default class BaseHttpClient {
5
14
  protected baseURL: string;
6
15
  protected timeout: number;
@@ -10,22 +19,124 @@ export default class BaseHttpClient {
10
19
  instance: ReturnType<typeof axios.create>;
11
20
  protected messageInstance: MessageInstance;
12
21
  protected notificationInstance: NotificationInstance;
22
+ /**
23
+ * 创建 BaseHttpClient 实例
24
+ * @param config - HTTP 客户端配置对象
25
+ */
13
26
  constructor(config: BaseHttpClientConfig);
27
+ /**
28
+ * 处理请求配置,子类可重写此方法自定义请求配置
29
+ * @param config - 请求配置对象
30
+ * @returns 处理后的请求配置
31
+ */
14
32
  processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
33
+ /**
34
+ * 处理响应配置,子类可重写此方法自定义响应处理
35
+ * 按照标准 HTTP 结构处理响应
36
+ * @param response - Axios 响应对象
37
+ * @returns 解析后的响应数据
38
+ */
15
39
  processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
40
+ /**
41
+ * 处理 HTTP 状态码
42
+ * 子类可重写此方法来自定义 HTTP 状态码处理逻辑
43
+ * @param response - Axios 响应对象
44
+ */
16
45
  protected handleHttpStatus(response: AxiosResponse): void;
46
+ /**
47
+ * 处理成功响应
48
+ * 子类可重写此方法来自定义成功响应的处理逻辑
49
+ * @param response - Axios 响应对象
50
+ * @returns 解析后的响应数据
51
+ */
17
52
  protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
53
+ /**
54
+ * 处理响应错误,子类可重写此方法自定义错误处理
55
+ * 按照标准 HTTP 错误结构处理错误
56
+ * @param error - Axios 错误对象
57
+ * @returns 处理后的错误对象
58
+ */
18
59
  processResponseError(error: AxiosError): Promise<AxiosError>;
60
+ /**
61
+ * 处理认证错误(401 - 未授权/登录失效)
62
+ * 子类可重写此方法来自定义认证错误处理逻辑
63
+ * @param error - Axios 错误对象
64
+ */
19
65
  protected handleAuthenticationError(error: AxiosError): void;
66
+ /**
67
+ * 处理超时错误
68
+ * 子类可重写此方法来自定义超时错误处理逻辑
69
+ * @param error - Axios 错误对象
70
+ */
20
71
  protected handleTimeoutError(error: AxiosError): void;
72
+ /**
73
+ * 处理网络错误(其他错误)
74
+ * 子类可重写此方法来自定义网络错误处理逻辑
75
+ * @param error - Axios 错误对象
76
+ */
21
77
  protected handleNetworkError(error: AxiosError): void;
78
+ /**
79
+ * 设置请求和响应拦截器
80
+ * 请求拦截器:自动添加 Token
81
+ * 响应拦截器:处理成功响应和错误响应(401、超时等)
82
+ */
22
83
  private setupInterceptors;
84
+ /**
85
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
86
+ * @param config - Axios 请求配置对象
87
+ * @returns 解析后的响应数据
88
+ */
23
89
  protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
90
+ /**
91
+ * 发送 GET 请求
92
+ * @param url - 请求 URL 路径
93
+ * @param params - 查询参数对象
94
+ * @param config - 额外的请求配置
95
+ * @returns 解析后的响应数据
96
+ */
24
97
  get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
98
+ /**
99
+ * 发送 POST 请求
100
+ * @param url - 请求 URL 路径
101
+ * @param data - 请求体数据
102
+ * @param config - 额外的请求配置
103
+ * @returns 解析后的响应数据
104
+ */
25
105
  post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
106
+ /**
107
+ * 发送 DELETE 请求
108
+ * @param url - 请求 URL 路径
109
+ * @param params - 查询参数对象
110
+ * @param config - 额外的请求配置
111
+ * @returns 解析后的响应数据
112
+ */
26
113
  delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
114
+ /**
115
+ * 发送 PUT 请求
116
+ * @param url - 请求 URL 路径
117
+ * @param data - 请求体数据
118
+ * @param config - 额外的请求配置
119
+ * @returns 解析后的响应数据
120
+ */
27
121
  put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
122
+ /**
123
+ * 批量请求,并发发送多个请求
124
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
125
+ * @returns 所有请求的响应数据数组
126
+ */
28
127
  all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
128
+ /**
129
+ * 文件上传,将文件包装为 FormData 发送
130
+ * @param url - 上传地址
131
+ * @param file - 文件对象
132
+ * @param config - 额外的请求配置
133
+ * @returns 解析后的响应数据
134
+ */
29
135
  uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
136
+ /**
137
+ * 下载文件,将 Blob 对象下载到本地
138
+ * @param blob - Blob 对象
139
+ * @param filename - 文件名,如果不提供则使用时间戳
140
+ */
30
141
  downloadFile(blob: Blob, filename?: string): void;
31
142
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * SystemErrorDialog 组件
3
+ * 使用 defineComponent 和 h 函数实现
4
+ */
1
5
  declare const _default: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
2
6
  title: {
3
7
  type: StringConstructor;
@@ -1,29 +1,65 @@
1
1
  import { App } from 'vue';
2
2
  import { MessageInstance } from '../_utils/index.ts';
3
3
  import { default as BaseApi } from '../class.ts';
4
+ /**
5
+ * BaseHttpClient 基础配置接口,包含最基础的 HTTP 客户端配置
6
+ */
4
7
  export interface BaseHttpClientConfig {
8
+ /** API 基础地址 */
5
9
  baseURL?: string;
10
+ /** 请求超时时间(毫秒),默认 5000 */
6
11
  timeout?: number;
12
+ /** 请求超时回调函数,接收 messageInstance 用于显示消息提示 */
7
13
  onTimeout?: (messageInstance: MessageInstance) => void;
14
+ /** 获取 token 的函数,每次请求前自动调用 */
8
15
  getToken?: () => string | null;
16
+ /** 登录失效回调函数,当检测到 401 错误时调用,接收 messageInstance 用于显示消息提示 */
9
17
  onLoginRequired?: (messageInstance: MessageInstance) => void;
18
+ /** 允许其他任意配置项,会直接传递给 axios.create */
10
19
  [key: string]: any;
11
20
  }
21
+ /**
22
+ * BaseApi 配置接口,用于配置 BaseApi 实例的所有选项
23
+ * 继承 BaseHttpClientConfig,添加响应字段映射和系统异常弹窗配置
24
+ */
12
25
  export interface BaseApiConfig extends BaseHttpClientConfig {
26
+ /** 响应字段映射配置 */
13
27
  responseFields?: {
28
+ /** 响应状态码字段名,默认 'Code' */
14
29
  code?: string;
30
+ /** 响应消息字段名,默认 'Message' */
15
31
  message?: string;
32
+ /** 响应数据字段名,默认 'data' */
16
33
  data?: string;
34
+ /** 错误数组字段名 */
17
35
  errors?: string;
36
+ /** 提示信息字段名 */
18
37
  tips?: string;
19
38
  };
39
+ /** 是否启用 code === -1 的系统异常弹窗,默认为 true */
20
40
  enableSystemErrorDialog?: boolean;
21
41
  }
42
+ /**
43
+ * Vue Axios 插件配置选项
44
+ */
22
45
  export interface vueAxiosPluginOptionsType {
46
+ /** 默认 HTTP 服务配置 */
23
47
  default?: BaseApiConfig;
48
+ /** 是否在所有组件中通过 mixin 注入 $http,默认为 true */
24
49
  globalMixin?: boolean;
25
50
  }
51
+ /**
52
+ * Vue HTTP 服务类型,在 Vue 应用中通过 this.$http 或 inject('$http') 获取
53
+ */
26
54
  export type vueHttpServiceType = BaseApi;
55
+ /**
56
+ * Vue Axios 插件类型,定义了 Vue 插件的标准接口
57
+ */
27
58
  export interface vueAxiosPluginType {
59
+ /**
60
+ * 安装插件
61
+ * @param app - Vue 应用实例
62
+ * @param options - 插件配置选项
63
+ */
28
64
  install: (app: App, options?: vueAxiosPluginOptionsType) => void;
29
65
  }
@@ -1,6 +1,13 @@
1
+ /**
2
+ * SystemErrorDialog 组件的 Emits 类型定义
3
+ */
1
4
  export interface SystemErrorDialogEmitsType {
5
+ /** v-model 更新事件 */
2
6
  'update:modelValue': [val: boolean];
7
+ /** 关闭事件 */
3
8
  'close': [];
9
+ /** 确认事件 */
4
10
  'confirm': [data: any];
11
+ /** 上报事件 */
5
12
  'report': [];
6
13
  }
@@ -1,13 +1,27 @@
1
+ /**
2
+ * SystemErrorDialog 组件的 Props 类型定义
3
+ */
1
4
  export interface SystemErrorDialogPropsType {
5
+ /** 对话框标题 */
2
6
  title?: string;
7
+ /** 对话框宽度 */
3
8
  width?: number | string;
9
+ /** 用户名 */
4
10
  userName?: string;
11
+ /** 用户ID */
5
12
  userId?: string;
13
+ /** 科室名称 */
6
14
  deptName?: string;
15
+ /** 科室ID */
7
16
  deptId?: string;
17
+ /** 客户端IP地址 */
8
18
  clientIp?: string;
19
+ /** 请求URL路径 */
9
20
  requestUrl?: string;
21
+ /** 链路追踪ID */
10
22
  traceId?: string;
23
+ /** 错误消息 */
11
24
  errorMessage?: string;
25
+ /** 错误代码 */
12
26
  errorCode?: number | string;
13
27
  }
@@ -1,3 +1,7 @@
1
+ /**
2
+ * 创建消息实例的包装函数
3
+ * @returns 消息实例,支持 success、error、warning、info 方法
4
+ */
1
5
  export declare function createMessageWrapper(): (import('element-plus').MessageFn & {
2
6
  primary: import('element-plus').MessageTypedFn;
3
7
  success: import('element-plus').MessageTypedFn;
@@ -1,3 +1,7 @@
1
+ /**
2
+ * 创建通知实例的包装函数(用于 errors / tips 展示)
3
+ * @returns 通知实例,支持 success、error、warning、info 方法
4
+ */
1
5
  export declare function createNotificationWrapper(): ((import('element-plus').Notify & import('vue').Plugin) & {
2
6
  _context: import('vue').AppContext | null;
3
7
  }) | ((options: string | {
@@ -1,6 +1,27 @@
1
1
  import { AxiosResponse } from 'axios';
2
2
  import { SystemErrorDialogPropsType } from '../_types/index.ts';
3
+ /**
4
+ * 规范化请求参数对象
5
+ * @param payload 请求参数
6
+ * @returns 规范化后的对象
7
+ */
3
8
  export declare function normalizePayload(payload: any): Record<string, any>;
9
+ /**
10
+ * 解析响应头中的 TraceId
11
+ * @param headers 响应头
12
+ * @returns TraceId 字符串
13
+ */
4
14
  export declare function resolveTraceId(headers: AxiosResponse['headers'] | undefined): string;
15
+ /**
16
+ * 从 localStorage 中读取 userInfo
17
+ * @returns userInfo 对象,如果不存在则返回空对象
18
+ */
5
19
  export declare function getUserInfoFromLocalStorage(): Record<string, any>;
20
+ /**
21
+ * 从 AxiosResponse 中提取系统错误信息
22
+ * @param response Axios 响应对象
23
+ * @param code 错误代码
24
+ * @param message 错误消息
25
+ * @returns 提取的错误信息
26
+ */
6
27
  export declare function extractSystemErrorInfo(response: AxiosResponse, code: number, message: string): Omit<SystemErrorDialogPropsType, 'title' | 'width'>;
package/es/class.d.ts CHANGED
@@ -1,34 +1,208 @@
1
- import { AxiosError, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
1
+ import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
2
  import { BaseApiConfig } from './_types/index.ts';
3
3
  import { default as BaseHttpClient } from './BaseHttpClient.ts';
4
+ /**
5
+ * BaseApi 类
6
+ * 继承 BaseHttpClient,提供增强的响应解析和错误处理功能
7
+ * 包括:响应字段映射、错误码处理、系统异常弹窗等
8
+ */
4
9
  export default class BaseApi extends BaseHttpClient {
5
10
  protected responseFields: Required<BaseApiConfig['responseFields']>;
6
11
  protected enableSystemErrorDialog: boolean;
12
+ /**
13
+ * 创建 BaseApi 实例
14
+ * @param config - API 配置对象
15
+ */
7
16
  constructor(config: BaseApiConfig);
17
+ /**
18
+ * 处理请求配置,子类可重写此方法自定义请求配置
19
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
20
+ * @param config - 请求配置对象
21
+ * @returns 处理后的请求配置
22
+ */
8
23
  processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
24
+ /**
25
+ * 处理响应配置,子类可重写此方法自定义响应处理
26
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
27
+ * @param response - Axios 响应对象
28
+ * @returns 解析后的响应数据
29
+ */
30
+ processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
31
+ /**
32
+ * 处理响应错误,子类可重写此方法自定义错误处理
33
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
34
+ * @param error - Axios 错误对象
35
+ * @returns 处理后的错误对象
36
+ */
9
37
  processResponseError(error: AxiosError): Promise<AxiosError>;
38
+ /**
39
+ * 处理 HTTP 状态码
40
+ * 重写父类方法,确保子类可以重写此方法
41
+ * @param response - Axios 响应对象
42
+ */
10
43
  protected handleHttpStatus(response: AxiosResponse): void;
44
+ /**
45
+ * 处理认证错误(401 - 未授权/登录失效)
46
+ * 重写父类方法,处理 HTTP 401 错误
47
+ * 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
48
+ * @param error - Axios 错误对象
49
+ */
11
50
  protected handleAuthenticationError(error: AxiosError): void;
51
+ /**
52
+ * 处理超时错误
53
+ * 重写父类方法,确保子类可以重写此方法
54
+ * @param error - Axios 错误对象
55
+ */
12
56
  protected handleTimeoutError(error: AxiosError): void;
57
+ /**
58
+ * 处理网络错误(其他错误)
59
+ * 重写父类方法,确保子类可以重写此方法
60
+ * @param error - Axios 错误对象
61
+ */
13
62
  protected handleNetworkError(error: AxiosError): void;
63
+ /**
64
+ * 处理成功响应
65
+ * 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
66
+ * 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
67
+ * 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
68
+ * @param response - Axios 响应对象
69
+ * @returns 解析后的响应数据
70
+ */
14
71
  protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
72
+ /**
73
+ * 解析响应字段,支持嵌套路径解析
74
+ * 子类可重写此方法来自定义字段解析逻辑
75
+ * @param data - 响应数据对象
76
+ * @returns 解析后的字段值对象
77
+ */
15
78
  protected parseResponseFields(data: any): {
16
79
  code: any;
17
80
  message: any;
18
81
  responseData: any;
19
82
  };
83
+ /**
84
+ * 处理系统异常错误(-1 - 系统异常)
85
+ * 子类可重写此方法来自定义系统异常处理逻辑
86
+ * @param response - Axios 响应对象
87
+ * @param code - 响应状态码
88
+ * @param message - 错误消息
89
+ * @param responseData - 响应数据
90
+ */
20
91
  protected handleSystemError(response: AxiosResponse, code: any, message: any, responseData: any): void;
92
+ /**
93
+ * 处理业务错误(其他非200错误码)
94
+ * 子类可重写此方法来自定义业务错误处理逻辑
95
+ * @param code - 响应状态码
96
+ * @param message - 错误消息
97
+ */
21
98
  protected handleBusinessError(code: any, message: any): void;
99
+ /**
100
+ * 处理错误数组 errors(如果有配置)
101
+ * 子类可重写此方法来自定义错误数组处理逻辑
102
+ * @param responseData - 响应数据
103
+ */
22
104
  protected handleErrorArray(responseData: any): void;
105
+ /**
106
+ * 显示错误数组通知
107
+ * 子类可重写此方法来自定义错误数组通知显示方式
108
+ * @param errors - 错误数组
109
+ */
23
110
  protected showErrorArrayNotification(errors: Array<{
24
111
  code: string;
25
112
  message: string;
26
113
  }>): void;
114
+ /**
115
+ * 处理提示信息 tips(如果有配置)
116
+ * 子类可重写此方法来自定义提示信息处理逻辑
117
+ * @param responseData - 响应数据
118
+ */
27
119
  protected handleTips(responseData: any): void;
120
+ /**
121
+ * 显示提示信息通知
122
+ * 子类可重写此方法来自定义提示信息通知显示方式
123
+ * @param tips - 提示信息数组
124
+ */
28
125
  protected showTipsNotification(tips: Array<{
29
126
  code: string;
30
127
  message: string;
31
128
  }>): void;
129
+ /**
130
+ * 显示系统异常对话框,当响应状态码为 -1 时调用
131
+ * @param response - Axios 响应对象
132
+ * @param responseData - 响应数据
133
+ * @param code - 错误状态码
134
+ * @param message - 错误消息
135
+ */
32
136
  private showSystemExceptionDialog;
137
+ /**
138
+ * 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
139
+ * @param errorInfo - 错误信息对象
140
+ */
33
141
  protected reportError(errorInfo: any): Promise<void>;
142
+ /**
143
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
144
+ * 显式声明以确保类型一致性,子类可重写此方法
145
+ * @param config - Axios 请求配置对象
146
+ * @returns 解析后的响应数据
147
+ */
148
+ protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
149
+ /**
150
+ * 发送 GET 请求
151
+ * 显式声明以确保类型一致性,子类可重写此方法
152
+ * @param url - 请求 URL 路径
153
+ * @param params - 查询参数对象
154
+ * @param config - 额外的请求配置
155
+ * @returns 解析后的响应数据
156
+ */
157
+ get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
158
+ /**
159
+ * 发送 POST 请求
160
+ * 显式声明以确保类型一致性,子类可重写此方法
161
+ * @param url - 请求 URL 路径
162
+ * @param data - 请求体数据
163
+ * @param config - 额外的请求配置
164
+ * @returns 解析后的响应数据
165
+ */
166
+ post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
167
+ /**
168
+ * 发送 DELETE 请求
169
+ * 显式声明以确保类型一致性,子类可重写此方法
170
+ * @param url - 请求 URL 路径
171
+ * @param params - 查询参数对象
172
+ * @param config - 额外的请求配置
173
+ * @returns 解析后的响应数据
174
+ */
175
+ delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
176
+ /**
177
+ * 发送 PUT 请求
178
+ * 显式声明以确保类型一致性,子类可重写此方法
179
+ * @param url - 请求 URL 路径
180
+ * @param data - 请求体数据
181
+ * @param config - 额外的请求配置
182
+ * @returns 解析后的响应数据
183
+ */
184
+ put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
185
+ /**
186
+ * 批量请求,并发发送多个请求
187
+ * 显式声明以确保类型一致性,子类可重写此方法
188
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
189
+ * @returns 所有请求的响应数据数组
190
+ */
191
+ all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
192
+ /**
193
+ * 文件上传,将文件包装为 FormData 发送
194
+ * 显式声明以确保类型一致性,子类可重写此方法
195
+ * @param url - 上传地址
196
+ * @param file - 文件对象
197
+ * @param config - 额外的请求配置
198
+ * @returns 解析后的响应数据
199
+ */
200
+ uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
201
+ /**
202
+ * 下载文件,将 Blob 对象下载到本地
203
+ * 显式声明以确保类型一致性,子类可重写此方法
204
+ * @param blob - Blob 对象
205
+ * @param filename - 文件名,如果不提供则使用时间戳
206
+ */
207
+ downloadFile(blob: Blob, filename?: string): void;
34
208
  }
package/es/index.d.ts CHANGED
@@ -2,4 +2,5 @@ import { default as BaseHttpClient } from './BaseHttpClient.ts';
2
2
  import { default as BaseApi } from './class.ts';
3
3
  import { default as VueAxiosPlugin, createHttpService, getHttpService } from './netseriver.ts';
4
4
  export { BaseApi, BaseHttpClient, createHttpService, getHttpService, VueAxiosPlugin, };
5
+ export type { BaseApiConfig, BaseHttpClientConfig, vueAxiosPluginOptionsType, vueAxiosPluginType, vueHttpServiceType, } from './_types/index.ts';
5
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("065a78da-34dc-4a45-874d-4fb480012cd9")) {
5
+ if (!document.getElementById("ffe3dd99-bf7e-4730-8936-fd7b509c3c02")) {
6
6
  var elementStyle = document.createElement("style");
7
- elementStyle.id = "065a78da-34dc-4a45-874d-4fb480012cd9";
7
+ elementStyle.id = "ffe3dd99-bf7e-4730-8936-fd7b509c3c02";
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,6 +12183,10 @@ 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
+ */
12186
12190
  constructor(config) {
12187
12191
  __publicField(this, "baseURL", "");
12188
12192
  __publicField(this, "timeout", 5e3);
@@ -12212,42 +12216,86 @@ class BaseHttpClient {
12212
12216
  baseURL: this.baseURL,
12213
12217
  timeout: this.timeout,
12214
12218
  ...axiosConfig
12219
+ // 将所有剩余参数传给axios.create
12215
12220
  });
12216
12221
  this.setupInterceptors();
12217
12222
  }
12223
+ /**
12224
+ * 处理请求配置,子类可重写此方法自定义请求配置
12225
+ * @param config - 请求配置对象
12226
+ * @returns 处理后的请求配置
12227
+ */
12218
12228
  processRequestConfig(config) {
12219
12229
  return config;
12220
12230
  }
12231
+ /**
12232
+ * 处理响应配置,子类可重写此方法自定义响应处理
12233
+ * 按照标准 HTTP 结构处理响应
12234
+ * @param response - Axios 响应对象
12235
+ * @returns 解析后的响应数据
12236
+ */
12221
12237
  processResponseConfig(response) {
12222
12238
  this.handleHttpStatus(response);
12223
12239
  return this.handleSuccessResponse(response);
12224
12240
  }
12241
+ /**
12242
+ * 处理 HTTP 状态码
12243
+ * 子类可重写此方法来自定义 HTTP 状态码处理逻辑
12244
+ * @param response - Axios 响应对象
12245
+ */
12225
12246
  handleHttpStatus(response) {
12226
12247
  var _a2;
12227
12248
  if (response.status !== 200) {
12228
12249
  throw new Error(((_a2 = response.data) == null ? void 0 : _a2.message) || `HTTP Error: ${response.status}`);
12229
12250
  }
12230
12251
  }
12252
+ /**
12253
+ * 处理成功响应
12254
+ * 子类可重写此方法来自定义成功响应的处理逻辑
12255
+ * @param response - Axios 响应对象
12256
+ * @returns 解析后的响应数据
12257
+ */
12231
12258
  handleSuccessResponse(response) {
12232
12259
  return response.data;
12233
12260
  }
12261
+ /**
12262
+ * 处理响应错误,子类可重写此方法自定义错误处理
12263
+ * 按照标准 HTTP 错误结构处理错误
12264
+ * @param error - Axios 错误对象
12265
+ * @returns 处理后的错误对象
12266
+ */
12234
12267
  async processResponseError(error) {
12235
12268
  this.handleAuthenticationError(error);
12236
12269
  this.handleTimeoutError(error);
12237
12270
  this.handleNetworkError(error);
12238
12271
  return error;
12239
12272
  }
12273
+ /**
12274
+ * 处理认证错误(401 - 未授权/登录失效)
12275
+ * 子类可重写此方法来自定义认证错误处理逻辑
12276
+ * @param error - Axios 错误对象
12277
+ */
12240
12278
  handleAuthenticationError(error) {
12241
12279
  var _a2, _b;
12242
12280
  if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
12243
12281
  (_b = this.onLoginRequired) == null ? void 0 : _b.call(this, this.messageInstance);
12244
12282
  }
12245
12283
  }
12284
+ /**
12285
+ * 处理超时错误
12286
+ * 子类可重写此方法来自定义超时错误处理逻辑
12287
+ * @param error - Axios 错误对象
12288
+ */
12246
12289
  handleTimeoutError(error) {
12247
12290
  if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
12248
12291
  this.onTimeout(this.messageInstance);
12249
12292
  }
12250
12293
  }
12294
+ /**
12295
+ * 处理网络错误(其他错误)
12296
+ * 子类可重写此方法来自定义网络错误处理逻辑
12297
+ * @param error - Axios 错误对象
12298
+ */
12251
12299
  handleNetworkError(error) {
12252
12300
  var _a2, _b, _c;
12253
12301
  if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
@@ -12258,6 +12306,11 @@ class BaseHttpClient {
12258
12306
  });
12259
12307
  }
12260
12308
  }
12309
+ /**
12310
+ * 设置请求和响应拦截器
12311
+ * 请求拦截器:自动添加 Token
12312
+ * 响应拦截器:处理成功响应和错误响应(401、超时等)
12313
+ */
12261
12314
  setupInterceptors() {
12262
12315
  this.instance.interceptors.request.use(
12263
12316
  (config) => {
@@ -12284,21 +12337,59 @@ class BaseHttpClient {
12284
12337
  }
12285
12338
  );
12286
12339
  }
12340
+ /**
12341
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
12342
+ * @param config - Axios 请求配置对象
12343
+ * @returns 解析后的响应数据
12344
+ */
12287
12345
  async request(config) {
12288
12346
  return this.instance.request(config);
12289
12347
  }
12348
+ /**
12349
+ * 发送 GET 请求
12350
+ * @param url - 请求 URL 路径
12351
+ * @param params - 查询参数对象
12352
+ * @param config - 额外的请求配置
12353
+ * @returns 解析后的响应数据
12354
+ */
12290
12355
  async get(url, params, config) {
12291
12356
  return this.request({ ...config, url, method: "get", params });
12292
12357
  }
12358
+ /**
12359
+ * 发送 POST 请求
12360
+ * @param url - 请求 URL 路径
12361
+ * @param data - 请求体数据
12362
+ * @param config - 额外的请求配置
12363
+ * @returns 解析后的响应数据
12364
+ */
12293
12365
  async post(url, data, config) {
12294
12366
  return this.request({ ...config, url, method: "post", data });
12295
12367
  }
12368
+ /**
12369
+ * 发送 DELETE 请求
12370
+ * @param url - 请求 URL 路径
12371
+ * @param params - 查询参数对象
12372
+ * @param config - 额外的请求配置
12373
+ * @returns 解析后的响应数据
12374
+ */
12296
12375
  async delete(url, params, config) {
12297
12376
  return this.request({ ...config, url, method: "delete", params });
12298
12377
  }
12378
+ /**
12379
+ * 发送 PUT 请求
12380
+ * @param url - 请求 URL 路径
12381
+ * @param data - 请求体数据
12382
+ * @param config - 额外的请求配置
12383
+ * @returns 解析后的响应数据
12384
+ */
12299
12385
  async put(url, data, config) {
12300
12386
  return this.request({ ...config, url, method: "put", data });
12301
12387
  }
12388
+ /**
12389
+ * 批量请求,并发发送多个请求
12390
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
12391
+ * @returns 所有请求的响应数据数组
12392
+ */
12302
12393
  async all(requests) {
12303
12394
  if (!requests.length)
12304
12395
  return [];
@@ -12311,6 +12402,13 @@ class BaseHttpClient {
12311
12402
  const promises = requests.map((config) => this.request(config));
12312
12403
  return await Promise.all(promises);
12313
12404
  }
12405
+ /**
12406
+ * 文件上传,将文件包装为 FormData 发送
12407
+ * @param url - 上传地址
12408
+ * @param file - 文件对象
12409
+ * @param config - 额外的请求配置
12410
+ * @returns 解析后的响应数据
12411
+ */
12314
12412
  async uploadFile(url, file, config) {
12315
12413
  const formData = new FormData();
12316
12414
  formData.append("file", file);
@@ -12322,6 +12420,11 @@ class BaseHttpClient {
12322
12420
  }
12323
12421
  });
12324
12422
  }
12423
+ /**
12424
+ * 下载文件,将 Blob 对象下载到本地
12425
+ * @param blob - Blob 对象
12426
+ * @param filename - 文件名,如果不提供则使用时间戳
12427
+ */
12325
12428
  downloadFile(blob, filename) {
12326
12429
  if (typeof window === "undefined") {
12327
12430
  console.warn("downloadFile: 非浏览器环境,无法下载文件");
@@ -12333,7 +12436,7 @@ class BaseHttpClient {
12333
12436
  link.download = filename || `download-${Date.now()}`;
12334
12437
  document.body.appendChild(link);
12335
12438
  link.click();
12336
- document.body.removeChild(link);
12439
+ link.remove();
12337
12440
  window.URL.revokeObjectURL(url);
12338
12441
  }
12339
12442
  }
@@ -12437,10 +12540,12 @@ function createApiDialog(DialogComponent) {
12437
12540
  cleanup();
12438
12541
  }
12439
12542
  },
12543
+ // 监听关闭事件
12440
12544
  onClose: () => {
12441
12545
  reject(new Error("对话框已关闭"));
12442
12546
  cleanup();
12443
12547
  },
12548
+ // 监听确认事件(如有)
12444
12549
  onConfirm: (data) => {
12445
12550
  resolve(data);
12446
12551
  cleanup();
@@ -12491,6 +12596,10 @@ function createApiDialog(DialogComponent) {
12491
12596
  const hasDocument = typeof document !== "undefined";
12492
12597
  let systemErrorDialogInstance = null;
12493
12598
  class BaseApi extends BaseHttpClient {
12599
+ /**
12600
+ * 创建 BaseApi 实例
12601
+ * @param config - API 配置对象
12602
+ */
12494
12603
  constructor(config) {
12495
12604
  const {
12496
12605
  responseFields,
@@ -12510,24 +12619,74 @@ class BaseApi extends BaseHttpClient {
12510
12619
  };
12511
12620
  this.enableSystemErrorDialog = enableSystemErrorDialog;
12512
12621
  }
12622
+ /**
12623
+ * 处理请求配置,子类可重写此方法自定义请求配置
12624
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12625
+ * @param config - 请求配置对象
12626
+ * @returns 处理后的请求配置
12627
+ */
12513
12628
  processRequestConfig(config) {
12514
12629
  return super.processRequestConfig(config);
12515
12630
  }
12631
+ /**
12632
+ * 处理响应配置,子类可重写此方法自定义响应处理
12633
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12634
+ * @param response - Axios 响应对象
12635
+ * @returns 解析后的响应数据
12636
+ */
12637
+ processResponseConfig(response) {
12638
+ return super.processResponseConfig(response);
12639
+ }
12640
+ /**
12641
+ * 处理响应错误,子类可重写此方法自定义错误处理
12642
+ * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
12643
+ * @param error - Axios 错误对象
12644
+ * @returns 处理后的错误对象
12645
+ */
12516
12646
  async processResponseError(error) {
12517
12647
  return super.processResponseError(error);
12518
12648
  }
12649
+ /**
12650
+ * 处理 HTTP 状态码
12651
+ * 重写父类方法,确保子类可以重写此方法
12652
+ * @param response - Axios 响应对象
12653
+ */
12519
12654
  handleHttpStatus(response) {
12520
12655
  return super.handleHttpStatus(response);
12521
12656
  }
12657
+ /**
12658
+ * 处理认证错误(401 - 未授权/登录失效)
12659
+ * 重写父类方法,处理 HTTP 401 错误
12660
+ * 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
12661
+ * @param error - Axios 错误对象
12662
+ */
12522
12663
  handleAuthenticationError(error) {
12523
12664
  super.handleAuthenticationError(error);
12524
12665
  }
12666
+ /**
12667
+ * 处理超时错误
12668
+ * 重写父类方法,确保子类可以重写此方法
12669
+ * @param error - Axios 错误对象
12670
+ */
12525
12671
  handleTimeoutError(error) {
12526
12672
  return super.handleTimeoutError(error);
12527
12673
  }
12674
+ /**
12675
+ * 处理网络错误(其他错误)
12676
+ * 重写父类方法,确保子类可以重写此方法
12677
+ * @param error - Axios 错误对象
12678
+ */
12528
12679
  handleNetworkError(error) {
12529
12680
  return super.handleNetworkError(error);
12530
12681
  }
12682
+ /**
12683
+ * 处理成功响应
12684
+ * 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
12685
+ * 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
12686
+ * 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
12687
+ * @param response - Axios 响应对象
12688
+ * @returns 解析后的响应数据
12689
+ */
12531
12690
  handleSuccessResponse(response) {
12532
12691
  const httpData = super.handleSuccessResponse(response);
12533
12692
  const parsedFields = this.parseResponseFields(httpData);
@@ -12538,6 +12697,12 @@ class BaseApi extends BaseHttpClient {
12538
12697
  this.handleTips(responseData);
12539
12698
  return responseData;
12540
12699
  }
12700
+ /**
12701
+ * 解析响应字段,支持嵌套路径解析
12702
+ * 子类可重写此方法来自定义字段解析逻辑
12703
+ * @param data - 响应数据对象
12704
+ * @returns 解析后的字段值对象
12705
+ */
12541
12706
  parseResponseFields(data) {
12542
12707
  var _a2, _b, _c;
12543
12708
  const getValueByPath = (obj, path) => {
@@ -12559,6 +12724,14 @@ class BaseApi extends BaseHttpClient {
12559
12724
  const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
12560
12725
  return { code, message: message2, responseData };
12561
12726
  }
12727
+ /**
12728
+ * 处理系统异常错误(-1 - 系统异常)
12729
+ * 子类可重写此方法来自定义系统异常处理逻辑
12730
+ * @param response - Axios 响应对象
12731
+ * @param code - 响应状态码
12732
+ * @param message - 错误消息
12733
+ * @param responseData - 响应数据
12734
+ */
12562
12735
  handleSystemError(response, code, message2, responseData) {
12563
12736
  if (code === -1) {
12564
12737
  if (this.enableSystemErrorDialog) {
@@ -12569,6 +12742,12 @@ class BaseApi extends BaseHttpClient {
12569
12742
  throw new Error(message2 || "系统异常");
12570
12743
  }
12571
12744
  }
12745
+ /**
12746
+ * 处理业务错误(其他非200错误码)
12747
+ * 子类可重写此方法来自定义业务错误处理逻辑
12748
+ * @param code - 响应状态码
12749
+ * @param message - 错误消息
12750
+ */
12572
12751
  handleBusinessError(code, message2) {
12573
12752
  var _a2;
12574
12753
  if (code && code !== 200) {
@@ -12579,6 +12758,11 @@ class BaseApi extends BaseHttpClient {
12579
12758
  throw new Error(message2 || "请求失败");
12580
12759
  }
12581
12760
  }
12761
+ /**
12762
+ * 处理错误数组 errors(如果有配置)
12763
+ * 子类可重写此方法来自定义错误数组处理逻辑
12764
+ * @param responseData - 响应数据
12765
+ */
12582
12766
  handleErrorArray(responseData) {
12583
12767
  var _a2;
12584
12768
  const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
@@ -12590,6 +12774,11 @@ class BaseApi extends BaseHttpClient {
12590
12774
  }
12591
12775
  }
12592
12776
  }
12777
+ /**
12778
+ * 显示错误数组通知
12779
+ * 子类可重写此方法来自定义错误数组通知显示方式
12780
+ * @param errors - 错误数组
12781
+ */
12593
12782
  showErrorArrayNotification(errors) {
12594
12783
  var _a2, _b;
12595
12784
  const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
@@ -12608,6 +12797,11 @@ class BaseApi extends BaseHttpClient {
12608
12797
  });
12609
12798
  }
12610
12799
  }
12800
+ /**
12801
+ * 处理提示信息 tips(如果有配置)
12802
+ * 子类可重写此方法来自定义提示信息处理逻辑
12803
+ * @param responseData - 响应数据
12804
+ */
12611
12805
  handleTips(responseData) {
12612
12806
  var _a2;
12613
12807
  const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
@@ -12618,6 +12812,11 @@ class BaseApi extends BaseHttpClient {
12618
12812
  }
12619
12813
  }
12620
12814
  }
12815
+ /**
12816
+ * 显示提示信息通知
12817
+ * 子类可重写此方法来自定义提示信息通知显示方式
12818
+ * @param tips - 提示信息数组
12819
+ */
12621
12820
  showTipsNotification(tips) {
12622
12821
  var _a2, _b;
12623
12822
  const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
@@ -12636,6 +12835,13 @@ class BaseApi extends BaseHttpClient {
12636
12835
  });
12637
12836
  }
12638
12837
  }
12838
+ /**
12839
+ * 显示系统异常对话框,当响应状态码为 -1 时调用
12840
+ * @param response - Axios 响应对象
12841
+ * @param responseData - 响应数据
12842
+ * @param code - 错误状态码
12843
+ * @param message - 错误消息
12844
+ */
12639
12845
  async showSystemExceptionDialog(response, responseData, code, message2) {
12640
12846
  if (!hasDocument) {
12641
12847
  console.error("系统异常信息:", responseData);
@@ -12674,6 +12880,10 @@ class BaseApi extends BaseHttpClient {
12674
12880
  console.error("系统异常信息:", responseData);
12675
12881
  }
12676
12882
  }
12883
+ /**
12884
+ * 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
12885
+ * @param errorInfo - 错误信息对象
12886
+ */
12677
12887
  async reportError(errorInfo) {
12678
12888
  var _a2, _b;
12679
12889
  try {
@@ -12691,11 +12901,98 @@ class BaseApi extends BaseHttpClient {
12691
12901
  });
12692
12902
  }
12693
12903
  }
12904
+ /**
12905
+ * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
12906
+ * 显式声明以确保类型一致性,子类可重写此方法
12907
+ * @param config - Axios 请求配置对象
12908
+ * @returns 解析后的响应数据
12909
+ */
12910
+ async request(config) {
12911
+ return super.request(config);
12912
+ }
12913
+ /**
12914
+ * 发送 GET 请求
12915
+ * 显式声明以确保类型一致性,子类可重写此方法
12916
+ * @param url - 请求 URL 路径
12917
+ * @param params - 查询参数对象
12918
+ * @param config - 额外的请求配置
12919
+ * @returns 解析后的响应数据
12920
+ */
12921
+ async get(url, params, config) {
12922
+ return super.get(url, params, config);
12923
+ }
12924
+ /**
12925
+ * 发送 POST 请求
12926
+ * 显式声明以确保类型一致性,子类可重写此方法
12927
+ * @param url - 请求 URL 路径
12928
+ * @param data - 请求体数据
12929
+ * @param config - 额外的请求配置
12930
+ * @returns 解析后的响应数据
12931
+ */
12932
+ async post(url, data, config) {
12933
+ return super.post(url, data, config);
12934
+ }
12935
+ /**
12936
+ * 发送 DELETE 请求
12937
+ * 显式声明以确保类型一致性,子类可重写此方法
12938
+ * @param url - 请求 URL 路径
12939
+ * @param params - 查询参数对象
12940
+ * @param config - 额外的请求配置
12941
+ * @returns 解析后的响应数据
12942
+ */
12943
+ async delete(url, params, config) {
12944
+ return super.delete(url, params, config);
12945
+ }
12946
+ /**
12947
+ * 发送 PUT 请求
12948
+ * 显式声明以确保类型一致性,子类可重写此方法
12949
+ * @param url - 请求 URL 路径
12950
+ * @param data - 请求体数据
12951
+ * @param config - 额外的请求配置
12952
+ * @returns 解析后的响应数据
12953
+ */
12954
+ async put(url, data, config) {
12955
+ return super.put(url, data, config);
12956
+ }
12957
+ /**
12958
+ * 批量请求,并发发送多个请求
12959
+ * 显式声明以确保类型一致性,子类可重写此方法
12960
+ * @param requests - 请求配置数组或已发起的请求 Promise 数组
12961
+ * @returns 所有请求的响应数据数组
12962
+ */
12963
+ async all(requests) {
12964
+ return super.all(requests);
12965
+ }
12966
+ /**
12967
+ * 文件上传,将文件包装为 FormData 发送
12968
+ * 显式声明以确保类型一致性,子类可重写此方法
12969
+ * @param url - 上传地址
12970
+ * @param file - 文件对象
12971
+ * @param config - 额外的请求配置
12972
+ * @returns 解析后的响应数据
12973
+ */
12974
+ async uploadFile(url, file, config) {
12975
+ return super.uploadFile(url, file, config);
12976
+ }
12977
+ /**
12978
+ * 下载文件,将 Blob 对象下载到本地
12979
+ * 显式声明以确保类型一致性,子类可重写此方法
12980
+ * @param blob - Blob 对象
12981
+ * @param filename - 文件名,如果不提供则使用时间戳
12982
+ */
12983
+ downloadFile(blob, filename) {
12984
+ return super.downloadFile(blob, filename);
12985
+ }
12694
12986
  }
12695
12987
  function createHttpService(options = {}) {
12696
12988
  return new BaseApi(options);
12697
12989
  }
12698
12990
  const VueAxiosPlugin = {
12991
+ /**
12992
+ * 安装插件
12993
+ * @param app - Vue 应用实例
12994
+ * @param options - 插件配置选项
12995
+ */
12699
12996
  install(app, options = {}) {
12700
12997
  const httpService = createHttpService(options.default ?? {});
12701
12998
  app.config.globalProperties.$http = httpService;
@@ -12876,10 +13173,12 @@ const SystemErrorDialog = defineComponent({
12876
13173
  h("span", { style: { fontWeight: "bold", fontSize: "16px" } }, props.title || "系统异常信息")
12877
13174
  ]),
12878
13175
  default: () => h("div", { style: { padding: 0, maxHeight: "500px", overflowY: "auto" } }, [
13176
+ // 第一块:无法完成您的请求
12879
13177
  h("div", { style: { padding: "20px", borderBottom: "1px solid #ebeef5" } }, [
12880
13178
  h("h3", { style: { margin: "0 0 12px 0", fontSize: "16px", fontWeight: "bold", color: "#303133" } }, "无法完成您的请求"),
12881
13179
  h("p", { style: { margin: 0, color: "#606266", lineHeight: 1.5 } }, "系统在处理您的请求时遇到了问题,可能是由于服务暂时不可用。")
12882
13180
  ]),
13181
+ // 第二块:技术摘要(可展开)
12883
13182
  h("div", { style: { borderBottom: "1px solid #ebeef5" } }, [
12884
13183
  h(
12885
13184
  "div",
@@ -12941,6 +13240,7 @@ const SystemErrorDialog = defineComponent({
12941
13240
  )
12942
13241
  ) : null
12943
13242
  ]),
13243
+ // SkyWalking 按钮
12944
13244
  h("div", { style: { padding: "16px 20px", borderBottom: "1px solid #ebeef5" } }, [
12945
13245
  h(
12946
13246
  ElButton,
@@ -12952,6 +13252,7 @@ const SystemErrorDialog = defineComponent({
12952
13252
  { default: () => "📊 在SkyWalking中查看详情" }
12953
13253
  )
12954
13254
  ]),
13255
+ // 黑色错误信息区域
12955
13256
  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" } }, [
12956
13257
  h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
12957
13258
  h("div", { style: { color: "#e74c3c", fontWeight: "bold" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
@@ -5,8 +5,22 @@ declare global {
5
5
  $http?: vueHttpServiceType;
6
6
  }
7
7
  }
8
+ /**
9
+ * 创建 HTTP 服务实例
10
+ * @param options - API 配置对象
11
+ * @returns BaseApi 实例
12
+ */
8
13
  declare function createHttpService(options?: BaseApiConfig): BaseApi;
14
+ /**
15
+ * Vue Axios 插件,用于在 Vue 应用中全局注册 HTTP 服务
16
+ * 提供 this.$http、inject('$http') 和 window.$http 三种使用方式
17
+ */
9
18
  declare const VueAxiosPlugin: vueAxiosPluginType;
19
+ /**
20
+ * 获取 HTTP 服务实例,与 createHttpService 功能相同
21
+ * @param options - API 配置对象
22
+ * @returns BaseApi 实例
23
+ */
10
24
  declare function getHttpService(options?: BaseApiConfig): BaseApi;
11
25
  export default VueAxiosPlugin;
12
26
  export { createHttpService, getHttpService };
@@ -0,0 +1,9 @@
1
+ import { AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
+ import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
3
+ export default class BaseRequestApi extends BaseApi {
4
+ constructor(config?: Partial<BaseApiConfig>);
5
+ processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
6
+ protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
7
+ protected handleHttpStatus(response: AxiosResponse): void;
8
+ protected handleBusinessError(code: any, message: any): void;
9
+ }
@@ -0,0 +1,21 @@
1
+ import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
+ import { default as BaseRequestApi } from './BaseRequestApi.ts';
3
+ export default class DownloadApi extends BaseRequestApi {
4
+ private downloadingFiles;
5
+ constructor();
6
+ processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
7
+ processResponseError(error: AxiosError): Promise<AxiosError>;
8
+ protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
9
+ downloadFileFromUrl(url: string, filename?: string, params?: Record<string, any>, data?: Record<string, any>, method?: 'get' | 'post', config?: AxiosRequestConfig): Promise<boolean>;
10
+ private getFilenameFromUrl;
11
+ downloadMultipleFiles(files: Array<{
12
+ url: string;
13
+ filename?: string;
14
+ params?: Record<string, any>;
15
+ data?: Record<string, any>;
16
+ method?: 'get' | 'post';
17
+ }>, onProgress?: (progress: number, currentFile: string) => void): Promise<{
18
+ success: number;
19
+ total: number;
20
+ }>;
21
+ }
@@ -0,0 +1,4 @@
1
+ import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
2
+ export default class RoleApi extends BaseApi {
3
+ constructor(config?: Partial<BaseApiConfig>);
4
+ }
@@ -0,0 +1,4 @@
1
+ import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
2
+ export default class UserApi extends BaseApi {
3
+ constructor(config?: Partial<BaseApiConfig>);
4
+ }
@@ -0,0 +1,9 @@
1
+ import { default as DownloadApi } from './DownloadApi.ts';
2
+ import { default as BaseRequestApi } from './BaseRequestApi.ts';
3
+ import { default as UserApi } from './UserApi.ts';
4
+ import { default as RoleApi } from './RoleApi.ts';
5
+ export declare const downloadRequest: DownloadApi;
6
+ export declare const userRequest: any;
7
+ export declare const baseRequest: any;
8
+ export declare const roleRequest: any;
9
+ export { DownloadApi, BaseRequestApi, UserApi, RoleApi, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moluoxixi/ajax-package",
3
- "version": "0.0.13",
3
+ "version": "0.0.14-beta.1",
4
4
  "description": "AjaxPackage 组件",
5
5
  "sideEffects": [
6
6
  "*.css",