@ibiz-template/core 0.0.1-alpha.6 → 0.0.1-beta.130
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/dist/system/index.system.js +1 -0
- package/out/constant/core/core.d.ts +9 -0
- package/out/constant/core/core.d.ts.map +1 -1
- package/out/constant/core/core.js +9 -0
- package/out/constant/index.d.ts +3 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +3 -0
- package/out/constant/login-mode/login-mode.d.ts +23 -0
- package/out/constant/login-mode/login-mode.d.ts.map +1 -0
- package/out/constant/login-mode/login-mode.js +24 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
- package/out/constant/util/util.d.ts +5 -0
- package/out/constant/util/util.d.ts.map +1 -0
- package/out/constant/util/util.js +5 -0
- package/out/context/index.d.ts +49 -27
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +94 -55
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +16 -2
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +0 -4
- package/out/factory-center.d.ts +11 -0
- package/out/factory-center.d.ts.map +1 -0
- package/out/factory-center.js +10 -0
- package/out/ibizsys.d.ts +8 -1
- package/out/ibizsys.d.ts.map +1 -1
- package/out/ibizsys.js +8 -1
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/install.d.ts.map +1 -1
- package/out/install.js +4 -2
- package/out/interface/click-outside/click-outside.d.ts +70 -0
- package/out/interface/click-outside/click-outside.d.ts.map +1 -0
- package/out/interface/click-outside/click-outside.js +1 -0
- package/out/interface/i-environment/i-environment.d.ts +108 -4
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/interface/index.d.ts +1 -0
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/index.js +1 -1
- package/out/types.d.ts +41 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/click-outside/click-outside.d.ts +14 -0
- package/out/utils/click-outside/click-outside.d.ts.map +1 -0
- package/out/utils/click-outside/click-outside.js +85 -0
- package/out/utils/color/color.d.ts +13 -0
- package/out/utils/color/color.d.ts.map +1 -0
- package/out/utils/color/color.js +76 -0
- package/out/utils/download-file/download-file.d.ts +31 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -0
- package/out/utils/download-file/download-file.js +107 -0
- package/out/utils/event/event.d.ts +34 -0
- package/out/utils/event/event.d.ts.map +1 -0
- package/out/utils/event/event.js +60 -0
- package/out/utils/index.d.ts +11 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +11 -1
- package/out/utils/interceptor/core-interceptor.d.ts +15 -0
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/core-interceptor.js +30 -0
- package/out/utils/interceptor/index.d.ts +3 -0
- package/out/utils/interceptor/index.d.ts.map +1 -0
- package/out/utils/interceptor/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts +74 -3
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +73 -22
- package/out/utils/logger/logger.d.ts +3 -0
- package/out/utils/logger/logger.d.ts.map +1 -0
- package/out/utils/logger/logger.js +2 -0
- package/out/utils/net/http-response.d.ts +4 -9
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/http-response.js +0 -7
- package/out/utils/net/net.d.ts +98 -30
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +133 -38
- package/out/utils/plural/plural.d.ts.map +1 -1
- package/out/utils/plural/plural.js +2 -0
- package/out/utils/string-util/string-util.d.ts +46 -0
- package/out/utils/string-util/string-util.d.ts.map +1 -0
- package/out/utils/string-util/string-util.js +71 -0
- package/out/utils/sync/await-timeout.d.ts +14 -0
- package/out/utils/sync/await-timeout.d.ts.map +1 -0
- package/out/utils/sync/await-timeout.js +23 -0
- package/out/utils/sync/count-latch.d.ts +60 -0
- package/out/utils/sync/count-latch.d.ts.map +1 -0
- package/out/utils/sync/count-latch.js +90 -0
- package/out/utils/sync/index.d.ts +3 -0
- package/out/utils/sync/index.d.ts.map +1 -0
- package/out/utils/sync/index.js +2 -0
- package/out/utils/upload/select-file.d.ts +53 -0
- package/out/utils/upload/select-file.d.ts.map +1 -0
- package/out/utils/upload/select-file.js +47 -0
- package/out/utils/upload/upload-file.d.ts +46 -0
- package/out/utils/upload/upload-file.d.ts.map +1 -0
- package/out/utils/upload/upload-file.js +150 -0
- package/out/utils/url-helper/url-helper.d.ts +51 -0
- package/out/utils/url-helper/url-helper.d.ts.map +1 -0
- package/out/utils/url-helper/url-helper.js +59 -0
- package/out/utils/util/util.d.ts +20 -4
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +59 -5
- package/package.json +21 -10
- package/src/constant/core/core.ts +10 -0
- package/src/constant/index.ts +3 -0
- package/src/constant/login-mode/login-mode.ts +23 -0
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
- package/src/constant/util/util.ts +5 -0
- package/src/context/index.ts +127 -51
- package/src/environment/environment.ts +16 -2
- package/src/error/http-error/http-error.ts +0 -4
- package/src/factory-center.ts +9 -0
- package/src/ibizsys.ts +9 -1
- package/src/index.ts +2 -1
- package/src/install.ts +4 -2
- package/src/interface/click-outside/click-outside.ts +71 -0
- package/src/interface/i-environment/i-environment.ts +122 -4
- package/src/interface/index.ts +1 -0
- package/src/types.ts +45 -0
- package/src/utils/click-outside/click-outside.ts +110 -0
- package/src/utils/color/color.ts +84 -0
- package/src/utils/download-file/download-file.ts +109 -0
- package/src/utils/event/event.ts +77 -0
- package/src/utils/index.ts +11 -1
- package/src/utils/interceptor/core-interceptor.ts +35 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +109 -22
- package/src/utils/logger/logger.ts +3 -0
- package/src/utils/net/http-response.ts +6 -9
- package/src/utils/net/net.ts +171 -50
- package/src/utils/plural/plural.ts +3 -0
- package/src/utils/string-util/string-util.ts +75 -0
- package/src/utils/sync/await-timeout.ts +27 -0
- package/src/utils/sync/count-latch.ts +96 -0
- package/src/utils/sync/index.ts +2 -0
- package/src/utils/upload/select-file.ts +86 -0
- package/src/utils/upload/upload-file.ts +206 -0
- package/src/utils/url-helper/url-helper.ts +62 -0
- package/src/utils/util/util.ts +72 -14
- package/LICENSE +0 -21
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 根据文件名称计算Mime类型
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-11-16 22:11:02
|
|
6
|
+
* @export
|
|
7
|
+
* @param {string} fileName
|
|
8
|
+
* @returns {*}
|
|
9
|
+
*/
|
|
10
|
+
export function calcMimeByFileName(fileName) {
|
|
11
|
+
const ext = fileName.split('.').pop();
|
|
12
|
+
let mime = '';
|
|
13
|
+
switch (ext) {
|
|
14
|
+
case '.wps':
|
|
15
|
+
mime = 'application/kswps';
|
|
16
|
+
break;
|
|
17
|
+
case '.doc':
|
|
18
|
+
mime = 'application/msword';
|
|
19
|
+
break;
|
|
20
|
+
case '.docx':
|
|
21
|
+
mime =
|
|
22
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
23
|
+
break;
|
|
24
|
+
case '.txt':
|
|
25
|
+
mime = 'text/plain';
|
|
26
|
+
break;
|
|
27
|
+
case '.zip':
|
|
28
|
+
mime = 'application/zip';
|
|
29
|
+
break;
|
|
30
|
+
case '.png':
|
|
31
|
+
mime = 'image/png';
|
|
32
|
+
break;
|
|
33
|
+
case '.gif':
|
|
34
|
+
mime = 'image/gif';
|
|
35
|
+
break;
|
|
36
|
+
case '.jpeg':
|
|
37
|
+
mime = 'image/jpeg';
|
|
38
|
+
break;
|
|
39
|
+
case '.jpg':
|
|
40
|
+
mime = 'image/jpeg';
|
|
41
|
+
break;
|
|
42
|
+
case '.rtf':
|
|
43
|
+
mime = 'application/rtf';
|
|
44
|
+
break;
|
|
45
|
+
case '.avi':
|
|
46
|
+
mime = 'video/x-msvideo';
|
|
47
|
+
break;
|
|
48
|
+
case '.gz':
|
|
49
|
+
mime = 'application/x-gzip';
|
|
50
|
+
break;
|
|
51
|
+
case '.tar':
|
|
52
|
+
mime = 'application/x-tar';
|
|
53
|
+
break;
|
|
54
|
+
case '.xlsx':
|
|
55
|
+
mime = 'application/vnd.ms-excel';
|
|
56
|
+
break;
|
|
57
|
+
default:
|
|
58
|
+
mime = '';
|
|
59
|
+
}
|
|
60
|
+
return mime;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 判断是否是图片格式
|
|
64
|
+
*
|
|
65
|
+
* @author lxm
|
|
66
|
+
* @date 2022-11-21 13:11:23
|
|
67
|
+
* @export
|
|
68
|
+
* @param {string} fileName
|
|
69
|
+
* @returns {*} {boolean}
|
|
70
|
+
*/
|
|
71
|
+
export function isImage(fileName) {
|
|
72
|
+
const ext = fileName.split('.').pop();
|
|
73
|
+
if (!ext) {
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
const imageTypes = ['.jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
|
|
77
|
+
return imageTypes.includes(ext);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 纯JS触发下载文件
|
|
81
|
+
*
|
|
82
|
+
* @author lxm
|
|
83
|
+
* @date 2022-11-16 22:11:24
|
|
84
|
+
* @export
|
|
85
|
+
* @param {Blob} file 文件流Blob
|
|
86
|
+
* @param {string} fileName 文件名称
|
|
87
|
+
*/
|
|
88
|
+
export function downloadFileFromBlob(file, fileName) {
|
|
89
|
+
// 获取文件名
|
|
90
|
+
const filetype = calcMimeByFileName(fileName);
|
|
91
|
+
// 用blob对象获取文件流
|
|
92
|
+
const blob = new Blob([file], { type: filetype });
|
|
93
|
+
// 通过文件流创建下载链接
|
|
94
|
+
const href = URL.createObjectURL(blob);
|
|
95
|
+
// 创建一个a元素并设置相关属性
|
|
96
|
+
const a = document.createElement('a');
|
|
97
|
+
a.href = href;
|
|
98
|
+
a.download = fileName;
|
|
99
|
+
// 添加a元素到当前网页
|
|
100
|
+
document.body.appendChild(a);
|
|
101
|
+
// 触发a元素的点击事件,实现下载
|
|
102
|
+
a.click();
|
|
103
|
+
// 从当前网页移除a元素
|
|
104
|
+
document.body.removeChild(a);
|
|
105
|
+
// 释放blob对象
|
|
106
|
+
URL.revokeObjectURL(href);
|
|
107
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-28 17:10:14
|
|
6
|
+
* @param {MouseEvent} event
|
|
7
|
+
* @returns {*}
|
|
8
|
+
*/
|
|
9
|
+
export declare function eventPath(event: MouseEvent): (EventTarget | null)[];
|
|
10
|
+
/**
|
|
11
|
+
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
12
|
+
*
|
|
13
|
+
* @author lxm
|
|
14
|
+
* @date 2022-10-28 18:10:36
|
|
15
|
+
* @export
|
|
16
|
+
* @param {EventTarget} target 监听对象
|
|
17
|
+
* @param {string} eventName 监听事件名称
|
|
18
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
19
|
+
* @param {AddEventListenerOptions} options 额外参数
|
|
20
|
+
* @returns {*} {() => void}
|
|
21
|
+
*/
|
|
22
|
+
export declare function listenJSEvent(target: EventTarget, eventName: string, listener: (..._args: any[]) => any, options?: AddEventListenerOptions): () => void;
|
|
23
|
+
/**
|
|
24
|
+
* event是否是在目标元素内部触发的
|
|
25
|
+
*
|
|
26
|
+
* @author lxm
|
|
27
|
+
* @date 2022-10-31 11:10:49
|
|
28
|
+
* @export
|
|
29
|
+
* @param {MouseEvent} event 原生事件
|
|
30
|
+
* @param {HTMLElement} el 目标元素
|
|
31
|
+
* @returns {*} {boolean}
|
|
32
|
+
*/
|
|
33
|
+
export declare function isEventInside(event: MouseEvent, el: HTMLElement): boolean;
|
|
34
|
+
//# sourceMappingURL=event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/utils/event/event.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAmBnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,OAAO,GAAE,uBAA4B,GACpC,MAAM,IAAI,CAYZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAEzE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { NOOP } from '../../constant';
|
|
3
|
+
/**
|
|
4
|
+
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-28 17:10:14
|
|
8
|
+
* @param {MouseEvent} event
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
export function eventPath(event) {
|
|
12
|
+
const path = ((event.composedPath && event.composedPath()) ||
|
|
13
|
+
event.path);
|
|
14
|
+
if (path != null)
|
|
15
|
+
return path;
|
|
16
|
+
// 浏览器没有提供的,自己递归计算
|
|
17
|
+
function getParents(node, memo = []) {
|
|
18
|
+
const parentNode = node.parentNode;
|
|
19
|
+
return parentNode
|
|
20
|
+
? getParents(parentNode, memo.concat([parentNode]))
|
|
21
|
+
: memo;
|
|
22
|
+
}
|
|
23
|
+
return [event.target].concat(getParents(event.target));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
27
|
+
*
|
|
28
|
+
* @author lxm
|
|
29
|
+
* @date 2022-10-28 18:10:36
|
|
30
|
+
* @export
|
|
31
|
+
* @param {EventTarget} target 监听对象
|
|
32
|
+
* @param {string} eventName 监听事件名称
|
|
33
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
34
|
+
* @param {AddEventListenerOptions} options 额外参数
|
|
35
|
+
* @returns {*} {() => void}
|
|
36
|
+
*/
|
|
37
|
+
export function listenJSEvent(target, eventName, listener, options = {}) {
|
|
38
|
+
target.addEventListener(eventName, listener, options);
|
|
39
|
+
let cleanup = () => {
|
|
40
|
+
target.removeEventListener(eventName, listener, options);
|
|
41
|
+
// cleanup方法只能调用一次
|
|
42
|
+
cleanup = NOOP;
|
|
43
|
+
};
|
|
44
|
+
return () => {
|
|
45
|
+
cleanup();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* event是否是在目标元素内部触发的
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-31 11:10:49
|
|
53
|
+
* @export
|
|
54
|
+
* @param {MouseEvent} event 原生事件
|
|
55
|
+
* @param {HTMLElement} el 目标元素
|
|
56
|
+
* @returns {*} {boolean}
|
|
57
|
+
*/
|
|
58
|
+
export function isEventInside(event, el) {
|
|
59
|
+
return el && (event.target === el || eventPath(event).includes(el));
|
|
60
|
+
}
|
package/out/utils/index.d.ts
CHANGED
|
@@ -1,7 +1,17 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './interceptor';
|
|
2
|
+
export { Logger } from './logger/logger';
|
|
2
3
|
export { Namespace } from './namespace/namespace';
|
|
3
4
|
export { IHttpResponse, HttpResponse } from './net/http-response';
|
|
4
5
|
export { Net } from './net/net';
|
|
5
6
|
export { plural, pluralLower } from './plural/plural';
|
|
6
7
|
export * from './util/util';
|
|
8
|
+
export * from './url-helper/url-helper';
|
|
9
|
+
export * from './event/event';
|
|
10
|
+
export * from './click-outside/click-outside';
|
|
11
|
+
export * from './color/color';
|
|
12
|
+
export * from './download-file/download-file';
|
|
13
|
+
export * from './upload/select-file';
|
|
14
|
+
export * from './upload/upload-file';
|
|
15
|
+
export * from './sync';
|
|
16
|
+
export { StringUtil } from './string-util/string-util';
|
|
7
17
|
//# sourceMappingURL=index.d.ts.map
|
package/out/utils/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AACvB,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC"}
|
package/out/utils/index.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from './interceptor';
|
|
2
|
+
export { Logger } from './logger/logger';
|
|
2
3
|
export { Namespace } from './namespace/namespace';
|
|
3
4
|
export { HttpResponse } from './net/http-response';
|
|
4
5
|
export { Net } from './net/net';
|
|
5
6
|
export { plural, pluralLower } from './plural/plural';
|
|
6
7
|
export * from './util/util';
|
|
8
|
+
export * from './url-helper/url-helper';
|
|
9
|
+
export * from './event/event';
|
|
10
|
+
export * from './click-outside/click-outside';
|
|
11
|
+
export * from './color/color';
|
|
12
|
+
export * from './download-file/download-file';
|
|
13
|
+
export * from './upload/select-file';
|
|
14
|
+
export * from './upload/upload-file';
|
|
15
|
+
export * from './sync';
|
|
16
|
+
export { StringUtil } from './string-util/string-util';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { Interceptor } from './interceptor';
|
|
3
|
+
/**
|
|
4
|
+
* 核心包拦截器
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-27 17:10:48
|
|
8
|
+
* @export
|
|
9
|
+
* @class CoreInterceptor
|
|
10
|
+
* @extends {Interceptor}
|
|
11
|
+
*/
|
|
12
|
+
export declare class CoreInterceptor extends Interceptor {
|
|
13
|
+
protected onBeforeRequest(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=core-interceptor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core-interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/core-interceptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,OAAO,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C;;;;;;;;GAQG;AACH,qBAAa,eAAgB,SAAQ,WAAW;cAC9B,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;CAkB/B"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getToken } from '../util/util';
|
|
2
|
+
import { Interceptor } from './interceptor';
|
|
3
|
+
/**
|
|
4
|
+
* 核心包拦截器
|
|
5
|
+
*
|
|
6
|
+
* @author lxm
|
|
7
|
+
* @date 2022-10-27 17:10:48
|
|
8
|
+
* @export
|
|
9
|
+
* @class CoreInterceptor
|
|
10
|
+
* @extends {Interceptor}
|
|
11
|
+
*/
|
|
12
|
+
export class CoreInterceptor extends Interceptor {
|
|
13
|
+
async onBeforeRequest(config) {
|
|
14
|
+
await super.onBeforeRequest(config);
|
|
15
|
+
if (!config.headers) {
|
|
16
|
+
config.headers = {};
|
|
17
|
+
}
|
|
18
|
+
config.headers.Authorization = `Bearer ${getToken()}`;
|
|
19
|
+
const { orgData } = ibiz;
|
|
20
|
+
if (orgData) {
|
|
21
|
+
if (orgData.systemid) {
|
|
22
|
+
config.headers.srfsystemid = orgData.systemid;
|
|
23
|
+
}
|
|
24
|
+
if (orgData.orgid) {
|
|
25
|
+
config.headers.srforgid = orgData.orgid;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return config;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* 拦截器基类
|
|
3
4
|
*
|
|
4
5
|
* @author chitanda
|
|
5
6
|
* @date 2022-07-20 18:07:11
|
|
@@ -7,7 +8,77 @@
|
|
|
7
8
|
* @class Interceptor
|
|
8
9
|
*/
|
|
9
10
|
export declare class Interceptor {
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
/**
|
|
12
|
+
* 请求拦截器绑定标识
|
|
13
|
+
*
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2022-10-27 17:10:20
|
|
16
|
+
* @private
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
private requestTag?;
|
|
20
|
+
/**
|
|
21
|
+
* 响应拦截器绑定标识
|
|
22
|
+
*
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2022-10-27 17:10:19
|
|
25
|
+
* @private
|
|
26
|
+
* @type {number}
|
|
27
|
+
*/
|
|
28
|
+
private responseTag?;
|
|
29
|
+
/**
|
|
30
|
+
* 请求之前处理
|
|
31
|
+
*
|
|
32
|
+
* @author lxm
|
|
33
|
+
* @date 2022-10-27 17:10:41
|
|
34
|
+
* @protected
|
|
35
|
+
* @param {AxiosRequestConfig} config
|
|
36
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
37
|
+
*/
|
|
38
|
+
protected onBeforeRequest(config: AxiosRequestConfig): Promise<AxiosRequestConfig>;
|
|
39
|
+
/**
|
|
40
|
+
* 请求失败之后处理
|
|
41
|
+
*
|
|
42
|
+
* @author lxm
|
|
43
|
+
* @date 2022-10-27 17:10:40
|
|
44
|
+
* @protected
|
|
45
|
+
* @param {*} error
|
|
46
|
+
*/
|
|
47
|
+
protected onRequestError(error: any): Promise<never>;
|
|
48
|
+
/**
|
|
49
|
+
* 响应成功之后处理
|
|
50
|
+
*
|
|
51
|
+
* @author lxm
|
|
52
|
+
* @date 2022-10-27 17:10:38
|
|
53
|
+
* @protected
|
|
54
|
+
* @param {AxiosResponse} config
|
|
55
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
56
|
+
*/
|
|
57
|
+
protected onResponseSuccess(config: AxiosResponse): Promise<AxiosResponse>;
|
|
58
|
+
/**
|
|
59
|
+
* 响应失败之后处理
|
|
60
|
+
*
|
|
61
|
+
* @author lxm
|
|
62
|
+
* @date 2022-10-27 17:10:37
|
|
63
|
+
* @protected
|
|
64
|
+
* @param {*} _error
|
|
65
|
+
*/
|
|
66
|
+
protected onResponseError(error: any): Promise<never>;
|
|
67
|
+
/**
|
|
68
|
+
* 使用拦截器
|
|
69
|
+
*
|
|
70
|
+
* @author lxm
|
|
71
|
+
* @date 2022-10-27 17:10:28
|
|
72
|
+
* @param {AxiosInstance} instance
|
|
73
|
+
*/
|
|
74
|
+
use(instance: AxiosInstance): void;
|
|
75
|
+
/**
|
|
76
|
+
* 移出拦截器
|
|
77
|
+
*
|
|
78
|
+
* @author lxm
|
|
79
|
+
* @date 2022-10-27 17:10:27
|
|
80
|
+
* @param {AxiosInstance} instance
|
|
81
|
+
*/
|
|
82
|
+
eject(instance: AxiosInstance): void;
|
|
12
83
|
}
|
|
13
84
|
//# sourceMappingURL=interceptor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"interceptor.d.ts","sourceRoot":"","sources":["../../../src/utils/interceptor/interceptor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEzE;;;;;;;GAOG;AACH,qBAAa,WAAW;IACtB;;;;;;;OAOG;IACH,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;IACH,OAAO,CAAC,WAAW,CAAC,CAAS;IAE7B;;;;;;;;OAQG;cACa,eAAe,CAC7B,MAAM,EAAE,kBAAkB,GACzB,OAAO,CAAC,kBAAkB,CAAC;IAI9B;;;;;;;OAOG;IACH,SAAS,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG;IAKnC;;;;;;;;OAQG;cACa,iBAAiB,CAC/B,MAAM,EAAE,aAAa,GACpB,OAAO,CAAC,aAAa,CAAC;IAIzB;;;;;;;OAOG;IACH,SAAS,CAAC,eAAe,CAAC,KAAK,EAAE,GAAG;IAKpC;;;;;;OAMG;IACH,GAAG,CAAC,QAAQ,EAAE,aAAa,GAAG,IAAI;IAWlC;;;;;;OAMG;IACH,KAAK,CAAC,QAAQ,EAAE,aAAa;CAQ9B"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
import { getToken } from '../util/util';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* 拦截器基类
|
|
5
3
|
*
|
|
6
4
|
* @author chitanda
|
|
7
5
|
* @date 2022-07-20 18:07:11
|
|
@@ -9,25 +7,78 @@ import { getToken } from '../util/util';
|
|
|
9
7
|
* @class Interceptor
|
|
10
8
|
*/
|
|
11
9
|
export class Interceptor {
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
/**
|
|
11
|
+
* 请求之前处理
|
|
12
|
+
*
|
|
13
|
+
* @author lxm
|
|
14
|
+
* @date 2022-10-27 17:10:41
|
|
15
|
+
* @protected
|
|
16
|
+
* @param {AxiosRequestConfig} config
|
|
17
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
18
|
+
*/
|
|
19
|
+
async onBeforeRequest(config) {
|
|
20
|
+
return config;
|
|
14
21
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
/**
|
|
23
|
+
* 请求失败之后处理
|
|
24
|
+
*
|
|
25
|
+
* @author lxm
|
|
26
|
+
* @date 2022-10-27 17:10:40
|
|
27
|
+
* @protected
|
|
28
|
+
* @param {*} error
|
|
29
|
+
*/
|
|
30
|
+
onRequestError(error) {
|
|
31
|
+
// 处理请求错误
|
|
32
|
+
return Promise.reject(error);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 响应成功之后处理
|
|
36
|
+
*
|
|
37
|
+
* @author lxm
|
|
38
|
+
* @date 2022-10-27 17:10:38
|
|
39
|
+
* @protected
|
|
40
|
+
* @param {AxiosResponse} config
|
|
41
|
+
* @returns {*} {Promise<AxiosRequestConfig>}
|
|
42
|
+
*/
|
|
43
|
+
async onResponseSuccess(config) {
|
|
44
|
+
return config;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* 响应失败之后处理
|
|
48
|
+
*
|
|
49
|
+
* @author lxm
|
|
50
|
+
* @date 2022-10-27 17:10:37
|
|
51
|
+
* @protected
|
|
52
|
+
* @param {*} _error
|
|
53
|
+
*/
|
|
54
|
+
onResponseError(error) {
|
|
55
|
+
// 处理响应错误
|
|
56
|
+
return Promise.reject(error);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* 使用拦截器
|
|
60
|
+
*
|
|
61
|
+
* @author lxm
|
|
62
|
+
* @date 2022-10-27 17:10:28
|
|
63
|
+
* @param {AxiosInstance} instance
|
|
64
|
+
*/
|
|
65
|
+
use(instance) {
|
|
66
|
+
this.requestTag = instance.interceptors.request.use(this.onBeforeRequest, this.onRequestError);
|
|
67
|
+
this.responseTag = instance.interceptors.response.use(this.onResponseSuccess, this.onResponseError);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 移出拦截器
|
|
71
|
+
*
|
|
72
|
+
* @author lxm
|
|
73
|
+
* @date 2022-10-27 17:10:27
|
|
74
|
+
* @param {AxiosInstance} instance
|
|
75
|
+
*/
|
|
76
|
+
eject(instance) {
|
|
77
|
+
if (this.requestTag) {
|
|
78
|
+
instance.interceptors.request.eject(this.requestTag);
|
|
79
|
+
}
|
|
80
|
+
if (this.responseTag) {
|
|
81
|
+
instance.interceptors.response.eject(this.responseTag);
|
|
82
|
+
}
|
|
32
83
|
}
|
|
33
84
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AAEnC,OAAO,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -27,7 +27,7 @@ export interface IHttpResponse<T = IData> extends AxiosResponse {
|
|
|
27
27
|
* @date 2022-08-18 15:08:44
|
|
28
28
|
* @type {boolean}
|
|
29
29
|
*/
|
|
30
|
-
local
|
|
30
|
+
local: boolean;
|
|
31
31
|
data: T;
|
|
32
32
|
/**
|
|
33
33
|
* 当前页
|
|
@@ -64,14 +64,9 @@ export declare class HttpResponse<T = IData> implements IHttpResponse<T> {
|
|
|
64
64
|
data: T;
|
|
65
65
|
status: number;
|
|
66
66
|
statusText: string;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
* @author chitanda
|
|
71
|
-
* @date 2022-08-18 15:08:46
|
|
72
|
-
* @type {AxiosResponseHeaders}
|
|
73
|
-
*/
|
|
74
|
-
headers: AxiosResponseHeaders;
|
|
67
|
+
headers: AxiosResponseHeaders | Partial<Record<string, string> & {
|
|
68
|
+
'set-cookie'?: string[] | undefined;
|
|
69
|
+
}>;
|
|
75
70
|
/**
|
|
76
71
|
* AxiosResponse 本地仿造时值为空
|
|
77
72
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../src/utils/net/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,KAAK,CAAE,SAAQ,aAAa;IAC7D;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,
|
|
1
|
+
{"version":3,"file":"http-response.d.ts","sourceRoot":"","sources":["../../../src/utils/net/http-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAEhF;;;;;;;;;GASG;AACH,MAAM,WAAW,aAAa,CAAC,CAAC,GAAG,KAAK,CAAE,SAAQ,aAAa;IAC7D;;;;;;;OAOG;IACH,EAAE,EAAE,OAAO,CAAC;IACZ;;;;;;;OAOG;IACH,KAAK,EAAE,OAAO,CAAC;IAEf,IAAI,EAAE,CAAC,CAAC;IAER;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;GASG;AACH,qBAAa,YAAY,CAAC,CAAC,GAAG,KAAK,CAAE,YAAW,aAAa,CAAC,CAAC,CAAC;IAC9D;;;;;OAKG;IACH,KAAK,UAAQ;IAEb,EAAE,UAAS;IAEX,IAAI,EAAE,CAAC,CAAC;IAER,MAAM,EAAE,MAAM,CAAC;IAEf,UAAU,EAAE,MAAM,CAAC;IAEnB,OAAO,EACH,oBAAoB,GACpB,OAAO,CACL,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG;QAAE,YAAY,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;KAAE,CACjE,CAAM;IAEX;;;;;;OAMG;IACH,MAAM,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAM;IAEvC;;;;;;;;OAQG;gBACS,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM;CAQjE"}
|
|
@@ -27,13 +27,6 @@ export class HttpResponse {
|
|
|
27
27
|
*/
|
|
28
28
|
this.local = true;
|
|
29
29
|
this.ok = false;
|
|
30
|
-
/**
|
|
31
|
-
* header 本地仿造时值为空
|
|
32
|
-
*
|
|
33
|
-
* @author chitanda
|
|
34
|
-
* @date 2022-08-18 15:08:46
|
|
35
|
-
* @type {AxiosResponseHeaders}
|
|
36
|
-
*/
|
|
37
30
|
this.headers = {};
|
|
38
31
|
/**
|
|
39
32
|
* AxiosResponse 本地仿造时值为空
|