@ibiz-template/core 0.7.41-alpha.1 → 0.7.41-alpha.106
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/index.esm.js +75 -15
- package/dist/index.system.min.js +1 -1
- package/out/context/index.d.ts.map +1 -1
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +8 -1
- package/out/error/http-error/http-error.d.ts +2 -2
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/interface/api/chat-message/i-api-chat-message.d.ts +63 -0
- package/out/interface/api/chat-message/i-api-chat-message.d.ts.map +1 -0
- package/out/interface/api/chat-message/i-api-chat-message.js +1 -0
- package/out/interface/api/chat-message/index.d.ts +2 -0
- package/out/interface/api/chat-message/index.d.ts.map +1 -0
- package/out/interface/api/chat-message/index.js +1 -0
- package/out/interface/api/environment/i-devtool-config.d.ts +11 -1
- package/out/interface/api/environment/i-devtool-config.d.ts.map +1 -1
- package/out/interface/api/environment/i-environment.d.ts +138 -1
- package/out/interface/api/environment/i-environment.d.ts.map +1 -1
- package/out/interface/api/ibizsys/i-app-data.d.ts +57 -0
- package/out/interface/api/ibizsys/i-app-data.d.ts.map +1 -0
- package/out/interface/api/ibizsys/i-app-data.js +1 -0
- package/out/interface/api/ibizsys/i-org-data.d.ts +1 -1
- package/out/interface/api/ibizsys/index.d.ts +1 -0
- package/out/interface/api/ibizsys/index.d.ts.map +1 -1
- package/out/interface/api/index.d.ts +1 -0
- package/out/interface/api/index.d.ts.map +1 -1
- package/out/interface/api/index.js +1 -0
- package/out/interface/api/utils/i-api-i18n.d.ts +9 -9
- package/out/interface/api/utils/index.d.ts +1 -0
- package/out/interface/api/utils/index.d.ts.map +1 -1
- package/out/interface/api/utils/message-center/base/i-message-base.d.ts +3 -3
- package/out/interface/api/utils/message-center/command/add-in-changed/i-command-add-in-changed.d.ts +1 -1
- package/out/interface/api/utils/message-center/command/async-action/i-command-async-action.d.ts +1 -1
- package/out/interface/api/utils/message-center/command/i-message-command.d.ts +1 -1
- package/out/interface/api/utils/message-center/command/internal-message/i-command-internal-message.d.ts +1 -1
- package/out/interface/api/utils/message-center/command/mark-open-data/i-command-mark-open-data.d.ts +1 -1
- package/out/interface/api/utils/message-center/common/i-message-center-event.d.ts +5 -0
- package/out/interface/api/utils/message-center/common/i-message-center-event.d.ts.map +1 -1
- package/out/interface/api/utils/message-center/common/i-portal-message.d.ts +3 -3
- package/out/interface/api/utils/message-center/console/i-message-console.d.ts +1 -1
- package/out/interface/api/utils/message-center/error/i-message-error.d.ts +1 -1
- package/out/interface/api/utils/message-center/i-message-center.d.ts +2 -2
- package/out/interface/api/utils/net/i-api-http-error.d.ts +39 -0
- package/out/interface/api/utils/net/i-api-http-error.d.ts.map +1 -0
- package/out/interface/api/utils/net/i-api-http-error.js +1 -0
- package/out/interface/api/utils/net/i-api-net.d.ts +1 -1
- package/out/interface/i-chat-message/i-chat-message.d.ts +2 -49
- package/out/interface/i-chat-message/i-chat-message.d.ts.map +1 -1
- package/out/utils/download-file/download-file.d.ts.map +1 -1
- package/out/utils/download-file/download-file.js +11 -1
- package/out/utils/interceptor/core-interceptor.js +2 -1
- package/out/utils/net/http-response.d.ts +2 -1
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/http-response.js +5 -1
- package/out/utils/net/net.d.ts +1 -1
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/recursive/find-recursive-child.d.ts +20 -0
- package/out/utils/recursive/find-recursive-child.d.ts.map +1 -1
- package/out/utils/recursive/find-recursive-child.js +69 -7
- package/out/utils/string-util/string-util.d.ts.map +1 -1
- package/out/utils/string-util/string-util.js +2 -4
- package/package.json +5 -4
- package/src/command/command-register.ts +121 -0
- package/src/command/command.ts +78 -0
- package/src/command/index.ts +8 -0
- package/src/command/utils/index.ts +2 -0
- package/src/command/utils/linked-list.ts +136 -0
- package/src/command/utils/util.ts +103 -0
- package/src/constant/core/core.ts +54 -0
- package/src/constant/emoji/emoji.ts +2929 -0
- package/src/constant/http-status-message/http-status-message.ts +18 -0
- package/src/constant/index.ts +4 -0
- package/src/constant/util/util.ts +3 -0
- package/src/context/index.ts +231 -0
- package/src/environment/environment.ts +64 -0
- package/src/error/http-error/entity-error.ts +29 -0
- package/src/error/http-error/http-error-factory.ts +24 -0
- package/src/error/http-error/http-error.ts +52 -0
- package/src/error/index.ts +7 -0
- package/src/error/model-error/model-error.ts +27 -0
- package/src/error/notice-error/notice-error.ts +16 -0
- package/src/error/runtime-error/runtime-error.ts +13 -0
- package/src/error/runtime-model-error/runtime-model-error.ts +27 -0
- package/src/ibizsys.ts +82 -0
- package/src/index.ts +14 -0
- package/src/install.ts +12 -0
- package/src/interface/api/chat-message/i-api-chat-message.ts +71 -0
- package/src/interface/api/chat-message/index.ts +1 -0
- package/src/interface/api/constant/index.ts +2 -0
- package/src/interface/api/constant/login-mode/login-mode.ts +25 -0
- package/src/interface/api/constant/menu-permission-mode/menu-permission-mode.ts +20 -0
- package/src/interface/api/environment/i-devtool-config.ts +56 -0
- package/src/interface/api/environment/i-environment.ts +523 -0
- package/src/interface/api/environment/index.ts +2 -0
- package/src/interface/api/global-param/i-api-context.ts +37 -0
- package/src/interface/api/global-param/i-global-param.ts +27 -0
- package/src/interface/api/global-param/index.ts +2 -0
- package/src/interface/api/ibizsys/i-api-ibizsys.ts +54 -0
- package/src/interface/api/ibizsys/i-app-data.ts +64 -0
- package/src/interface/api/ibizsys/i-org-data.ts +31 -0
- package/src/interface/api/ibizsys/index.ts +3 -0
- package/src/interface/api/index.ts +6 -0
- package/src/interface/api/utils/i-api-i18n.ts +56 -0
- package/src/interface/api/utils/index.ts +5 -0
- package/src/interface/api/utils/message-center/base/i-message-all.ts +8 -0
- package/src/interface/api/utils/message-center/base/i-message-base.ts +29 -0
- package/src/interface/api/utils/message-center/base/index.ts +2 -0
- package/src/interface/api/utils/message-center/command/add-in-changed/i-add-in-changed.ts +25 -0
- package/src/interface/api/utils/message-center/command/add-in-changed/i-command-add-in-changed.ts +16 -0
- package/src/interface/api/utils/message-center/command/async-action/i-command-async-action.ts +17 -0
- package/src/interface/api/utils/message-center/command/change/i-command-change.ts +8 -0
- package/src/interface/api/utils/message-center/command/create/i-command-create.ts +18 -0
- package/src/interface/api/utils/message-center/command/i-command-base.ts +23 -0
- package/src/interface/api/utils/message-center/command/i-message-command.ts +94 -0
- package/src/interface/api/utils/message-center/command/index.ts +20 -0
- package/src/interface/api/utils/message-center/command/internal-message/i-command-internal-message.ts +17 -0
- package/src/interface/api/utils/message-center/command/internal-message/i-internal-message.ts +132 -0
- package/src/interface/api/utils/message-center/command/mark-open-data/i-command-mark-open-data.ts +17 -0
- package/src/interface/api/utils/message-center/command/mark-open-data/i-mark-open-data.ts +47 -0
- package/src/interface/api/utils/message-center/command/remove/i-command-remove.ts +18 -0
- package/src/interface/api/utils/message-center/command/update/i-command-update.ts +18 -0
- package/src/interface/api/utils/message-center/common/i-app-data-entity.ts +16 -0
- package/src/interface/api/utils/message-center/common/i-message-center-event.ts +15 -0
- package/src/interface/api/utils/message-center/common/i-msg-meta-data.ts +13 -0
- package/src/interface/api/utils/message-center/common/i-portal-async-action.ts +144 -0
- package/src/interface/api/utils/message-center/common/i-portal-message.ts +84 -0
- package/src/interface/api/utils/message-center/common/index.ts +5 -0
- package/src/interface/api/utils/message-center/console/i-message-console.ts +17 -0
- package/src/interface/api/utils/message-center/error/i-message-error.ts +17 -0
- package/src/interface/api/utils/message-center/i-message-center.ts +53 -0
- package/src/interface/api/utils/message-center/index.ts +6 -0
- package/src/interface/api/utils/net/i-api-http-error.ts +43 -0
- package/src/interface/api/utils/net/i-api-net.ts +93 -0
- package/src/interface/api/utils/net/i-http-response.ts +67 -0
- package/src/interface/click-outside/click-outside.ts +51 -0
- package/src/interface/command/command/i-command-option.ts +47 -0
- package/src/interface/command/command/i-command.ts +68 -0
- package/src/interface/command/disposable/i-disposable.ts +12 -0
- package/src/interface/command/i-command-controller.ts +50 -0
- package/src/interface/command/index.ts +11 -0
- package/src/interface/context/index.ts +42 -0
- package/src/interface/error/index.ts +13 -0
- package/src/interface/i-chat-message/i-chat-message.ts +16 -0
- package/src/interface/ibizsys/i-ibizsys.ts +33 -0
- package/src/interface/ibizsys/index.ts +1 -0
- package/src/interface/index.ts +11 -0
- package/src/interface/utils/i-18n.ts +22 -0
- package/src/interface/utils/index.ts +1 -0
- package/src/locale/en/index.ts +30 -0
- package/src/locale/index.ts +2 -0
- package/src/locale/zh-CN/index.ts +28 -0
- package/src/params/params.ts +131 -0
- package/src/types.ts +26 -0
- package/src/utils/bit-mask/bit-mask.ts +87 -0
- package/src/utils/click-outside/click-outside.ts +108 -0
- package/src/utils/clone/clone.ts +38 -0
- package/src/utils/color/color.ts +84 -0
- package/src/utils/cookie-util/cookie-util.ts +192 -0
- package/src/utils/data-type/data-types.ts +93 -0
- package/src/utils/download-file/download-file.ts +110 -0
- package/src/utils/event/event.ts +69 -0
- package/src/utils/history-list/history-item.ts +41 -0
- package/src/utils/history-list/history-list.ts +137 -0
- package/src/utils/index.ts +24 -0
- package/src/utils/interceptor/core-interceptor.ts +127 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +122 -0
- package/src/utils/logger/logger.ts +34 -0
- package/src/utils/message-center/base/message-all.ts +10 -0
- package/src/utils/message-center/base/message-base.ts +73 -0
- package/src/utils/message-center/command/add-in-changed/command-add-in-changed.ts +23 -0
- package/src/utils/message-center/command/async-action/command-async-action.ts +23 -0
- package/src/utils/message-center/command/change/command-change.ts +11 -0
- package/src/utils/message-center/command/command-base/command-base.ts +35 -0
- package/src/utils/message-center/command/create/command-create.ts +25 -0
- package/src/utils/message-center/command/internal-message/command-internal-message.ts +26 -0
- package/src/utils/message-center/command/mark-open-data/command-mark-open-data.ts +23 -0
- package/src/utils/message-center/command/message-command.ts +162 -0
- package/src/utils/message-center/command/remove/command-remove.ts +25 -0
- package/src/utils/message-center/command/update/command-update.ts +25 -0
- package/src/utils/message-center/console/message-console.ts +27 -0
- package/src/utils/message-center/error/message-error.ts +27 -0
- package/src/utils/message-center/index.ts +1 -0
- package/src/utils/message-center/message-center.ts +77 -0
- package/src/utils/namespace/namespace.ts +217 -0
- package/src/utils/net/http-response.ts +60 -0
- package/src/utils/net/net.ts +448 -0
- package/src/utils/recursive/find-recursive-child.ts +238 -0
- package/src/utils/string-util/string-util.ts +76 -0
- package/src/utils/style/remote-style.ts +17 -0
- package/src/utils/sync/await-timeout.ts +29 -0
- package/src/utils/sync/count-latch.ts +79 -0
- package/src/utils/sync/index.ts +2 -0
- package/src/utils/types/types.ts +24 -0
- package/src/utils/upload/select-file.ts +93 -0
- package/src/utils/upload/upload-file.ts +194 -0
- package/src/utils/url-helper/url-helper.ts +52 -0
- package/src/utils/util/util.ts +580 -0
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 数据类型转换识别工具类
|
|
3
|
+
* @export
|
|
4
|
+
* @class DataTypes
|
|
5
|
+
*/
|
|
6
|
+
export class DataTypes {
|
|
7
|
+
/**
|
|
8
|
+
* @description 数字类型映射字符串类型
|
|
9
|
+
* @static
|
|
10
|
+
* @type {{ [p: number]: string }}
|
|
11
|
+
* @memberof DataTypes
|
|
12
|
+
*/
|
|
13
|
+
static readonly typeMap: { [p: number]: string } = {
|
|
14
|
+
0: 'UNKNOWN',
|
|
15
|
+
1: 'BIGINT',
|
|
16
|
+
2: 'BINARY',
|
|
17
|
+
3: 'BIT',
|
|
18
|
+
4: 'CHAR',
|
|
19
|
+
5: 'DATETIME',
|
|
20
|
+
6: 'DECIMAL',
|
|
21
|
+
7: 'FLOAT',
|
|
22
|
+
8: 'IMAGE',
|
|
23
|
+
9: 'INT',
|
|
24
|
+
10: 'MONEY',
|
|
25
|
+
11: 'NCHAR',
|
|
26
|
+
12: 'NTEXT',
|
|
27
|
+
13: 'NVARCHAR',
|
|
28
|
+
14: 'NUMERIC',
|
|
29
|
+
15: 'REAL',
|
|
30
|
+
16: 'SMALLDATETIME',
|
|
31
|
+
17: 'SMALLINT',
|
|
32
|
+
18: 'SMALLMONEY',
|
|
33
|
+
19: 'SQL_VARIANT',
|
|
34
|
+
20: 'SYSNAME',
|
|
35
|
+
21: 'TEXT',
|
|
36
|
+
22: 'TIMESTAMP',
|
|
37
|
+
23: 'TINYINT',
|
|
38
|
+
24: 'VARBINARY',
|
|
39
|
+
25: 'VARCHAR',
|
|
40
|
+
26: 'UNIQUEIDENTIFIER',
|
|
41
|
+
27: 'DATE', // 纯日期型
|
|
42
|
+
28: 'TIME', // 纯时间
|
|
43
|
+
29: 'BIGDECIMAL', // 大数值
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* @description 是否是数值类型
|
|
48
|
+
* @static
|
|
49
|
+
* @param {number} dataType
|
|
50
|
+
* @returns {*} {boolean}
|
|
51
|
+
* @memberof DataTypes
|
|
52
|
+
*/
|
|
53
|
+
public static isNumber(dataType: number): boolean {
|
|
54
|
+
const numberTypes = [
|
|
55
|
+
'BIGINT',
|
|
56
|
+
'BINARY',
|
|
57
|
+
'DECIMAL',
|
|
58
|
+
'FLOAT',
|
|
59
|
+
'INT',
|
|
60
|
+
'MONEY',
|
|
61
|
+
'NUMERIC',
|
|
62
|
+
'REAL',
|
|
63
|
+
'SMALLINT',
|
|
64
|
+
'SMALLMONEY',
|
|
65
|
+
'TINYINT',
|
|
66
|
+
'VARBINARY',
|
|
67
|
+
];
|
|
68
|
+
return numberTypes.includes(this.toString(dataType));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @description 是否是日期类型数据
|
|
73
|
+
* @static
|
|
74
|
+
* @param {number} dataType
|
|
75
|
+
* @returns {*} {boolean}
|
|
76
|
+
* @memberof DataTypes
|
|
77
|
+
*/
|
|
78
|
+
public static isDate(dataType: number): boolean {
|
|
79
|
+
const dateTypes = ['DATETIME', 'SMALLDATETIME', 'DATE', 'TIME'];
|
|
80
|
+
return dateTypes.includes(this.toString(dataType));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @description 获取字符串数据类型
|
|
85
|
+
* @static
|
|
86
|
+
* @param {number} dataType
|
|
87
|
+
* @returns {*} {string}
|
|
88
|
+
* @memberof DataTypes
|
|
89
|
+
*/
|
|
90
|
+
public static toString(dataType: number): string {
|
|
91
|
+
return this.typeMap[dataType];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description 根据文件名称计算Mime类型
|
|
3
|
+
* @export
|
|
4
|
+
* @param {string} fileName
|
|
5
|
+
* @returns {*} {string}
|
|
6
|
+
*/
|
|
7
|
+
export function calcMimeByFileName(fileName: string): string {
|
|
8
|
+
const ext = fileName.includes('.') ? fileName.split('.').pop() : '';
|
|
9
|
+
let mime = '';
|
|
10
|
+
switch (ext) {
|
|
11
|
+
case 'wps':
|
|
12
|
+
mime = 'application/kswps';
|
|
13
|
+
break;
|
|
14
|
+
case 'doc':
|
|
15
|
+
mime = 'application/msword';
|
|
16
|
+
break;
|
|
17
|
+
case 'docx':
|
|
18
|
+
mime =
|
|
19
|
+
'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
|
|
20
|
+
break;
|
|
21
|
+
case 'txt':
|
|
22
|
+
mime = 'text/plain';
|
|
23
|
+
break;
|
|
24
|
+
case 'zip':
|
|
25
|
+
mime = 'application/zip';
|
|
26
|
+
break;
|
|
27
|
+
case 'png':
|
|
28
|
+
mime = 'image/png';
|
|
29
|
+
break;
|
|
30
|
+
case 'gif':
|
|
31
|
+
mime = 'image/gif';
|
|
32
|
+
break;
|
|
33
|
+
case 'jpeg':
|
|
34
|
+
mime = 'image/jpeg';
|
|
35
|
+
break;
|
|
36
|
+
case 'jpg':
|
|
37
|
+
mime = 'image/jpeg';
|
|
38
|
+
break;
|
|
39
|
+
case 'rtf':
|
|
40
|
+
mime = 'application/rtf';
|
|
41
|
+
break;
|
|
42
|
+
case 'avi':
|
|
43
|
+
mime = 'video/x-msvideo';
|
|
44
|
+
break;
|
|
45
|
+
case 'gz':
|
|
46
|
+
mime = 'application/x-gzip';
|
|
47
|
+
break;
|
|
48
|
+
case 'tar':
|
|
49
|
+
mime = 'application/x-tar';
|
|
50
|
+
break;
|
|
51
|
+
case 'xls':
|
|
52
|
+
mime = 'application/vnd.ms-excel';
|
|
53
|
+
break;
|
|
54
|
+
case 'xlsx':
|
|
55
|
+
mime =
|
|
56
|
+
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
|
|
57
|
+
break;
|
|
58
|
+
case 'pdf':
|
|
59
|
+
mime = 'application/pdf';
|
|
60
|
+
break;
|
|
61
|
+
case 'html':
|
|
62
|
+
mime = 'text/html';
|
|
63
|
+
break;
|
|
64
|
+
default:
|
|
65
|
+
mime = '';
|
|
66
|
+
}
|
|
67
|
+
return mime;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @description 判断是否是图片格式
|
|
72
|
+
* @export
|
|
73
|
+
* @param {string} fileName
|
|
74
|
+
* @returns {*} {boolean}
|
|
75
|
+
*/
|
|
76
|
+
export function isImage(fileName: string): boolean {
|
|
77
|
+
const ext = fileName.includes('.') ? fileName.split('.').pop() : '';
|
|
78
|
+
if (!ext) {
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
const imageTypes = ['jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
|
|
82
|
+
return imageTypes.includes(ext);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description 纯JS触发下载文件
|
|
87
|
+
* @export
|
|
88
|
+
* @param {Blob} file
|
|
89
|
+
* @param {string} fileName
|
|
90
|
+
*/
|
|
91
|
+
export function downloadFileFromBlob(file: Blob, fileName: string): void {
|
|
92
|
+
// 获取文件名
|
|
93
|
+
const filetype = calcMimeByFileName(fileName);
|
|
94
|
+
// 用blob对象获取文件流
|
|
95
|
+
const blob = new Blob([file], { type: filetype });
|
|
96
|
+
// 通过文件流创建下载链接
|
|
97
|
+
const href = URL.createObjectURL(blob);
|
|
98
|
+
// 创建一个a元素并设置相关属性
|
|
99
|
+
const a = document.createElement('a');
|
|
100
|
+
a.href = href;
|
|
101
|
+
a.download = fileName;
|
|
102
|
+
// 添加a元素到当前网页
|
|
103
|
+
document.body.appendChild(a);
|
|
104
|
+
// 触发a元素的点击事件,实现下载
|
|
105
|
+
a.click();
|
|
106
|
+
// 从当前网页移除a元素
|
|
107
|
+
document.body.removeChild(a);
|
|
108
|
+
// 释放blob对象
|
|
109
|
+
URL.revokeObjectURL(href);
|
|
110
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
|
|
3
|
+
import { NOOP } from '../../constant';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @description 计算event的composedPath返回事件路径(兼容了IE)
|
|
7
|
+
* @export
|
|
8
|
+
* @param {MouseEvent} event
|
|
9
|
+
* @returns {*} {((EventTarget | null)[])}
|
|
10
|
+
*/
|
|
11
|
+
export function eventPath(event: MouseEvent): (EventTarget | null)[] {
|
|
12
|
+
const path = ((event.composedPath && event.composedPath()) ||
|
|
13
|
+
(event as any).path) as HTMLElement[] | undefined;
|
|
14
|
+
|
|
15
|
+
if (path != null) return path;
|
|
16
|
+
|
|
17
|
+
// 浏览器没有提供的,自己递归计算
|
|
18
|
+
function getParents(
|
|
19
|
+
node: HTMLElement,
|
|
20
|
+
memo: HTMLElement[] = [],
|
|
21
|
+
): HTMLElement[] {
|
|
22
|
+
const parentNode = node.parentNode as HTMLElement | null;
|
|
23
|
+
|
|
24
|
+
return parentNode
|
|
25
|
+
? getParents(parentNode, memo.concat([parentNode]))
|
|
26
|
+
: memo;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return [event.target].concat(getParents(event.target as HTMLElement));
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* @description 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
34
|
+
* @export
|
|
35
|
+
* @param {EventTarget} target 监听对象
|
|
36
|
+
* @param {string} eventName 监听事件名称
|
|
37
|
+
* @param {(..._args: any[]) => any} listener 监听回调
|
|
38
|
+
* @param {AddEventListenerOptions} [options={}] 额外参数
|
|
39
|
+
* @returns {*} {() => void}
|
|
40
|
+
*/
|
|
41
|
+
export function listenJSEvent(
|
|
42
|
+
target: EventTarget,
|
|
43
|
+
eventName: string,
|
|
44
|
+
listener: (..._args: any[]) => any,
|
|
45
|
+
options: AddEventListenerOptions = {},
|
|
46
|
+
): () => void {
|
|
47
|
+
target.addEventListener(eventName, listener, options);
|
|
48
|
+
|
|
49
|
+
let cleanup = (): void => {
|
|
50
|
+
target.removeEventListener(eventName, listener, options);
|
|
51
|
+
// cleanup方法只能调用一次
|
|
52
|
+
cleanup = NOOP;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
cleanup();
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* @description event是否是在目标元素内部触发的
|
|
62
|
+
* @export
|
|
63
|
+
* @param {MouseEvent} event 原生事件
|
|
64
|
+
* @param {HTMLElement} el 目标元素
|
|
65
|
+
* @returns {*} {boolean}
|
|
66
|
+
*/
|
|
67
|
+
export function isEventInside(event: MouseEvent, el: HTMLElement): boolean {
|
|
68
|
+
return el && (event.target === el || eventPath(event).includes(el));
|
|
69
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { RuntimeError } from '../../error';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 历史项
|
|
5
|
+
* @export
|
|
6
|
+
* @class HistoryItem
|
|
7
|
+
* @template E
|
|
8
|
+
*/
|
|
9
|
+
export class HistoryItem<E> {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
static readonly Undefined = new HistoryItem<any>(undefined);
|
|
12
|
+
|
|
13
|
+
_prev: HistoryItem<E>;
|
|
14
|
+
|
|
15
|
+
_next: HistoryItem<E>;
|
|
16
|
+
|
|
17
|
+
data: E;
|
|
18
|
+
|
|
19
|
+
constructor(data: unknown = {}) {
|
|
20
|
+
this.data = data as E;
|
|
21
|
+
this._prev = HistoryItem.Undefined;
|
|
22
|
+
this._next = HistoryItem.Undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @description 克隆整个历史链
|
|
27
|
+
* @returns {*} {HistoryItem<E>}
|
|
28
|
+
* @memberof HistoryItem
|
|
29
|
+
*/
|
|
30
|
+
clone(): HistoryItem<E> {
|
|
31
|
+
// const history = new HistoryItem<E>(clone(this.data));
|
|
32
|
+
// if (history._prev && history._prev !== HistoryItem.Undefined) {
|
|
33
|
+
// history._prev = clone(this._prev);
|
|
34
|
+
// }
|
|
35
|
+
// if (history._next && history._next !== HistoryItem.Undefined) {
|
|
36
|
+
// history._next = clone(this._next);
|
|
37
|
+
// }
|
|
38
|
+
// return history;
|
|
39
|
+
throw new RuntimeError(ibiz.i18n.t('core.utils.unrealized'));
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { clone } from 'ramda';
|
|
2
|
+
import { HistoryItem } from './history-item';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @description 数据对象历史记录,只支持纯对象形式的数据。并未支持数组
|
|
6
|
+
* @export
|
|
7
|
+
* @class HistoryList
|
|
8
|
+
* @template E
|
|
9
|
+
*/
|
|
10
|
+
export class HistoryList<E = IData> {
|
|
11
|
+
/**
|
|
12
|
+
* @description 当前步骤的历史记录
|
|
13
|
+
* @private
|
|
14
|
+
* @type {HistoryItem<E>}
|
|
15
|
+
* @memberof HistoryList
|
|
16
|
+
*/
|
|
17
|
+
private _cur: HistoryItem<E>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @description 当前的数据
|
|
21
|
+
* @readonly
|
|
22
|
+
* @type {E}
|
|
23
|
+
* @memberof HistoryList
|
|
24
|
+
*/
|
|
25
|
+
get data(): E {
|
|
26
|
+
return this._cur.data;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of HistoryList.
|
|
31
|
+
* @param {E} data
|
|
32
|
+
* @memberof HistoryList
|
|
33
|
+
*/
|
|
34
|
+
constructor(data: E) {
|
|
35
|
+
this._cur = new HistoryItem<E>(data);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @description 先创建一次历史记录,再赋值
|
|
40
|
+
* @param {IData} data
|
|
41
|
+
* @memberof HistoryList
|
|
42
|
+
*/
|
|
43
|
+
assign(data: IData): void {
|
|
44
|
+
if (data) {
|
|
45
|
+
this.save();
|
|
46
|
+
Object.assign(this._cur.data!, data);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @description 创建一次历史记录
|
|
52
|
+
* @memberof HistoryList
|
|
53
|
+
*/
|
|
54
|
+
save(): void {
|
|
55
|
+
const oldCur = this._cur;
|
|
56
|
+
// 克隆当前数据对象
|
|
57
|
+
const data = clone(oldCur.data);
|
|
58
|
+
// 新的历史对象
|
|
59
|
+
const history = new HistoryItem<E>(data);
|
|
60
|
+
// 设置新历史的上一次历史为当前历史
|
|
61
|
+
history._prev = oldCur;
|
|
62
|
+
// 将下一步的前一步置空,断开引用
|
|
63
|
+
oldCur._next._prev = HistoryItem.Undefined;
|
|
64
|
+
// 清空下一步的所有引用
|
|
65
|
+
this._clear(oldCur._next);
|
|
66
|
+
// 设置当前历史的下一次历史为新历史,如果有旧的前进步骤就干掉了
|
|
67
|
+
oldCur._next = history;
|
|
68
|
+
// 设置新历史为新历史对象
|
|
69
|
+
this._cur = history;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @description 上一步
|
|
74
|
+
* @returns {*} {boolean}
|
|
75
|
+
* @memberof HistoryList
|
|
76
|
+
*/
|
|
77
|
+
prev(): boolean {
|
|
78
|
+
if (this._cur._prev && this._cur._prev !== HistoryItem.Undefined) {
|
|
79
|
+
this._cur = this._cur._prev;
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description 下一步
|
|
87
|
+
* @returns {*} {boolean}
|
|
88
|
+
* @memberof HistoryList
|
|
89
|
+
*/
|
|
90
|
+
next(): boolean {
|
|
91
|
+
if (this._cur._next && this._cur._next !== HistoryItem.Undefined) {
|
|
92
|
+
this._cur = this._cur._next;
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* @description 清空引用,避免内存泄漏
|
|
100
|
+
* @protected
|
|
101
|
+
* @param {HistoryItem<E>} h
|
|
102
|
+
* @memberof HistoryList
|
|
103
|
+
*/
|
|
104
|
+
protected _clear(h: HistoryItem<E>): void {
|
|
105
|
+
if (h._prev && h._prev !== HistoryItem.Undefined) {
|
|
106
|
+
h._prev._next = HistoryItem.Undefined;
|
|
107
|
+
this._clear(h._prev);
|
|
108
|
+
h._prev = HistoryItem.Undefined;
|
|
109
|
+
}
|
|
110
|
+
if (h._next && h._next !== HistoryItem.Undefined) {
|
|
111
|
+
h._next._prev = HistoryItem.Undefined;
|
|
112
|
+
this._clear(h._next);
|
|
113
|
+
h._next = HistoryItem.Undefined;
|
|
114
|
+
}
|
|
115
|
+
h.data = {} as E;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* @description 禁止克隆,直接返回当前实例
|
|
120
|
+
* @protected
|
|
121
|
+
* @returns {*} {HistoryList<E>}
|
|
122
|
+
* @memberof HistoryList
|
|
123
|
+
*/
|
|
124
|
+
protected clone(): HistoryList<E> {
|
|
125
|
+
const history = new HistoryList<E>({} as E);
|
|
126
|
+
history._cur = clone(this._cur);
|
|
127
|
+
return this;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* @description 销毁
|
|
132
|
+
* @memberof HistoryList
|
|
133
|
+
*/
|
|
134
|
+
destroy(): void {
|
|
135
|
+
this._clear(this._cur);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export * from './interceptor';
|
|
2
|
+
export { MessageCenter } from './message-center';
|
|
3
|
+
export { Namespace } from './namespace/namespace';
|
|
4
|
+
export { HttpResponse } from './net/http-response';
|
|
5
|
+
export { Net } from './net/net';
|
|
6
|
+
export { StringUtil } from './string-util/string-util';
|
|
7
|
+
export * from './util/util';
|
|
8
|
+
export * from './types/types';
|
|
9
|
+
export * from './url-helper/url-helper';
|
|
10
|
+
export * from './event/event';
|
|
11
|
+
export { HistoryItem } from './history-list/history-item';
|
|
12
|
+
export { HistoryList } from './history-list/history-list';
|
|
13
|
+
export * from './click-outside/click-outside';
|
|
14
|
+
export * from './color/color';
|
|
15
|
+
export * from './download-file/download-file';
|
|
16
|
+
export * from './upload/select-file';
|
|
17
|
+
export * from './upload/upload-file';
|
|
18
|
+
export * from './sync';
|
|
19
|
+
export * from './style/remote-style';
|
|
20
|
+
export * from './recursive/find-recursive-child';
|
|
21
|
+
export { DataTypes } from './data-type/data-types';
|
|
22
|
+
export * from './clone/clone';
|
|
23
|
+
export { BitMask } from './bit-mask/bit-mask';
|
|
24
|
+
export * from './cookie-util/cookie-util';
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { InternalAxiosRequestConfig } from 'axios';
|
|
2
|
+
import { getToken } from '../util/util';
|
|
3
|
+
import { Interceptor } from './interceptor';
|
|
4
|
+
import { getAppCookie } from '../cookie-util/cookie-util';
|
|
5
|
+
import { CoreConst } from '../../constant';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @description 核心包拦截器
|
|
9
|
+
* @export
|
|
10
|
+
* @class CoreInterceptor
|
|
11
|
+
* @extends {Interceptor}
|
|
12
|
+
*/
|
|
13
|
+
export class CoreInterceptor extends Interceptor {
|
|
14
|
+
/**
|
|
15
|
+
* @description 请求之前处理
|
|
16
|
+
* @protected
|
|
17
|
+
* @param {InternalAxiosRequestConfig} config
|
|
18
|
+
* @returns {*} {Promise<InternalAxiosRequestConfig>}
|
|
19
|
+
* @memberof CoreInterceptor
|
|
20
|
+
*/
|
|
21
|
+
protected async onBeforeRequest(
|
|
22
|
+
config: InternalAxiosRequestConfig,
|
|
23
|
+
): Promise<InternalAxiosRequestConfig> {
|
|
24
|
+
config = await super.onBeforeRequest(config);
|
|
25
|
+
|
|
26
|
+
const { headers } = config;
|
|
27
|
+
|
|
28
|
+
// Set the access token.
|
|
29
|
+
const token = getToken();
|
|
30
|
+
if (token) {
|
|
31
|
+
headers.set(
|
|
32
|
+
`${ibiz.env.tokenHeader}Authorization`,
|
|
33
|
+
`${ibiz.env.tokenPrefix}Bearer ${token}`,
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Set the system ID.
|
|
38
|
+
let systemId = ibiz.env.dcSystem;
|
|
39
|
+
const { orgData } = ibiz;
|
|
40
|
+
if (orgData) {
|
|
41
|
+
if (orgData.systemid) {
|
|
42
|
+
systemId = orgData.systemid;
|
|
43
|
+
}
|
|
44
|
+
if (orgData.orgid) {
|
|
45
|
+
headers.set('srforgid', orgData.orgid);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
headers.set('srfsystemid', systemId);
|
|
49
|
+
|
|
50
|
+
return config;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* @description 响应失败之后处理
|
|
55
|
+
* @protected
|
|
56
|
+
* @param {Error} error
|
|
57
|
+
* @returns {*} {Promise<never>}
|
|
58
|
+
* @memberof CoreInterceptor
|
|
59
|
+
*/
|
|
60
|
+
protected async onResponseError(error: Error): Promise<never> {
|
|
61
|
+
const { config, response } = error as IData;
|
|
62
|
+
if (
|
|
63
|
+
this.instance &&
|
|
64
|
+
response?.status === 401 &&
|
|
65
|
+
config &&
|
|
66
|
+
!config._retry &&
|
|
67
|
+
config.url &&
|
|
68
|
+
// 排除获取系统信息、应用数据、刷新 token 预定义接口
|
|
69
|
+
(config.url.indexOf('/uaa/getbydcsystem/') === -1 ||
|
|
70
|
+
config.url.indexOf('/appdata') !== -1 ||
|
|
71
|
+
config.url.indexOf('/uaa/refresh_token/') !== -1)
|
|
72
|
+
) {
|
|
73
|
+
try {
|
|
74
|
+
// 标记为已重试
|
|
75
|
+
config._retry = true;
|
|
76
|
+
// 刷新 token(匿名登录通过登录换算token,非匿名登录通过refreshToken换算新的token)
|
|
77
|
+
if (ibiz.env.enableAnonymous) {
|
|
78
|
+
const authInfo = (ibiz as IData).auth.getAuthInfo();
|
|
79
|
+
const refreshToken = getAppCookie(CoreConst.REFRESH_TOKEN);
|
|
80
|
+
// 匿名登录、匿名登录无refreshToken情况通过登录换算token
|
|
81
|
+
if (authInfo.isAnonymous || !refreshToken) {
|
|
82
|
+
const tempOrgData = ibiz.orgData;
|
|
83
|
+
await (ibiz as IData).auth.anonymousLogin();
|
|
84
|
+
ibiz.orgData = tempOrgData;
|
|
85
|
+
} else {
|
|
86
|
+
await (ibiz as IData).auth.refreshToken();
|
|
87
|
+
}
|
|
88
|
+
} else {
|
|
89
|
+
await (ibiz as IData).auth.refreshToken();
|
|
90
|
+
}
|
|
91
|
+
// 重新加载应用数据
|
|
92
|
+
const res = await ibiz.net.get(
|
|
93
|
+
'/appdata',
|
|
94
|
+
(ibiz as IData).appUtil?.getAppContext(),
|
|
95
|
+
);
|
|
96
|
+
if (res && res.ok) {
|
|
97
|
+
ibiz.appData = res.data;
|
|
98
|
+
}
|
|
99
|
+
// 重新发起原始请求
|
|
100
|
+
const { headers } = config;
|
|
101
|
+
const token = getToken();
|
|
102
|
+
if (token) {
|
|
103
|
+
headers.set(
|
|
104
|
+
`${ibiz.env.tokenHeader}Authorization`,
|
|
105
|
+
`${ibiz.env.tokenPrefix}Bearer ${token}`,
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
let systemId = ibiz.env.dcSystem;
|
|
109
|
+
const { orgData } = ibiz;
|
|
110
|
+
if (orgData) {
|
|
111
|
+
if (orgData.systemid) {
|
|
112
|
+
systemId = orgData.systemid;
|
|
113
|
+
}
|
|
114
|
+
if (orgData.orgid) {
|
|
115
|
+
headers.set('srforgid', orgData.orgid);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
headers.set('srfsystemid', systemId);
|
|
119
|
+
return this.instance(config);
|
|
120
|
+
} catch (err) {
|
|
121
|
+
return Promise.reject(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// 处理响应错误
|
|
125
|
+
return Promise.reject(error);
|
|
126
|
+
}
|
|
127
|
+
}
|