@moluoxixi/ajax-package 0.0.12 → 0.0.14
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 +8 -2
- package/es/SystemErrorDialog.d.ts +5 -5
- package/es/_types/api.d.ts +3 -2
- package/es/class.d.ts +26 -4
- package/es/index.d.ts +1 -0
- package/es/index.mjs +146 -70
- package/es/test/utils/BaseRequestApi.d.ts +9 -0
- package/es/test/utils/DownloadApi.d.ts +21 -0
- package/es/test/utils/RoleApi.d.ts +4 -0
- package/es/test/utils/UserApi.d.ts +4 -0
- package/es/test/utils/index.d.ts +9 -0
- package/package.json +1 -1
package/es/BaseHttpClient.d.ts
CHANGED
|
@@ -4,16 +4,21 @@ import { MessageInstance, NotificationInstance } from './_utils/index.ts';
|
|
|
4
4
|
export default class BaseHttpClient {
|
|
5
5
|
protected baseURL: string;
|
|
6
6
|
protected timeout: number;
|
|
7
|
-
protected onTimeout: () => void;
|
|
7
|
+
protected onTimeout: (messageInstance: MessageInstance) => void;
|
|
8
8
|
protected getToken?: () => string | null;
|
|
9
|
-
protected onLoginRequired?: () => void;
|
|
9
|
+
protected onLoginRequired?: (messageInstance: MessageInstance) => void;
|
|
10
10
|
instance: ReturnType<typeof axios.create>;
|
|
11
11
|
protected messageInstance: MessageInstance;
|
|
12
12
|
protected notificationInstance: NotificationInstance;
|
|
13
13
|
constructor(config: BaseHttpClientConfig);
|
|
14
14
|
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig<any>;
|
|
15
15
|
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
16
|
+
protected handleHttpStatus(response: AxiosResponse): void;
|
|
17
|
+
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
16
18
|
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
19
|
+
protected handleAuthenticationError(error: AxiosError): void;
|
|
20
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
21
|
+
protected handleNetworkError(error: AxiosError): void;
|
|
17
22
|
private setupInterceptors;
|
|
18
23
|
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
19
24
|
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
@@ -22,4 +27,5 @@ export default class BaseHttpClient {
|
|
|
22
27
|
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
23
28
|
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
24
29
|
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
30
|
+
downloadFile(blob: Blob, filename?: string): void;
|
|
25
31
|
}
|
|
@@ -4,7 +4,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
4
4
|
default: string;
|
|
5
5
|
};
|
|
6
6
|
width: {
|
|
7
|
-
type: (
|
|
7
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
8
8
|
default: number;
|
|
9
9
|
};
|
|
10
10
|
userName: {
|
|
@@ -40,7 +40,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
40
40
|
default: undefined;
|
|
41
41
|
};
|
|
42
42
|
errorCode: {
|
|
43
|
-
type: (
|
|
43
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
44
44
|
default: undefined;
|
|
45
45
|
};
|
|
46
46
|
modelValue: {
|
|
@@ -60,7 +60,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
60
60
|
default: string;
|
|
61
61
|
};
|
|
62
62
|
width: {
|
|
63
|
-
type: (
|
|
63
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
64
64
|
default: number;
|
|
65
65
|
};
|
|
66
66
|
userName: {
|
|
@@ -96,7 +96,7 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
96
96
|
default: undefined;
|
|
97
97
|
};
|
|
98
98
|
errorCode: {
|
|
99
|
-
type: (
|
|
99
|
+
type: (StringConstructor | NumberConstructor)[];
|
|
100
100
|
default: undefined;
|
|
101
101
|
};
|
|
102
102
|
modelValue: {
|
|
@@ -110,7 +110,6 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
110
110
|
onReport?: (() => any) | undefined;
|
|
111
111
|
}>, {
|
|
112
112
|
title: string;
|
|
113
|
-
modelValue: boolean;
|
|
114
113
|
width: string | number;
|
|
115
114
|
userName: string;
|
|
116
115
|
userId: string;
|
|
@@ -121,5 +120,6 @@ declare const _default: import('vue').DefineComponent<import('vue').ExtractPropT
|
|
|
121
120
|
traceId: string;
|
|
122
121
|
errorMessage: string;
|
|
123
122
|
errorCode: string | number;
|
|
123
|
+
modelValue: boolean;
|
|
124
124
|
}, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
|
|
125
125
|
export default _default;
|
package/es/_types/api.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
|
+
import { MessageInstance } from '../_utils/index.ts';
|
|
2
3
|
import { default as BaseApi } from '../class.ts';
|
|
3
4
|
export interface BaseHttpClientConfig {
|
|
4
5
|
baseURL?: string;
|
|
5
6
|
timeout?: number;
|
|
6
|
-
onTimeout?: () => void;
|
|
7
|
+
onTimeout?: (messageInstance: MessageInstance) => void;
|
|
7
8
|
getToken?: () => string | null;
|
|
8
|
-
onLoginRequired?: () => void;
|
|
9
|
+
onLoginRequired?: (messageInstance: MessageInstance) => void;
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
}
|
|
11
12
|
export interface BaseApiConfig extends BaseHttpClientConfig {
|
package/es/class.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
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
4
|
export default class BaseApi extends BaseHttpClient {
|
|
@@ -6,16 +6,38 @@ export default class BaseApi extends BaseHttpClient {
|
|
|
6
6
|
protected enableSystemErrorDialog: boolean;
|
|
7
7
|
constructor(config: BaseApiConfig);
|
|
8
8
|
processRequestConfig(config: InternalAxiosRequestConfig): InternalAxiosRequestConfig;
|
|
9
|
-
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
10
9
|
processResponseConfig(response: AxiosResponse): AxiosResponse['data'];
|
|
10
|
+
processResponseError(error: AxiosError): Promise<AxiosError>;
|
|
11
|
+
protected handleHttpStatus(response: AxiosResponse): void;
|
|
12
|
+
protected handleAuthenticationError(error: AxiosError): void;
|
|
13
|
+
protected handleTimeoutError(error: AxiosError): void;
|
|
14
|
+
protected handleNetworkError(error: AxiosError): void;
|
|
15
|
+
protected handleSuccessResponse(response: AxiosResponse): AxiosResponse['data'];
|
|
11
16
|
protected parseResponseFields(data: any): {
|
|
12
17
|
code: any;
|
|
13
18
|
message: any;
|
|
14
19
|
responseData: any;
|
|
15
20
|
};
|
|
16
|
-
protected
|
|
17
|
-
protected
|
|
21
|
+
protected handleSystemError(response: AxiosResponse, code: any, message: any, responseData: any): void;
|
|
22
|
+
protected handleBusinessError(code: any, message: any): void;
|
|
23
|
+
protected handleErrorArray(responseData: any): void;
|
|
24
|
+
protected showErrorArrayNotification(errors: Array<{
|
|
25
|
+
code: string;
|
|
26
|
+
message: string;
|
|
27
|
+
}>): void;
|
|
18
28
|
protected handleTips(responseData: any): void;
|
|
29
|
+
protected showTipsNotification(tips: Array<{
|
|
30
|
+
code: string;
|
|
31
|
+
message: string;
|
|
32
|
+
}>): void;
|
|
19
33
|
private showSystemExceptionDialog;
|
|
20
34
|
protected reportError(errorInfo: any): Promise<void>;
|
|
35
|
+
protected request<R>(config: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
36
|
+
get<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
37
|
+
post<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
38
|
+
delete<R>(url: string, params?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
39
|
+
put<R>(url: string, data?: Record<string, any>, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
40
|
+
all<R>(requests: Array<AxiosRequestConfig | Promise<AxiosResponse<R>>>): Promise<AxiosResponse['data'][]>;
|
|
41
|
+
uploadFile<R>(url: string, file: File | Blob, config?: AxiosRequestConfig): Promise<AxiosResponse['data']>;
|
|
42
|
+
downloadFile(blob: Blob, filename?: string): void;
|
|
21
43
|
}
|
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("
|
|
5
|
+
if (!document.getElementById("75eddb1d-8897-4198-902d-b3b4a60a3856")) {
|
|
6
6
|
var elementStyle = document.createElement("style");
|
|
7
|
-
elementStyle.id = "
|
|
7
|
+
elementStyle.id = "75eddb1d-8897-4198-902d-b3b4a60a3856";
|
|
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
|
}
|
|
@@ -12170,7 +12170,11 @@ function extractSystemErrorInfo(response, code, message2) {
|
|
|
12170
12170
|
errorMessage: message2
|
|
12171
12171
|
};
|
|
12172
12172
|
}
|
|
12173
|
-
function defaultOnLoginRequired() {
|
|
12173
|
+
function defaultOnLoginRequired(messageInstance) {
|
|
12174
|
+
messageInstance == null ? void 0 : messageInstance.error({
|
|
12175
|
+
message: "登录已过期,请重新登录",
|
|
12176
|
+
duration: 5 * 1e3
|
|
12177
|
+
});
|
|
12174
12178
|
if (typeof window !== "undefined") {
|
|
12175
12179
|
window.location.href = `/login?redirect=${encodeURIComponent(window.location.href)}`;
|
|
12176
12180
|
}
|
|
@@ -12215,11 +12219,45 @@ class BaseHttpClient {
|
|
|
12215
12219
|
return config;
|
|
12216
12220
|
}
|
|
12217
12221
|
processResponseConfig(response) {
|
|
12222
|
+
this.handleHttpStatus(response);
|
|
12223
|
+
return this.handleSuccessResponse(response);
|
|
12224
|
+
}
|
|
12225
|
+
handleHttpStatus(response) {
|
|
12226
|
+
var _a2;
|
|
12227
|
+
if (response.status !== 200) {
|
|
12228
|
+
throw new Error(((_a2 = response.data) == null ? void 0 : _a2.message) || `HTTP Error: ${response.status}`);
|
|
12229
|
+
}
|
|
12230
|
+
}
|
|
12231
|
+
handleSuccessResponse(response) {
|
|
12218
12232
|
return response.data;
|
|
12219
12233
|
}
|
|
12220
12234
|
async processResponseError(error) {
|
|
12235
|
+
this.handleAuthenticationError(error);
|
|
12236
|
+
this.handleTimeoutError(error);
|
|
12237
|
+
this.handleNetworkError(error);
|
|
12221
12238
|
return error;
|
|
12222
12239
|
}
|
|
12240
|
+
handleAuthenticationError(error) {
|
|
12241
|
+
var _a2, _b;
|
|
12242
|
+
if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
|
|
12243
|
+
(_b = this.onLoginRequired) == null ? void 0 : _b.call(this, this.messageInstance);
|
|
12244
|
+
}
|
|
12245
|
+
}
|
|
12246
|
+
handleTimeoutError(error) {
|
|
12247
|
+
if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
|
|
12248
|
+
this.onTimeout(this.messageInstance);
|
|
12249
|
+
}
|
|
12250
|
+
}
|
|
12251
|
+
handleNetworkError(error) {
|
|
12252
|
+
var _a2, _b, _c;
|
|
12253
|
+
if (((_a2 = error.response) == null ? void 0 : _a2.status) !== 401 && error.code !== "ECONNABORTED") {
|
|
12254
|
+
const fallbackError = error;
|
|
12255
|
+
(_c = this.messageInstance) == null ? void 0 : _c.error({
|
|
12256
|
+
message: ((_b = fallbackError.response) == null ? void 0 : _b.data) || fallbackError.message || "网络错误",
|
|
12257
|
+
duration: 5 * 1e3
|
|
12258
|
+
});
|
|
12259
|
+
}
|
|
12260
|
+
}
|
|
12223
12261
|
setupInterceptors() {
|
|
12224
12262
|
this.instance.interceptors.request.use(
|
|
12225
12263
|
(config) => {
|
|
@@ -12238,34 +12276,10 @@ class BaseHttpClient {
|
|
|
12238
12276
|
);
|
|
12239
12277
|
this.instance.interceptors.response.use(
|
|
12240
12278
|
(res) => {
|
|
12241
|
-
var _a2;
|
|
12242
|
-
if (res.status !== 200) {
|
|
12243
|
-
return Promise.reject(new Error(((_a2 = res.data) == null ? void 0 : _a2.message) || "Error"));
|
|
12244
|
-
}
|
|
12245
12279
|
return this.processResponseConfig(res);
|
|
12246
12280
|
},
|
|
12247
12281
|
async (error) => {
|
|
12248
|
-
var _a2, _b, _c, _d, _e, _f;
|
|
12249
12282
|
await this.processResponseError(error);
|
|
12250
|
-
if (((_a2 = error.response) == null ? void 0 : _a2.status) === 401) {
|
|
12251
|
-
(_b = this.onLoginRequired) == null ? void 0 : _b.call(this);
|
|
12252
|
-
(_c = this.messageInstance) == null ? void 0 : _c.error({
|
|
12253
|
-
message: "登录已过期,请重新登录",
|
|
12254
|
-
duration: 5 * 1e3
|
|
12255
|
-
});
|
|
12256
|
-
} else if (error.code === "ECONNABORTED" && error.message.includes("timeout")) {
|
|
12257
|
-
this.onTimeout();
|
|
12258
|
-
(_d = this.messageInstance) == null ? void 0 : _d.error({
|
|
12259
|
-
message: "请求超时,请检查网络连接或稍后重试",
|
|
12260
|
-
duration: 5 * 1e3
|
|
12261
|
-
});
|
|
12262
|
-
} else {
|
|
12263
|
-
const fallbackError = error;
|
|
12264
|
-
(_f = this.messageInstance) == null ? void 0 : _f.error({
|
|
12265
|
-
message: ((_e = fallbackError.response) == null ? void 0 : _e.data) || fallbackError.message || "网络错误",
|
|
12266
|
-
duration: 5 * 1e3
|
|
12267
|
-
});
|
|
12268
|
-
}
|
|
12269
12283
|
return Promise.reject(error);
|
|
12270
12284
|
}
|
|
12271
12285
|
);
|
|
@@ -12308,6 +12322,20 @@ class BaseHttpClient {
|
|
|
12308
12322
|
}
|
|
12309
12323
|
});
|
|
12310
12324
|
}
|
|
12325
|
+
downloadFile(blob, filename) {
|
|
12326
|
+
if (typeof window === "undefined") {
|
|
12327
|
+
console.warn("downloadFile: 非浏览器环境,无法下载文件");
|
|
12328
|
+
return;
|
|
12329
|
+
}
|
|
12330
|
+
const url = window.URL.createObjectURL(blob);
|
|
12331
|
+
const link = document.createElement("a");
|
|
12332
|
+
link.href = url;
|
|
12333
|
+
link.download = filename || `download-${Date.now()}`;
|
|
12334
|
+
document.body.appendChild(link);
|
|
12335
|
+
link.click();
|
|
12336
|
+
document.body.removeChild(link);
|
|
12337
|
+
window.URL.revokeObjectURL(url);
|
|
12338
|
+
}
|
|
12311
12339
|
}
|
|
12312
12340
|
async function dynamicImports(modulePromise, exportNames) {
|
|
12313
12341
|
const module = await modulePromise;
|
|
@@ -12485,14 +12513,31 @@ class BaseApi extends BaseHttpClient {
|
|
|
12485
12513
|
processRequestConfig(config) {
|
|
12486
12514
|
return super.processRequestConfig(config);
|
|
12487
12515
|
}
|
|
12516
|
+
processResponseConfig(response) {
|
|
12517
|
+
return super.processResponseConfig(response);
|
|
12518
|
+
}
|
|
12488
12519
|
async processResponseError(error) {
|
|
12489
12520
|
return super.processResponseError(error);
|
|
12490
12521
|
}
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12522
|
+
handleHttpStatus(response) {
|
|
12523
|
+
return super.handleHttpStatus(response);
|
|
12524
|
+
}
|
|
12525
|
+
handleAuthenticationError(error) {
|
|
12526
|
+
super.handleAuthenticationError(error);
|
|
12527
|
+
}
|
|
12528
|
+
handleTimeoutError(error) {
|
|
12529
|
+
return super.handleTimeoutError(error);
|
|
12530
|
+
}
|
|
12531
|
+
handleNetworkError(error) {
|
|
12532
|
+
return super.handleNetworkError(error);
|
|
12533
|
+
}
|
|
12534
|
+
handleSuccessResponse(response) {
|
|
12535
|
+
const httpData = super.handleSuccessResponse(response);
|
|
12536
|
+
const parsedFields = this.parseResponseFields(httpData);
|
|
12537
|
+
const { code, message: message2, responseData } = parsedFields;
|
|
12538
|
+
this.handleSystemError(response, code, message2, responseData);
|
|
12539
|
+
this.handleBusinessError(code, message2);
|
|
12540
|
+
this.handleErrorArray(responseData);
|
|
12496
12541
|
this.handleTips(responseData);
|
|
12497
12542
|
return responseData;
|
|
12498
12543
|
}
|
|
@@ -12517,11 +12562,7 @@ class BaseApi extends BaseHttpClient {
|
|
|
12517
12562
|
const responseData = getValueByPath(data, (_c = this.responseFields) == null ? void 0 : _c.data);
|
|
12518
12563
|
return { code, message: message2, responseData };
|
|
12519
12564
|
}
|
|
12520
|
-
|
|
12521
|
-
var _a2;
|
|
12522
|
-
if (code === 401) {
|
|
12523
|
-
throw new Error("登录失效,请重新登录");
|
|
12524
|
-
}
|
|
12565
|
+
handleSystemError(response, code, message2, responseData) {
|
|
12525
12566
|
if (code === -1) {
|
|
12526
12567
|
if (this.enableSystemErrorDialog) {
|
|
12527
12568
|
this.showSystemExceptionDialog(response, responseData, code, message2).catch((error) => {
|
|
@@ -12530,6 +12571,9 @@ class BaseApi extends BaseHttpClient {
|
|
|
12530
12571
|
}
|
|
12531
12572
|
throw new Error(message2 || "系统异常");
|
|
12532
12573
|
}
|
|
12574
|
+
}
|
|
12575
|
+
handleBusinessError(code, message2) {
|
|
12576
|
+
var _a2;
|
|
12533
12577
|
if (code && code !== 200) {
|
|
12534
12578
|
(_a2 = this.messageInstance) == null ? void 0 : _a2.error({
|
|
12535
12579
|
message: message2 || "请求失败",
|
|
@@ -12538,55 +12582,63 @@ class BaseApi extends BaseHttpClient {
|
|
|
12538
12582
|
throw new Error(message2 || "请求失败");
|
|
12539
12583
|
}
|
|
12540
12584
|
}
|
|
12541
|
-
|
|
12542
|
-
var _a2
|
|
12585
|
+
handleErrorArray(responseData) {
|
|
12586
|
+
var _a2;
|
|
12543
12587
|
const errorsField = (_a2 = this.responseFields) == null ? void 0 : _a2.errors;
|
|
12544
12588
|
if (errorsField) {
|
|
12545
12589
|
const errors = responseData == null ? void 0 : responseData[errorsField];
|
|
12546
12590
|
if (Array.isArray(errors) && errors.length) {
|
|
12547
|
-
|
|
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
|
-
}
|
|
12591
|
+
this.showErrorArrayNotification(errors);
|
|
12562
12592
|
throw new Error("请求错误");
|
|
12563
12593
|
}
|
|
12564
12594
|
}
|
|
12565
12595
|
}
|
|
12596
|
+
showErrorArrayNotification(errors) {
|
|
12597
|
+
var _a2, _b;
|
|
12598
|
+
const html = errors.map((item) => `<div style="font-size: 14px;color:red">${item.code}:${item.message}</div>`).join("");
|
|
12599
|
+
if (hasDocument) {
|
|
12600
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, {
|
|
12601
|
+
title: "提示",
|
|
12602
|
+
message: html,
|
|
12603
|
+
type: "error"
|
|
12604
|
+
});
|
|
12605
|
+
} else {
|
|
12606
|
+
const errorMessages = errors.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12607
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
|
|
12608
|
+
title: "提示",
|
|
12609
|
+
message: errorMessages,
|
|
12610
|
+
type: "error"
|
|
12611
|
+
});
|
|
12612
|
+
}
|
|
12613
|
+
}
|
|
12566
12614
|
handleTips(responseData) {
|
|
12567
|
-
var _a2
|
|
12615
|
+
var _a2;
|
|
12568
12616
|
const tipsField = (_a2 = this.responseFields) == null ? void 0 : _a2.tips;
|
|
12569
12617
|
if (tipsField) {
|
|
12570
12618
|
const tips = responseData == null ? void 0 : responseData[tipsField];
|
|
12571
12619
|
if (Array.isArray(tips) && tips.length) {
|
|
12572
|
-
|
|
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
|
-
}
|
|
12620
|
+
this.showTipsNotification(tips);
|
|
12587
12621
|
}
|
|
12588
12622
|
}
|
|
12589
12623
|
}
|
|
12624
|
+
showTipsNotification(tips) {
|
|
12625
|
+
var _a2, _b;
|
|
12626
|
+
const html = tips.map((item) => `<div style="font-size: 14px;color:#E6A23C">${item.code}:${item.message}</div>`).join("");
|
|
12627
|
+
if (hasDocument) {
|
|
12628
|
+
(_a2 = this.notificationInstance) == null ? void 0 : _a2.call(this, {
|
|
12629
|
+
title: "提示",
|
|
12630
|
+
message: html,
|
|
12631
|
+
type: "warning"
|
|
12632
|
+
});
|
|
12633
|
+
} else {
|
|
12634
|
+
const tipMessages = tips.map((item) => `${item.code}:${item.message}`).join("\n");
|
|
12635
|
+
(_b = this.notificationInstance) == null ? void 0 : _b.call(this, {
|
|
12636
|
+
title: "提示",
|
|
12637
|
+
message: tipMessages,
|
|
12638
|
+
type: "warning"
|
|
12639
|
+
});
|
|
12640
|
+
}
|
|
12641
|
+
}
|
|
12590
12642
|
async showSystemExceptionDialog(response, responseData, code, message2) {
|
|
12591
12643
|
if (!hasDocument) {
|
|
12592
12644
|
console.error("系统异常信息:", responseData);
|
|
@@ -12642,6 +12694,30 @@ class BaseApi extends BaseHttpClient {
|
|
|
12642
12694
|
});
|
|
12643
12695
|
}
|
|
12644
12696
|
}
|
|
12697
|
+
async request(config) {
|
|
12698
|
+
return super.request(config);
|
|
12699
|
+
}
|
|
12700
|
+
async get(url, params, config) {
|
|
12701
|
+
return super.get(url, params, config);
|
|
12702
|
+
}
|
|
12703
|
+
async post(url, data, config) {
|
|
12704
|
+
return super.post(url, data, config);
|
|
12705
|
+
}
|
|
12706
|
+
async delete(url, params, config) {
|
|
12707
|
+
return super.delete(url, params, config);
|
|
12708
|
+
}
|
|
12709
|
+
async put(url, data, config) {
|
|
12710
|
+
return super.put(url, data, config);
|
|
12711
|
+
}
|
|
12712
|
+
async all(requests) {
|
|
12713
|
+
return super.all(requests);
|
|
12714
|
+
}
|
|
12715
|
+
async uploadFile(url, file, config) {
|
|
12716
|
+
return super.uploadFile(url, file, config);
|
|
12717
|
+
}
|
|
12718
|
+
downloadFile(blob, filename) {
|
|
12719
|
+
return super.downloadFile(blob, filename);
|
|
12720
|
+
}
|
|
12645
12721
|
}
|
|
12646
12722
|
function createHttpService(options = {}) {
|
|
12647
12723
|
return new BaseApi(options);
|
|
@@ -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,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, };
|