@ibiz-template/core 0.0.1-beta.1 → 0.0.1-beta.141
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 -1
- 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/context/index.d.ts +63 -4
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +73 -3
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +6 -0
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +0 -4
- package/out/interface/click-outside/click-outside.d.ts +1 -1
- package/out/interface/click-outside/click-outside.d.ts.map +1 -1
- package/out/interface/i-environment/i-environment.d.ts +44 -0
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/types.d.ts +31 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/data-type/data-types.d.ts +47 -0
- package/out/utils/data-type/data-types.d.ts.map +1 -0
- package/out/utils/data-type/data-types.js +96 -0
- package/out/utils/download-file/download-file.d.ts +10 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -1
- package/out/utils/download-file/download-file.js +20 -0
- package/out/utils/index.d.ts +6 -0
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +6 -0
- package/out/utils/interceptor/core-interceptor.d.ts +1 -2
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/core-interceptor.js +12 -7
- package/out/utils/interceptor/interceptor.d.ts +6 -6
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +2 -2
- package/out/utils/logger/logger.d.ts +1 -1
- package/out/utils/logger/logger.d.ts.map +1 -1
- package/out/utils/logger/logger.js +1 -1
- package/out/utils/net/http-response.d.ts +1 -3
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/net.d.ts +30 -13
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +37 -11
- 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 +151 -0
- package/out/utils/util/ie-helper.d.ts +12 -0
- package/out/utils/util/ie-helper.d.ts.map +1 -0
- package/out/utils/util/ie-helper.js +20 -0
- package/package.json +13 -11
- package/src/constant/core/core.ts +10 -0
- package/src/context/index.ts +115 -5
- package/src/environment/environment.ts +6 -0
- package/src/error/http-error/http-error.ts +0 -4
- package/src/interface/i-environment/i-environment.ts +50 -0
- package/src/types.ts +35 -0
- package/src/utils/data-type/data-types.ts +99 -0
- package/src/utils/download-file/download-file.ts +21 -0
- package/src/utils/index.ts +6 -0
- package/src/utils/interceptor/core-interceptor.ts +16 -11
- package/src/utils/interceptor/interceptor.ts +7 -9
- package/src/utils/logger/logger.ts +1 -1
- package/src/utils/net/http-response.ts +1 -5
- package/src/utils/net/net.ts +45 -22
- 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 +207 -0
- package/src/utils/util/ie-helper.ts +42 -0
- package/LICENSE +0 -21
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 计数插销工具类
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-11-24 19:11:49
|
|
6
|
+
* @export
|
|
7
|
+
* @class CountLatch
|
|
8
|
+
*/
|
|
9
|
+
export declare class CountLatch {
|
|
10
|
+
private promise;
|
|
11
|
+
private resolve;
|
|
12
|
+
/**
|
|
13
|
+
* 计数,当前等待的异步逻辑个数
|
|
14
|
+
*
|
|
15
|
+
* @author lxm
|
|
16
|
+
* @date 2022-11-24 19:11:59
|
|
17
|
+
* @type {number}
|
|
18
|
+
*/
|
|
19
|
+
count: number;
|
|
20
|
+
/**
|
|
21
|
+
* 开启promise
|
|
22
|
+
*
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2022-11-24 19:11:32
|
|
25
|
+
* @private
|
|
26
|
+
*/
|
|
27
|
+
private startPromise;
|
|
28
|
+
/**
|
|
29
|
+
* 结束promise
|
|
30
|
+
*
|
|
31
|
+
* @author lxm
|
|
32
|
+
* @date 2022-11-24 19:11:44
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
private endPromise;
|
|
36
|
+
/**
|
|
37
|
+
* 上锁,计数加一
|
|
38
|
+
* 第一次计数,开启异步
|
|
39
|
+
*
|
|
40
|
+
* @author lxm
|
|
41
|
+
* @date 2022-11-24 19:11:27
|
|
42
|
+
*/
|
|
43
|
+
lock(): void;
|
|
44
|
+
/**
|
|
45
|
+
* 解锁,计数减一
|
|
46
|
+
* 归零时结束异步
|
|
47
|
+
*
|
|
48
|
+
* @author lxm
|
|
49
|
+
* @date 2022-11-24 19:11:47
|
|
50
|
+
*/
|
|
51
|
+
unlock(): void;
|
|
52
|
+
/**
|
|
53
|
+
* 等待,计数归零异步结束
|
|
54
|
+
*
|
|
55
|
+
* @author lxm
|
|
56
|
+
* @date 2022-11-24 19:11:20
|
|
57
|
+
*/
|
|
58
|
+
await(): Promise<void>;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=count-latch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"count-latch.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/count-latch.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAA8B;IAE7C,OAAO,CAAC,OAAO,CAAwC;IAEvD;;;;;;OAMG;IACH,KAAK,EAAE,MAAM,CAAK;IAElB;;;;;;OAMG;IACH,OAAO,CAAC,YAAY;IAMpB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;IAQlB;;;;;;OAMG;IACH,IAAI;IAOJ;;;;;;OAMG;IACH,MAAM;IAWN;;;;;OAKG;IACG,KAAK;CAKZ"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { RuntimeError } from '../../error';
|
|
2
|
+
/**
|
|
3
|
+
* 计数插销工具类
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2022-11-24 19:11:49
|
|
7
|
+
* @export
|
|
8
|
+
* @class CountLatch
|
|
9
|
+
*/
|
|
10
|
+
export class CountLatch {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.promise = null;
|
|
13
|
+
this.resolve = null;
|
|
14
|
+
/**
|
|
15
|
+
* 计数,当前等待的异步逻辑个数
|
|
16
|
+
*
|
|
17
|
+
* @author lxm
|
|
18
|
+
* @date 2022-11-24 19:11:59
|
|
19
|
+
* @type {number}
|
|
20
|
+
*/
|
|
21
|
+
this.count = 0;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 开启promise
|
|
25
|
+
*
|
|
26
|
+
* @author lxm
|
|
27
|
+
* @date 2022-11-24 19:11:32
|
|
28
|
+
* @private
|
|
29
|
+
*/
|
|
30
|
+
startPromise() {
|
|
31
|
+
this.promise = new Promise(resolve => {
|
|
32
|
+
this.resolve = resolve;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 结束promise
|
|
37
|
+
*
|
|
38
|
+
* @author lxm
|
|
39
|
+
* @date 2022-11-24 19:11:44
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
endPromise() {
|
|
43
|
+
if (this.resolve) {
|
|
44
|
+
this.resolve();
|
|
45
|
+
this.resolve = null;
|
|
46
|
+
this.promise = null;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 上锁,计数加一
|
|
51
|
+
* 第一次计数,开启异步
|
|
52
|
+
*
|
|
53
|
+
* @author lxm
|
|
54
|
+
* @date 2022-11-24 19:11:27
|
|
55
|
+
*/
|
|
56
|
+
lock() {
|
|
57
|
+
this.count += 1;
|
|
58
|
+
if (!this.promise) {
|
|
59
|
+
this.startPromise();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* 解锁,计数减一
|
|
64
|
+
* 归零时结束异步
|
|
65
|
+
*
|
|
66
|
+
* @author lxm
|
|
67
|
+
* @date 2022-11-24 19:11:47
|
|
68
|
+
*/
|
|
69
|
+
unlock() {
|
|
70
|
+
if (this.count < 1) {
|
|
71
|
+
throw new RuntimeError('lock和unlock次数不匹配!');
|
|
72
|
+
}
|
|
73
|
+
this.count -= 1;
|
|
74
|
+
if (this.count === 0) {
|
|
75
|
+
debugger;
|
|
76
|
+
this.endPromise();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 等待,计数归零异步结束
|
|
81
|
+
*
|
|
82
|
+
* @author lxm
|
|
83
|
+
* @date 2022-11-24 19:11:20
|
|
84
|
+
*/
|
|
85
|
+
async await() {
|
|
86
|
+
if (this.promise) {
|
|
87
|
+
await this.promise;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/sync/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文件List转数组
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-11-18 13:11:03
|
|
6
|
+
* @export
|
|
7
|
+
* @param {FileList} fileList
|
|
8
|
+
* @returns {*}
|
|
9
|
+
*/
|
|
10
|
+
export declare function fileListToArr(fileList: FileList): File[];
|
|
11
|
+
/**
|
|
12
|
+
* JS打开文件上传操作配置参数
|
|
13
|
+
*
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2022-11-20 21:11:47
|
|
16
|
+
* @export
|
|
17
|
+
* @interface SelectFileOpts
|
|
18
|
+
*/
|
|
19
|
+
export interface SelectFileOpts {
|
|
20
|
+
/**
|
|
21
|
+
* 接受的文件类型
|
|
22
|
+
*
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2022-11-20 21:11:52
|
|
25
|
+
* @type {string}
|
|
26
|
+
*/
|
|
27
|
+
accept?: string;
|
|
28
|
+
/**
|
|
29
|
+
* 是否支持多选
|
|
30
|
+
*
|
|
31
|
+
* @author lxm
|
|
32
|
+
* @date 2022-11-20 21:11:52
|
|
33
|
+
* @type {boolean}
|
|
34
|
+
*/
|
|
35
|
+
multiple?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* 选中文件后回调
|
|
38
|
+
*
|
|
39
|
+
* @author lxm
|
|
40
|
+
* @date 2022-11-20 21:11:50
|
|
41
|
+
*/
|
|
42
|
+
onSelected: (_fileList: File[]) => void;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* JS打开文件上传操作
|
|
46
|
+
*
|
|
47
|
+
* @author lxm
|
|
48
|
+
* @date 2022-11-20 21:11:31
|
|
49
|
+
* @export
|
|
50
|
+
* @param {SelectFileOpts} _opts 配置参数
|
|
51
|
+
*/
|
|
52
|
+
export declare function selectFile(_opts: SelectFileOpts): void;
|
|
53
|
+
//# sourceMappingURL=select-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-file.d.ts","sourceRoot":"","sources":["../../../src/utils/upload/select-file.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,EAAE,CAMxD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;OAKG;IACH,UAAU,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;CACzC;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,QAwB/C"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { merge } from 'lodash-es';
|
|
2
|
+
/**
|
|
3
|
+
* 文件List转数组
|
|
4
|
+
*
|
|
5
|
+
* @author lxm
|
|
6
|
+
* @date 2022-11-18 13:11:03
|
|
7
|
+
* @export
|
|
8
|
+
* @param {FileList} fileList
|
|
9
|
+
* @returns {*}
|
|
10
|
+
*/
|
|
11
|
+
export function fileListToArr(fileList) {
|
|
12
|
+
const files = [];
|
|
13
|
+
for (let i = 0; i < fileList.length; i++) {
|
|
14
|
+
files.push(fileList[i]);
|
|
15
|
+
}
|
|
16
|
+
return files;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* JS打开文件上传操作
|
|
20
|
+
*
|
|
21
|
+
* @author lxm
|
|
22
|
+
* @date 2022-11-20 21:11:31
|
|
23
|
+
* @export
|
|
24
|
+
* @param {SelectFileOpts} _opts 配置参数
|
|
25
|
+
*/
|
|
26
|
+
export function selectFile(_opts) {
|
|
27
|
+
const opts = merge({
|
|
28
|
+
multiple: true,
|
|
29
|
+
accept: '',
|
|
30
|
+
}, _opts);
|
|
31
|
+
const input = document.createElement('input');
|
|
32
|
+
input.setAttribute('type', 'file');
|
|
33
|
+
input.setAttribute('multiple', `${opts.multiple}`);
|
|
34
|
+
input.setAttribute('accept', opts.accept);
|
|
35
|
+
input.onchange = e => {
|
|
36
|
+
const inputEl = e.target;
|
|
37
|
+
const files = inputEl.files ? fileListToArr(inputEl.files) : [];
|
|
38
|
+
if (files.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
opts.onSelected(files);
|
|
42
|
+
inputEl.value = ''; // 如果不置空,相同的文件不会触发change事件
|
|
43
|
+
};
|
|
44
|
+
document.body.appendChild(input);
|
|
45
|
+
input.click();
|
|
46
|
+
document.body.removeChild(input);
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { HttpResponse } from '../net/http-response';
|
|
2
|
+
export interface IUploadFile {
|
|
3
|
+
name: string;
|
|
4
|
+
uid: string;
|
|
5
|
+
status: 'uploading' | 'finished' | 'fail' | 'cancel';
|
|
6
|
+
percentage: number;
|
|
7
|
+
response?: HttpResponse;
|
|
8
|
+
error?: unknown;
|
|
9
|
+
}
|
|
10
|
+
export interface IUploadFileOpts {
|
|
11
|
+
uploadUrl: string;
|
|
12
|
+
/**
|
|
13
|
+
* 接受的文件类型
|
|
14
|
+
*
|
|
15
|
+
* @author lxm
|
|
16
|
+
* @date 2022-11-20 21:11:52
|
|
17
|
+
* @type {string}
|
|
18
|
+
*/
|
|
19
|
+
accept?: string;
|
|
20
|
+
/**
|
|
21
|
+
* 是否支持多选
|
|
22
|
+
*
|
|
23
|
+
* @author lxm
|
|
24
|
+
* @date 2022-11-20 21:11:52
|
|
25
|
+
* @type {Boolean}
|
|
26
|
+
*/
|
|
27
|
+
multiple?: boolean;
|
|
28
|
+
separate?: string;
|
|
29
|
+
request?: (_files: File[]) => Promise<HttpResponse>;
|
|
30
|
+
beforeUpload?: (_fileData: File[], _files: IUploadFile[]) => boolean;
|
|
31
|
+
finish?: (_resultFiles: IUploadFile[]) => void;
|
|
32
|
+
success?: (_resultFiles: IUploadFile[], _res: HttpResponse) => void;
|
|
33
|
+
error?: (_resultFiles: IUploadFile[], _error: unknown) => void;
|
|
34
|
+
progress?: (_files: IUploadFile[]) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* 使用上传文件逻辑
|
|
38
|
+
*
|
|
39
|
+
* @author lxm
|
|
40
|
+
* @date 2022-11-20 21:11:52
|
|
41
|
+
* @export
|
|
42
|
+
* @param {IUploadFileOpts} _opts
|
|
43
|
+
* @returns {*}
|
|
44
|
+
*/
|
|
45
|
+
export declare function uploadFile(_opts: IUploadFileOpts): void;
|
|
46
|
+
//# sourceMappingURL=upload-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../../src/utils/upload/upload-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAIpD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,OAAO,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACpE,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,QA0JhD"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-empty-function */
|
|
2
|
+
/* eslint-disable no-param-reassign */
|
|
3
|
+
import { cloneDeep, isFunction, merge, round, uniqueId } from 'lodash-es';
|
|
4
|
+
import { selectFile } from './select-file';
|
|
5
|
+
import { promiseAllSettled } from '../util/ie-helper';
|
|
6
|
+
/**
|
|
7
|
+
* 使用上传文件逻辑
|
|
8
|
+
*
|
|
9
|
+
* @author lxm
|
|
10
|
+
* @date 2022-11-20 21:11:52
|
|
11
|
+
* @export
|
|
12
|
+
* @param {IUploadFileOpts} _opts
|
|
13
|
+
* @returns {*}
|
|
14
|
+
*/
|
|
15
|
+
export function uploadFile(_opts) {
|
|
16
|
+
const opts = merge({
|
|
17
|
+
multiple: true,
|
|
18
|
+
accept: '',
|
|
19
|
+
separate: true,
|
|
20
|
+
beforeUpload: (_fileData, _files) => true,
|
|
21
|
+
finish: (_resultFiles) => { },
|
|
22
|
+
success: (_resultFiles, _res) => { },
|
|
23
|
+
error: (_resultFiles, _error) => { },
|
|
24
|
+
progress: (_files) => { },
|
|
25
|
+
}, _opts);
|
|
26
|
+
/**
|
|
27
|
+
* 进度条回调
|
|
28
|
+
*
|
|
29
|
+
* @author lxm
|
|
30
|
+
* @date 2022-11-20 21:11:47
|
|
31
|
+
* @param {IParams} event
|
|
32
|
+
* @param {IUploadFile[]} files
|
|
33
|
+
*/
|
|
34
|
+
const onUploadProgress = (event, files) => {
|
|
35
|
+
files.forEach(file => {
|
|
36
|
+
file.percentage = round(event.progress * 100);
|
|
37
|
+
});
|
|
38
|
+
opts.progress(cloneDeep(files));
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* 上传请求方法,返回响应对象
|
|
42
|
+
*
|
|
43
|
+
* @author lxm
|
|
44
|
+
* @date 2022-11-18 13:11:57
|
|
45
|
+
* @param {File[]} files
|
|
46
|
+
* @returns {*} {Promise<HttpResponse>}
|
|
47
|
+
*/
|
|
48
|
+
const uploadRequest = async (files, onProgress) => {
|
|
49
|
+
// 自定义上传请求
|
|
50
|
+
if (opts.request && isFunction(opts.request)) {
|
|
51
|
+
return opts.request(files);
|
|
52
|
+
}
|
|
53
|
+
// 默认每次单个文件上传,可能存在接口一次上传多个文件,
|
|
54
|
+
const data = new FormData();
|
|
55
|
+
files.forEach(file => {
|
|
56
|
+
data.append('file', file);
|
|
57
|
+
});
|
|
58
|
+
const res = await ibiz.net.request(opts.uploadUrl, {
|
|
59
|
+
method: 'post',
|
|
60
|
+
baseURL: '',
|
|
61
|
+
data,
|
|
62
|
+
headers: { 'Content-Type': 'multipart/form-data' },
|
|
63
|
+
onUploadProgress: onProgress,
|
|
64
|
+
});
|
|
65
|
+
return res;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* 执行一次上传,可能是一个文件也可能是多个文件
|
|
69
|
+
*
|
|
70
|
+
* @author lxm
|
|
71
|
+
* @date 2022-11-18 14:11:54
|
|
72
|
+
* @param {File[]} files 此次上传文件的集合
|
|
73
|
+
* @returns {*} {Promise<IUploadFile[]>}
|
|
74
|
+
*/
|
|
75
|
+
const executeSingleUpload = async (files) => {
|
|
76
|
+
const resultFiles = files.map(file => {
|
|
77
|
+
return {
|
|
78
|
+
status: 'uploading',
|
|
79
|
+
name: file.name,
|
|
80
|
+
uid: uniqueId(),
|
|
81
|
+
percentage: 0,
|
|
82
|
+
};
|
|
83
|
+
});
|
|
84
|
+
// 上传前回调,可以取消此次下载
|
|
85
|
+
const pass = opts.beforeUpload(files, resultFiles);
|
|
86
|
+
if (!pass) {
|
|
87
|
+
resultFiles.forEach(file => {
|
|
88
|
+
file.status = 'cancel';
|
|
89
|
+
});
|
|
90
|
+
ibiz.log.debug('取消上传', resultFiles);
|
|
91
|
+
return resultFiles;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const res = await uploadRequest(files, event => {
|
|
95
|
+
onUploadProgress(event, resultFiles);
|
|
96
|
+
});
|
|
97
|
+
resultFiles.forEach(file => {
|
|
98
|
+
file.status = 'finished';
|
|
99
|
+
});
|
|
100
|
+
// 上传成功事件
|
|
101
|
+
opts.success(resultFiles, res);
|
|
102
|
+
resultFiles.forEach(file => {
|
|
103
|
+
file.response = res;
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
resultFiles.forEach(file => {
|
|
108
|
+
file.status = 'fail';
|
|
109
|
+
});
|
|
110
|
+
// 上传失败事件
|
|
111
|
+
opts.error(resultFiles, error);
|
|
112
|
+
resultFiles.forEach(file => {
|
|
113
|
+
file.error = error;
|
|
114
|
+
});
|
|
115
|
+
ibiz.log.error(error);
|
|
116
|
+
ibiz.log.error(`${files.map(file => file.name).join(',')}上传失败`);
|
|
117
|
+
}
|
|
118
|
+
return resultFiles;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* 执行上传文件逻辑
|
|
122
|
+
*
|
|
123
|
+
* @author lxm
|
|
124
|
+
* @date 2022-11-18 13:11:21
|
|
125
|
+
* @param {files} File[] 文件集合
|
|
126
|
+
*/
|
|
127
|
+
const uploadFiles = async (files) => {
|
|
128
|
+
const uploadSequence = opts.separate ? files.map(file => [file]) : [files];
|
|
129
|
+
const res = await promiseAllSettled(uploadSequence.map(async (sequence) => {
|
|
130
|
+
return executeSingleUpload(sequence);
|
|
131
|
+
}));
|
|
132
|
+
// 整合所有的返回文件
|
|
133
|
+
const resultFiles = [];
|
|
134
|
+
res.forEach(result => {
|
|
135
|
+
if (result.status === 'fulfilled') {
|
|
136
|
+
resultFiles.push(...result.value);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
opts.finish(resultFiles);
|
|
140
|
+
};
|
|
141
|
+
const select = () => {
|
|
142
|
+
selectFile({
|
|
143
|
+
accept: opts.accept,
|
|
144
|
+
multiple: opts.multiple,
|
|
145
|
+
onSelected: files => {
|
|
146
|
+
uploadFiles(files);
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
select();
|
|
151
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface PromiseFulfilledResult {
|
|
2
|
+
status: 'fulfilled';
|
|
3
|
+
value: any;
|
|
4
|
+
}
|
|
5
|
+
interface PromiseRejectedResult {
|
|
6
|
+
status: 'rejected';
|
|
7
|
+
reason: any;
|
|
8
|
+
}
|
|
9
|
+
type PromiseSettledResult = PromiseFulfilledResult | PromiseRejectedResult;
|
|
10
|
+
export declare function promiseAllSettled(promiseList: Promise<any>[]): Promise<PromiseSettledResult[]>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=ie-helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ie-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/util/ie-helper.ts"],"names":[],"mappings":"AAGA,UAAU,sBAAsB;IAC9B,MAAM,EAAE,WAAW,CAAC;IACpB,KAAK,EAAE,GAAG,CAAC;CACZ;AAED,UAAU,qBAAqB;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,MAAM,EAAE,GAAG,CAAC;CACb;AAED,KAAK,oBAAoB,GAAG,sBAAsB,GAAG,qBAAqB,CAAC;AAE3E,wBAAgB,iBAAiB,CAC/B,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,GAC1B,OAAO,CAAC,oBAAoB,EAAE,CAAC,CAwBjC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/* eslint-disable no-shadow */
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3
|
+
export function promiseAllSettled(promiseList) {
|
|
4
|
+
const helper = (promiseList) => {
|
|
5
|
+
return promiseList.map((promise) => {
|
|
6
|
+
return promise.then((result) => {
|
|
7
|
+
return {
|
|
8
|
+
status: 'fulfilled',
|
|
9
|
+
value: result,
|
|
10
|
+
};
|
|
11
|
+
}, (reason) => {
|
|
12
|
+
return {
|
|
13
|
+
status: 'rejected',
|
|
14
|
+
reason,
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
return Promise.all(helper(promiseList));
|
|
20
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibiz-template/core",
|
|
3
|
-
"version": "0.0.1-beta.
|
|
3
|
+
"version": "0.0.1-beta.141",
|
|
4
4
|
"description": "核心包",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "out/index.js",
|
|
@@ -25,25 +25,27 @@
|
|
|
25
25
|
"test": "jest",
|
|
26
26
|
"prepublish": "npm run build",
|
|
27
27
|
"publish:next": "npm publish --access public --tag next",
|
|
28
|
-
"publish:
|
|
28
|
+
"publish:alpha": "npm publish --access public --tag alpha",
|
|
29
|
+
"publish:npm": "npm publish --registry https://registry.npmjs.org/"
|
|
29
30
|
},
|
|
30
31
|
"author": "chitanda",
|
|
31
32
|
"license": "MIT",
|
|
32
33
|
"dependencies": {
|
|
33
|
-
"axios": "^
|
|
34
|
-
"loglevel": "^1.8.
|
|
34
|
+
"axios": "^0.27.2",
|
|
35
|
+
"loglevel": "^1.8.1",
|
|
35
36
|
"pluralize": "^8.0.0",
|
|
36
|
-
"qs": "^6.11.
|
|
37
|
+
"qs": "^6.11.2"
|
|
37
38
|
},
|
|
38
39
|
"devDependencies": {
|
|
39
|
-
"@types/pluralize": "^0.0.
|
|
40
|
-
"@types/qs": "^6.9.
|
|
40
|
+
"@types/pluralize": "^0.0.33",
|
|
41
|
+
"@types/qs": "^6.9.10",
|
|
41
42
|
"lodash-es": "^4.17.21",
|
|
42
|
-
"qx-util": "^0.4.
|
|
43
|
+
"qx-util": "^0.4.8",
|
|
44
|
+
"ramda": "^0.29.1"
|
|
43
45
|
},
|
|
44
46
|
"peerDependencies": {
|
|
45
47
|
"lodash-es": "^4.17.21",
|
|
46
|
-
"qx-util": "^0.4.
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
"qx-util": "^0.4.8",
|
|
49
|
+
"ramda": "^0.28.0"
|
|
50
|
+
}
|
|
49
51
|
}
|
|
@@ -20,4 +20,14 @@ export class CoreConst {
|
|
|
20
20
|
* @static
|
|
21
21
|
*/
|
|
22
22
|
static readonly TOKEN = 'access_token';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 访问令牌标识过期时间
|
|
26
|
+
*
|
|
27
|
+
* @author lxm
|
|
28
|
+
* @date 2023-02-13 07:11:33
|
|
29
|
+
* @static
|
|
30
|
+
* @memberof CoreConst
|
|
31
|
+
*/
|
|
32
|
+
static readonly TOKEN_EXPIRES = 'access_token_expires';
|
|
23
33
|
}
|