@moluoxixi/ajax-package 0.0.15 → 0.0.16

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/index.mjs CHANGED
@@ -2,9 +2,9 @@
2
2
  "use strict";
3
3
  try {
4
4
  if (typeof document !== "undefined") {
5
- if (!document.getElementById("ffe3dd99-bf7e-4730-8936-fd7b509c3c02")) {
5
+ if (!document.getElementById("14c6052f-e4ae-4502-9336-1f25c81ac076")) {
6
6
  var elementStyle = document.createElement("style");
7
- elementStyle.id = "ffe3dd99-bf7e-4730-8936-fd7b509c3c02";
7
+ elementStyle.id = "14c6052f-e4ae-4502-9336-1f25c81ac076";
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
  }
@@ -13255,7 +13255,7 @@ const SystemErrorDialog = defineComponent({
13255
13255
  // 黑色错误信息区域
13256
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" } }, [
13257
13257
  h("div", { style: { marginBottom: "8px", color: "#ecf0f1" } }, `Trace ID: ${props.traceId || "a1b2c3d4-e5f6-7890-g1h2-i3j4k5l6m7n8"}`),
13258
- h("div", { style: { color: "#e74c3c", fontWeight: "bold" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
13258
+ h("div", { style: { color: "#e74c3c", fontWeight: "bold", whiteSpace: "pre-wrap" } }, `Error: ${props.errorMessage || "Connection timeout after 5000ms"}`)
13259
13259
  ])
13260
13260
  ]),
13261
13261
  footer: () => h("div", { style: { display: "flex", justifyContent: "flex-end", alignItems: "center", paddingTop: "16px" } }, [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moluoxixi/ajax-package",
3
- "version": "0.0.15",
3
+ "version": "0.0.16",
4
4
  "description": "AjaxPackage 组件",
5
5
  "sideEffects": [
6
6
  "*.css",
@@ -1,142 +0,0 @@
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
- /**
5
- * BaseHttpClient 基础类
6
- * 提供最基础的 HTTP 请求功能,包括:
7
- * - 创建 axios 实例
8
- * - 自动添加 Token
9
- * - 基础错误处理(401、超时等)
10
- * - HTTP 方法(get、post、put、delete、all)
11
- * - 文件上传
12
- */
13
- export default class BaseHttpClient {
14
- protected baseURL: string;
15
- protected timeout: number;
16
- protected onTimeout: (messageInstance: MessageInstance) => void;
17
- protected getToken?: () => string | null;
18
- protected onLoginRequired?: (messageInstance: MessageInstance) => void;
19
- instance: ReturnType<typeof axios.create>;
20
- protected messageInstance: MessageInstance;
21
- protected notificationInstance: NotificationInstance;
22
- /**
23
- * 创建 BaseHttpClient 实例
24
- * @param config - HTTP 客户端配置对象
25
- */
26
- constructor(config: BaseHttpClientConfig);
27
- /**
28
- * 处理请求配置,子类可重写此方法自定义请求配置
29
- * @param config - 请求配置对象
30
- * @returns 处理后的请求配置
31
- */
32
- processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
33
- /**
34
- * 处理响应配置,子类可重写此方法自定义响应处理
35
- * 按照标准 HTTP 结构处理响应
36
- * @param response - Axios 响应对象
37
- * @returns 解析后的响应数据
38
- */
39
- processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
40
- /**
41
- * 处理 HTTP 状态码
42
- * 子类可重写此方法来自定义 HTTP 状态码处理逻辑
43
- * @param response - Axios 响应对象
44
- */
45
- protected handleHttpStatus(response: AxiosResponse): void;
46
- /**
47
- * 处理成功响应
48
- * 子类可重写此方法来自定义成功响应的处理逻辑
49
- * @param response - Axios 响应对象
50
- * @returns 解析后的响应数据
51
- */
52
- protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
53
- /**
54
- * 处理响应错误,子类可重写此方法自定义错误处理
55
- * 按照标准 HTTP 错误结构处理错误
56
- * @param error - Axios 错误对象
57
- * @returns 处理后的错误对象
58
- */
59
- processResponseError(error: AxiosError): Promise<AxiosError>;
60
- /**
61
- * 处理认证错误(401 - 未授权/登录失效)
62
- * 子类可重写此方法来自定义认证错误处理逻辑
63
- * @param error - Axios 错误对象
64
- */
65
- protected handleAuthenticationError(error: AxiosError): void;
66
- /**
67
- * 处理超时错误
68
- * 子类可重写此方法来自定义超时错误处理逻辑
69
- * @param error - Axios 错误对象
70
- */
71
- protected handleTimeoutError(error: AxiosError): void;
72
- /**
73
- * 处理网络错误(其他错误)
74
- * 子类可重写此方法来自定义网络错误处理逻辑
75
- * @param error - Axios 错误对象
76
- */
77
- protected handleNetworkError(error: AxiosError): void;
78
- /**
79
- * 设置请求和响应拦截器
80
- * 请求拦截器:自动添加 Token
81
- * 响应拦截器:处理成功响应和错误响应(401、超时等)
82
- */
83
- private setupInterceptors;
84
- /**
85
- * 发送 HTTP 请求,所有 HTTP 方法最终都调用此方法
86
- * @param config - Axios 请求配置对象
87
- * @returns 解析后的响应数据
88
- */
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
- */
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
- */
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
- */
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
- */
121
- put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
122
- /**
123
- * 批量请求,并发发送多个请求
124
- * @param requests - 请求配置数组或已发起的请求 Promise 数组
125
- * @returns 所有请求的响应数据数组
126
- */
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
- */
135
- uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
136
- /**
137
- * 下载文件,将 Blob 对象下载到本地
138
- * @param blob - Blob 对象
139
- * @param filename - 文件名,如果不提供则使用时间戳
140
- */
141
- downloadFile(blob: Blob, filename?: string): void;
142
- }
@@ -1,129 +0,0 @@
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
- onClose?: (() => any) | undefined;
112
- onConfirm?: ((data: any) => any) | undefined;
113
- "onUpdate:modelValue"?: ((val: boolean) => 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;
@@ -1,65 +0,0 @@
1
- import { App } from 'vue';
2
- import { MessageInstance } from '../_utils/index.ts';
3
- import { default as BaseApi } from '../class.ts';
4
- /**
5
- * BaseHttpClient 基础配置接口,包含最基础的 HTTP 客户端配置
6
- */
7
- export interface BaseHttpClientConfig {
8
- /** API 基础地址 */
9
- baseURL?: string;
10
- /** 请求超时时间(毫秒),默认 5000 */
11
- timeout?: number;
12
- /** 请求超时回调函数,接收 messageInstance 用于显示消息提示 */
13
- onTimeout?: (messageInstance: MessageInstance) => void;
14
- /** 获取 token 的函数,每次请求前自动调用 */
15
- getToken?: () => string | null;
16
- /** 登录失效回调函数,当检测到 401 错误时调用,接收 messageInstance 用于显示消息提示 */
17
- onLoginRequired?: (messageInstance: MessageInstance) => void;
18
- /** 允许其他任意配置项,会直接传递给 axios.create */
19
- [key: string]: any;
20
- }
21
- /**
22
- * BaseApi 配置接口,用于配置 BaseApi 实例的所有选项
23
- * 继承 BaseHttpClientConfig,添加响应字段映射和系统异常弹窗配置
24
- */
25
- export interface BaseApiConfig extends BaseHttpClientConfig {
26
- /** 响应字段映射配置 */
27
- responseFields?: {
28
- /** 响应状态码字段名,默认 'Code' */
29
- code?: string;
30
- /** 响应消息字段名,默认 'Message' */
31
- message?: string;
32
- /** 响应数据字段名,默认 'data' */
33
- data?: string;
34
- /** 错误数组字段名 */
35
- errors?: string;
36
- /** 提示信息字段名 */
37
- tips?: string;
38
- };
39
- /** 是否启用 code === -1 的系统异常弹窗,默认为 true */
40
- enableSystemErrorDialog?: boolean;
41
- }
42
- /**
43
- * Vue Axios 插件配置选项
44
- */
45
- export interface vueAxiosPluginOptionsType {
46
- /** 默认 HTTP 服务配置 */
47
- default?: BaseApiConfig;
48
- /** 是否在所有组件中通过 mixin 注入 $http,默认为 true */
49
- globalMixin?: boolean;
50
- }
51
- /**
52
- * Vue HTTP 服务类型,在 Vue 应用中通过 this.$http 或 inject('$http') 获取
53
- */
54
- export type vueHttpServiceType = BaseApi;
55
- /**
56
- * Vue Axios 插件类型,定义了 Vue 插件的标准接口
57
- */
58
- export interface vueAxiosPluginType {
59
- /**
60
- * 安装插件
61
- * @param app - Vue 应用实例
62
- * @param options - 插件配置选项
63
- */
64
- install: (app: App, options?: vueAxiosPluginOptionsType) => void;
65
- }
@@ -1,13 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
1
- export * from './api.ts';
2
- export * from './emits.ts';
3
- export type { SystemErrorDialogEmitsType } from './emits.ts';
4
- export * from './props.ts';
@@ -1,27 +0,0 @@
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
- }
@@ -1,3 +0,0 @@
1
- export * from './messageWrapper.ts';
2
- export * from './notificationWrapper.ts';
3
- export * from './systemErrorInfo.ts';
@@ -1,39 +0,0 @@
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>;
@@ -1,12 +0,0 @@
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>;
@@ -1,27 +0,0 @@
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 DELETED
@@ -1,208 +0,0 @@
1
- import { AxiosError, AxiosRequestConfig, AxiosResponse, InternalAxiosRequestConfig } from 'axios';
2
- import { BaseApiConfig } from './_types/index.ts';
3
- import { default as BaseHttpClient } from './BaseHttpClient.ts';
4
- /**
5
- * BaseApi 类
6
- * 继承 BaseHttpClient,提供增强的响应解析和错误处理功能
7
- * 包括:响应字段映射、错误码处理、系统异常弹窗等
8
- */
9
- export default class BaseApi extends BaseHttpClient {
10
- protected responseFields: Required<BaseApiConfig['responseFields']>;
11
- protected enableSystemErrorDialog: boolean;
12
- /**
13
- * 创建 BaseApi 实例
14
- * @param config - API 配置对象
15
- */
16
- constructor(config: BaseApiConfig);
17
- /**
18
- * 处理请求配置,子类可重写此方法自定义请求配置
19
- * 显式声明以确保类型一致性,避免打包后的类型不兼容问题
20
- * @param config - 请求配置对象
21
- * @returns 处理后的请求配置
22
- */
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
- */
37
- processResponseError(error: AxiosError): Promise<AxiosError>;
38
- /**
39
- * 处理 HTTP 状态码
40
- * 重写父类方法,确保子类可以重写此方法
41
- * @param response - Axios 响应对象
42
- */
43
- protected handleHttpStatus(response: AxiosResponse): void;
44
- /**
45
- * 处理认证错误(401 - 未授权/登录失效)
46
- * 重写父类方法,处理 HTTP 401 错误
47
- * 子类可重写此方法来自定义 HTTP 认证错误处理逻辑
48
- * @param error - Axios 错误对象
49
- */
50
- protected handleAuthenticationError(error: AxiosError): void;
51
- /**
52
- * 处理超时错误
53
- * 重写父类方法,确保子类可以重写此方法
54
- * @param error - Axios 错误对象
55
- */
56
- protected handleTimeoutError(error: AxiosError): void;
57
- /**
58
- * 处理网络错误(其他错误)
59
- * 重写父类方法,确保子类可以重写此方法
60
- * @param error - Axios 错误对象
61
- */
62
- protected handleNetworkError(error: AxiosError): void;
63
- /**
64
- * 处理成功响应
65
- * 重写父类方法,在标准 HTTP 成功响应基础上,处理业务特定的响应结构
66
- * 支持嵌套路径解析,自动处理业务层的登录失效、系统异常等错误
67
- * 注意:HTTP 层的错误(如 HTTP 401、超时等)由父类 BaseHttpClient 处理
68
- * @param response - Axios 响应对象
69
- * @returns 解析后的响应数据
70
- */
71
- protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
72
- /**
73
- * 解析响应字段,支持嵌套路径解析
74
- * 子类可重写此方法来自定义字段解析逻辑
75
- * @param data - 响应数据对象
76
- * @returns 解析后的字段值对象
77
- */
78
- protected parseResponseFields(data: any): {
79
- code: any;
80
- message: any;
81
- responseData: any;
82
- };
83
- /**
84
- * 处理系统异常错误(-1 - 系统异常)
85
- * 子类可重写此方法来自定义系统异常处理逻辑
86
- * @param response - Axios 响应对象
87
- * @param code - 响应状态码
88
- * @param message - 错误消息
89
- * @param responseData - 响应数据
90
- */
91
- protected handleSystemError(response: AxiosResponse, code: any, message: any, responseData: any): void;
92
- /**
93
- * 处理业务错误(其他非200错误码)
94
- * 子类可重写此方法来自定义业务错误处理逻辑
95
- * @param code - 响应状态码
96
- * @param message - 错误消息
97
- */
98
- protected handleBusinessError(code: any, message: any): void;
99
- /**
100
- * 处理错误数组 errors(如果有配置)
101
- * 子类可重写此方法来自定义错误数组处理逻辑
102
- * @param responseData - 响应数据
103
- */
104
- protected handleErrorArray(responseData: any): void;
105
- /**
106
- * 显示错误数组通知
107
- * 子类可重写此方法来自定义错误数组通知显示方式
108
- * @param errors - 错误数组
109
- */
110
- protected showErrorArrayNotification(errors: Array<{
111
- code: string;
112
- message: string;
113
- }>): void;
114
- /**
115
- * 处理提示信息 tips(如果有配置)
116
- * 子类可重写此方法来自定义提示信息处理逻辑
117
- * @param responseData - 响应数据
118
- */
119
- protected handleTips(responseData: any): void;
120
- /**
121
- * 显示提示信息通知
122
- * 子类可重写此方法来自定义提示信息通知显示方式
123
- * @param tips - 提示信息数组
124
- */
125
- protected showTipsNotification(tips: Array<{
126
- code: string;
127
- message: string;
128
- }>): void;
129
- /**
130
- * 显示系统异常对话框,当响应状态码为 -1 时调用
131
- * @param response - Axios 响应对象
132
- * @param responseData - 响应数据
133
- * @param code - 错误状态码
134
- * @param message - 错误消息
135
- */
136
- private showSystemExceptionDialog;
137
- /**
138
- * 上报错误信息到服务器,默认实现仅显示提示,子类可重写实现真实上报
139
- * @param errorInfo - 错误信息对象
140
- */
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;
208
- }
package/es/index.d.ts DELETED
@@ -1,6 +0,0 @@
1
- import { default as BaseHttpClient } from './BaseHttpClient.ts';
2
- import { default as BaseApi } from './class.ts';
3
- import { default as VueAxiosPlugin, createHttpService, getHttpService } from './netseriver.ts';
4
- export { BaseApi, BaseHttpClient, createHttpService, getHttpService, VueAxiosPlugin, };
5
- export type { BaseApiConfig, BaseHttpClientConfig, vueAxiosPluginOptionsType, vueAxiosPluginType, vueHttpServiceType, } from './_types/index.ts';
6
- export default getHttpService;
@@ -1,26 +0,0 @@
1
- import { BaseApiConfig, vueAxiosPluginType, vueHttpServiceType } from './_types/index.ts';
2
- import { default as BaseApi } from './class.ts';
3
- declare global {
4
- interface Window {
5
- $http?: vueHttpServiceType;
6
- }
7
- }
8
- /**
9
- * 创建 HTTP 服务实例
10
- * @param options - API 配置对象
11
- * @returns BaseApi 实例
12
- */
13
- declare function createHttpService(options?: BaseApiConfig): BaseApi;
14
- /**
15
- * Vue Axios 插件,用于在 Vue 应用中全局注册 HTTP 服务
16
- * 提供 this.$http、inject('$http') 和 window.$http 三种使用方式
17
- */
18
- declare const VueAxiosPlugin: vueAxiosPluginType;
19
- /**
20
- * 获取 HTTP 服务实例,与 createHttpService 功能相同
21
- * @param options - API 配置对象
22
- * @returns BaseApi 实例
23
- */
24
- declare function getHttpService(options?: BaseApiConfig): BaseApi;
25
- export default VueAxiosPlugin;
26
- export { createHttpService, getHttpService };
@@ -1,9 +0,0 @@
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
- }
@@ -1,21 +0,0 @@
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
- }
@@ -1,4 +0,0 @@
1
- import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
2
- export default class RoleApi extends BaseApi {
3
- constructor(config?: Partial<BaseApiConfig>);
4
- }
@@ -1,4 +0,0 @@
1
- import { BaseApi, BaseApiConfig } from '@moluoxixi/ajax-package';
2
- export default class UserApi extends BaseApi {
3
- constructor(config?: Partial<BaseApiConfig>);
4
- }
@@ -1,9 +0,0 @@
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, };