@ibiz-template/core 0.6.0 → 0.6.1-dev.1
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/package.json +3 -4
- package/src/command/command-register.ts +0 -135
- package/src/command/command.ts +0 -79
- package/src/command/index.ts +0 -11
- package/src/command/interface/command/command-option.ts +0 -22
- package/src/command/interface/command/command.ts +0 -86
- package/src/command/interface/disposable/disposable.ts +0 -3
- package/src/command/interface/index.ts +0 -9
- package/src/command/utils/index.ts +0 -2
- package/src/command/utils/linked-list.ts +0 -136
- package/src/command/utils/util.ts +0 -95
- package/src/constant/core/core.ts +0 -63
- package/src/constant/http-status-message/http-status-message.ts +0 -20
- package/src/constant/index.ts +0 -5
- package/src/constant/login-mode/login-mode.ts +0 -23
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +0 -23
- package/src/constant/util/util.ts +0 -5
- package/src/context/index.ts +0 -231
- package/src/environment/environment.ts +0 -39
- package/src/error/http-error/http-error.ts +0 -45
- package/src/error/index.ts +0 -5
- package/src/error/model-error/model-error.ts +0 -26
- package/src/error/notice-error/notice-error.ts +0 -19
- package/src/error/runtime-error/runtime-error.ts +0 -16
- package/src/error/runtime-model-error/runtime-model-error.ts +0 -27
- package/src/ibizsys.ts +0 -78
- package/src/index.ts +0 -14
- package/src/install.ts +0 -15
- package/src/interface/click-outside/click-outside.ts +0 -71
- package/src/interface/i-18n/i-18n.ts +0 -68
- package/src/interface/i-chat-message/i-chat-message.ts +0 -83
- package/src/interface/i-devtool-config/i-devtool-config.ts +0 -16
- package/src/interface/i-environment/i-environment.ts +0 -289
- package/src/interface/i-internal-message/i-internal-message.ts +0 -151
- package/src/interface/i-mark-open-data/i-mark-open-data.ts +0 -39
- package/src/interface/i-portal-async-action/i-portal-async-action.ts +0 -177
- package/src/interface/i-portal-message/i-portal-message.ts +0 -84
- package/src/interface/index.ts +0 -14
- package/src/interface/org-data/org-data.ts +0 -42
- package/src/params/params.ts +0 -134
- package/src/types.ts +0 -110
- package/src/utils/bit-mask/bit-mask.ts +0 -85
- package/src/utils/click-outside/click-outside.ts +0 -110
- package/src/utils/clone/clone.ts +0 -43
- package/src/utils/color/color.ts +0 -84
- package/src/utils/data-type/data-types.ts +0 -99
- package/src/utils/download-file/download-file.ts +0 -109
- package/src/utils/event/event.ts +0 -77
- package/src/utils/history-list/history-item.ts +0 -45
- package/src/utils/history-list/history-list.ts +0 -151
- package/src/utils/index.ts +0 -24
- package/src/utils/interceptor/core-interceptor.ts +0 -40
- package/src/utils/interceptor/index.ts +0 -2
- package/src/utils/interceptor/interceptor.ts +0 -126
- package/src/utils/logger/logger.ts +0 -10
- package/src/utils/message-center/base/message-all.ts +0 -12
- package/src/utils/message-center/base/message-base.ts +0 -86
- package/src/utils/message-center/command/async-action/command-async-action.ts +0 -24
- package/src/utils/message-center/command/change/command-change.ts +0 -12
- package/src/utils/message-center/command/command-base/command-base.ts +0 -30
- package/src/utils/message-center/command/create/command-create.ts +0 -24
- package/src/utils/message-center/command/internal-message/command-internal-message.ts +0 -24
- package/src/utils/message-center/command/mark-open-data/command-mark-open-data.ts +0 -24
- package/src/utils/message-center/command/message-command.ts +0 -158
- package/src/utils/message-center/command/remove/command-remove.ts +0 -24
- package/src/utils/message-center/command/update/command-update.ts +0 -24
- package/src/utils/message-center/console/message-console.ts +0 -31
- package/src/utils/message-center/index.ts +0 -1
- package/src/utils/message-center/interface/i-app-data-entity.ts +0 -19
- package/src/utils/message-center/interface/index.ts +0 -1
- package/src/utils/message-center/message-center.ts +0 -82
- package/src/utils/namespace/namespace.ts +0 -247
- package/src/utils/net/http-response.ts +0 -106
- package/src/utils/net/net.ts +0 -469
- package/src/utils/recursive/find-recursive-child.ts +0 -133
- package/src/utils/string-util/string-util.ts +0 -60
- package/src/utils/style/remote-style.ts +0 -20
- package/src/utils/sync/await-timeout.ts +0 -27
- package/src/utils/sync/count-latch.ts +0 -95
- package/src/utils/sync/index.ts +0 -2
- package/src/utils/types/types.ts +0 -22
- package/src/utils/upload/select-file.ts +0 -86
- package/src/utils/upload/upload-file.ts +0 -208
- package/src/utils/url-helper/url-helper.ts +0 -63
- package/src/utils/util/util.ts +0 -376
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { RuntimeError } from '../../error';
|
|
2
|
-
import {
|
|
3
|
-
OnClickOutsideHandler,
|
|
4
|
-
OnClickOutsideOptions,
|
|
5
|
-
OnClickOutsideResult,
|
|
6
|
-
} from '../../interface';
|
|
7
|
-
import { eventPath, isEventInside, listenJSEvent } from '../event/event';
|
|
8
|
-
|
|
9
|
-
const defaultWindow = typeof window !== 'undefined' ? window : undefined;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* 监听目标元素之外的点击事件回调
|
|
13
|
-
*
|
|
14
|
-
* @author lxm
|
|
15
|
-
* @date 2022-10-28 18:10:25
|
|
16
|
-
* @export
|
|
17
|
-
* @param {HTMLElement} target 目标元素
|
|
18
|
-
* @param {OnClickOutsideHandler} handler 触发的时间回调
|
|
19
|
-
* @param {OnClickOutsideOptions} [options={}] 额外配置参数
|
|
20
|
-
* @returns {*} {OnClickOutsideResult}
|
|
21
|
-
*/
|
|
22
|
-
export function onClickOutside(
|
|
23
|
-
target: HTMLElement,
|
|
24
|
-
handler: OnClickOutsideHandler,
|
|
25
|
-
options: OnClickOutsideOptions = {},
|
|
26
|
-
): OnClickOutsideResult {
|
|
27
|
-
const { window = defaultWindow, ignore = [], capture = true } = options;
|
|
28
|
-
|
|
29
|
-
if (!target) throw new RuntimeError('target元素不存在');
|
|
30
|
-
if (!window) throw new RuntimeError('找不到window');
|
|
31
|
-
|
|
32
|
-
/** 是否需要监听,为false时handler不会执行 */
|
|
33
|
-
let shouldListen = true;
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 判断event的触发是否是在元素的外部(排除了ignore元素)
|
|
37
|
-
* @param event 事件对象
|
|
38
|
-
* @returns
|
|
39
|
-
*/
|
|
40
|
-
const isOutside = (event: MouseEvent): boolean => {
|
|
41
|
-
// 有一个判断是在内部,则不算外部,返回false
|
|
42
|
-
return ![target, ...ignore].some(el => {
|
|
43
|
-
return isEventInside(event, el);
|
|
44
|
-
});
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
|
|
48
|
-
let isPaused = false;
|
|
49
|
-
const pause = (): void => {
|
|
50
|
-
isPaused = true;
|
|
51
|
-
};
|
|
52
|
-
const proceed = (): void => {
|
|
53
|
-
isPaused = false;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/** pointerup延时触发标识 */
|
|
57
|
-
let fallback: number;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* 事件监听处理回调
|
|
61
|
-
* @param event 事件对象
|
|
62
|
-
* @returns
|
|
63
|
-
*/
|
|
64
|
-
const listener = (event: MouseEvent): void => {
|
|
65
|
-
if (isPaused) return;
|
|
66
|
-
window.clearTimeout(fallback);
|
|
67
|
-
|
|
68
|
-
// 当需要监听并且最终触发在外部时才需要执行回调
|
|
69
|
-
if (!(shouldListen && isOutside(event))) return;
|
|
70
|
-
|
|
71
|
-
handler(event);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
// 鼠标左键单击先后触发pointerdown,pointerup,click
|
|
75
|
-
// 鼠标右键单击先后触发pointerdown,pointerup
|
|
76
|
-
const cleanups = [
|
|
77
|
-
listenJSEvent(window, 'click', listener, { passive: true, capture }),
|
|
78
|
-
listenJSEvent(
|
|
79
|
-
window,
|
|
80
|
-
'pointerdown',
|
|
81
|
-
e => {
|
|
82
|
-
if (isPaused) return;
|
|
83
|
-
// 当pointerdown是在内部触发则不需要后续监听
|
|
84
|
-
shouldListen = isOutside(e);
|
|
85
|
-
},
|
|
86
|
-
{ passive: true },
|
|
87
|
-
),
|
|
88
|
-
listenJSEvent(
|
|
89
|
-
window,
|
|
90
|
-
'pointerup',
|
|
91
|
-
e => {
|
|
92
|
-
if (isPaused) return;
|
|
93
|
-
// 鼠标左键触发才执行
|
|
94
|
-
if (e.button === 0) {
|
|
95
|
-
// 锁死结果避免延时执行时变更
|
|
96
|
-
const path = eventPath(e);
|
|
97
|
-
e.composedPath = (): (EventTarget | null)[] => path;
|
|
98
|
-
fallback = window.setTimeout(() => listener(e), 50);
|
|
99
|
-
}
|
|
100
|
-
},
|
|
101
|
-
{ passive: true },
|
|
102
|
-
),
|
|
103
|
-
].filter(Boolean);
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 停止事件监听,移除监听
|
|
107
|
-
*/
|
|
108
|
-
const stop = (): void => cleanups.forEach(fn => fn());
|
|
109
|
-
return { stop, pause, proceed };
|
|
110
|
-
}
|
package/src/utils/clone/clone.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { cloneDeepWith, cloneWith, isFunction, isObject } from 'lodash-es';
|
|
2
|
-
import { mergeDeepRight } from 'ramda';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 自定义克隆逻辑,有clone方法的拿clone方法,否则直接用lodash的clone
|
|
6
|
-
* @author lxm
|
|
7
|
-
* @date 2023-10-25 06:12:23
|
|
8
|
-
* @param {unknown} value
|
|
9
|
-
* @return {*} {unknown}
|
|
10
|
-
*/
|
|
11
|
-
function customizeFn<T>(value: T): T | undefined {
|
|
12
|
-
if (isObject(value) && isFunction((value as IData).clone)) {
|
|
13
|
-
return (value as IData).clone();
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export type CloneOpts = {
|
|
18
|
-
deep?: boolean;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const DefaultCloneOpts: CloneOpts = {
|
|
22
|
-
deep: true,
|
|
23
|
-
} as const;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* 克隆方法(如果对象有clone方法会用clone方法调用clone)
|
|
27
|
-
* @author lxm
|
|
28
|
-
* @date 2023-10-25 06:24:18
|
|
29
|
-
* @export
|
|
30
|
-
* @template T
|
|
31
|
-
* @param {readonly} value
|
|
32
|
-
* @param {*} T
|
|
33
|
-
* @param {*} []
|
|
34
|
-
* @param {CloneOpts} [opts]
|
|
35
|
-
* @return {*} {T[]}
|
|
36
|
-
*/
|
|
37
|
-
export function clone<T>(value: T, opts?: CloneOpts): T {
|
|
38
|
-
const options = mergeDeepRight(DefaultCloneOpts, opts || {})!;
|
|
39
|
-
if (options.deep) {
|
|
40
|
-
return cloneDeepWith(value, customizeFn);
|
|
41
|
-
}
|
|
42
|
-
return cloneWith(value, customizeFn);
|
|
43
|
-
}
|
package/src/utils/color/color.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-bitwise */
|
|
2
|
-
/* eslint-disable no-nested-ternary */
|
|
3
|
-
const r = Math.round;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 把颜色字符串转成RGBA数组
|
|
7
|
-
*
|
|
8
|
-
* @param {string} color 颜色字符串
|
|
9
|
-
* @returns {*} {number[]}
|
|
10
|
-
*/
|
|
11
|
-
function toRGBA(color: string): number[] {
|
|
12
|
-
const l = color.length;
|
|
13
|
-
const rgba = [];
|
|
14
|
-
if (color.slice(0, 3).toLowerCase() === 'rgb') {
|
|
15
|
-
const d = color.match(/([\d|.%]{1,3})/g)!;
|
|
16
|
-
rgba[0] = parseInt(d[0], 10);
|
|
17
|
-
rgba[1] = parseInt(d[1], 10);
|
|
18
|
-
rgba[2] = parseInt(d[2], 10);
|
|
19
|
-
rgba[3] = d[3]
|
|
20
|
-
? d[3].indexOf('%') !== -1
|
|
21
|
-
? parseInt(d[3], 10) / 100
|
|
22
|
-
: parseFloat(d[3])
|
|
23
|
-
: 1;
|
|
24
|
-
} else {
|
|
25
|
-
let d: number;
|
|
26
|
-
if (l < 6)
|
|
27
|
-
d = parseInt(
|
|
28
|
-
String(color[1]) +
|
|
29
|
-
color[1] +
|
|
30
|
-
color[2] +
|
|
31
|
-
color[2] +
|
|
32
|
-
color[3] +
|
|
33
|
-
color[3] +
|
|
34
|
-
(l > 4 ? String(color[4]) + color[4] : ''),
|
|
35
|
-
16,
|
|
36
|
-
);
|
|
37
|
-
else d = parseInt(color.slice(1), 16);
|
|
38
|
-
rgba[0] = (d >> 16) & 255;
|
|
39
|
-
rgba[1] = (d >> 8) & 255;
|
|
40
|
-
rgba[2] = d & 255;
|
|
41
|
-
rgba[3] =
|
|
42
|
-
l === 9 || l === 5 ? r((((d >> 24) & 255) / 255) * 10000) / 10000 : 1;
|
|
43
|
-
}
|
|
44
|
-
return rgba;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* 混合两种颜色,颜色格式支持hex和rgb
|
|
49
|
-
* 如:#46b5d555,#fff
|
|
50
|
-
* rgb(245 245 245 / 80%)
|
|
51
|
-
*
|
|
52
|
-
* @param {string} color1 颜色1
|
|
53
|
-
* @param {string} color2 颜色2
|
|
54
|
-
* @param {number} [p=0.5] 颜色1占多少百分比,小数格式
|
|
55
|
-
* @param {("hex" | "rgb")} [format="hex"] 输出的格式,hex或rgb
|
|
56
|
-
* @returns {*}
|
|
57
|
-
*/
|
|
58
|
-
export function colorBlend(
|
|
59
|
-
color1: string,
|
|
60
|
-
color2: string,
|
|
61
|
-
p = 0.5,
|
|
62
|
-
format: 'hex' | 'rgb' = 'hex',
|
|
63
|
-
): string {
|
|
64
|
-
color1 = color1.trim();
|
|
65
|
-
color2 = color2.trim();
|
|
66
|
-
const c1 = toRGBA(color1);
|
|
67
|
-
const c2 = toRGBA(color2);
|
|
68
|
-
const result = [
|
|
69
|
-
r((1 - p) * c1[0] + p * c2[0]),
|
|
70
|
-
r((1 - p) * c1[1] + p * c2[1]),
|
|
71
|
-
r((1 - p) * c1[2] + p * c2[2]),
|
|
72
|
-
(1 - p) * c1[3] + p * c2[3],
|
|
73
|
-
];
|
|
74
|
-
if (format === 'hex') {
|
|
75
|
-
const hex = [
|
|
76
|
-
result[0].toString(16),
|
|
77
|
-
result[1].toString(16),
|
|
78
|
-
result[2].toString(16),
|
|
79
|
-
result[3] === 0 ? '00' : r(result[3] * 255).toString(16),
|
|
80
|
-
];
|
|
81
|
-
return `#${hex[0]}${hex[1]}${hex[2]}${hex[3]}`;
|
|
82
|
-
}
|
|
83
|
-
return `rgb(${result[0]} ${result[1]} ${result[2]} / ${result[3]})`;
|
|
84
|
-
}
|
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 数据类型转换识别工具类
|
|
3
|
-
* @author lxm
|
|
4
|
-
* @date 2023-08-25 04:33:49
|
|
5
|
-
* @export
|
|
6
|
-
* @class DataTypes
|
|
7
|
-
*/
|
|
8
|
-
export class DataTypes {
|
|
9
|
-
/**
|
|
10
|
-
* 数字类型映射字符串类型
|
|
11
|
-
* @author lxm
|
|
12
|
-
* @date 2023-08-25 04:49:52
|
|
13
|
-
* @static
|
|
14
|
-
* @type {{ [p: number]: string }}
|
|
15
|
-
*/
|
|
16
|
-
static readonly typeMap: { [p: number]: string } = {
|
|
17
|
-
0: 'UNKNOWN',
|
|
18
|
-
1: 'BIGINT',
|
|
19
|
-
2: 'BINARY',
|
|
20
|
-
3: 'BIT',
|
|
21
|
-
4: 'CHAR',
|
|
22
|
-
5: 'DATETIME',
|
|
23
|
-
6: 'DECIMAL',
|
|
24
|
-
7: 'FLOAT',
|
|
25
|
-
8: 'IMAGE',
|
|
26
|
-
9: 'INT',
|
|
27
|
-
10: 'MONEY',
|
|
28
|
-
11: 'NCHAR',
|
|
29
|
-
12: 'NTEXT',
|
|
30
|
-
13: 'NVARCHAR',
|
|
31
|
-
14: 'NUMERIC',
|
|
32
|
-
15: 'REAL',
|
|
33
|
-
16: 'SMALLDATETIME',
|
|
34
|
-
17: 'SMALLINT',
|
|
35
|
-
18: 'SMALLMONEY',
|
|
36
|
-
19: 'SQL_VARIANT',
|
|
37
|
-
20: 'SYSNAME',
|
|
38
|
-
21: 'TEXT',
|
|
39
|
-
22: 'TIMESTAMP',
|
|
40
|
-
23: 'TINYINT',
|
|
41
|
-
24: 'VARBINARY',
|
|
42
|
-
25: 'VARCHAR',
|
|
43
|
-
26: 'UNIQUEIDENTIFIER',
|
|
44
|
-
27: 'DATE', // 纯日期型
|
|
45
|
-
28: 'TIME', // 纯时间
|
|
46
|
-
29: 'BIGDECIMAL', // 大数值
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 是否是数值类型
|
|
51
|
-
* @author lxm
|
|
52
|
-
* @date 2023-08-25 04:53:30
|
|
53
|
-
* @static
|
|
54
|
-
* @param {number} dataType 数据类型(数值)
|
|
55
|
-
* @return {*} {boolean}
|
|
56
|
-
*/
|
|
57
|
-
public static isNumber(dataType: number): boolean {
|
|
58
|
-
const numberTypes = [
|
|
59
|
-
'BIGINT',
|
|
60
|
-
'BINARY',
|
|
61
|
-
'DECIMAL',
|
|
62
|
-
'FLOAT',
|
|
63
|
-
'INT',
|
|
64
|
-
'MONEY',
|
|
65
|
-
'NUMERIC',
|
|
66
|
-
'REAL',
|
|
67
|
-
'SMALLINT',
|
|
68
|
-
'SMALLMONEY',
|
|
69
|
-
'TINYINT',
|
|
70
|
-
'VARBINARY',
|
|
71
|
-
];
|
|
72
|
-
return numberTypes.includes(this.toString(dataType));
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* 是否是日期类型数据
|
|
77
|
-
*
|
|
78
|
-
* @static
|
|
79
|
-
* @param {number} dataType
|
|
80
|
-
* @return {*}
|
|
81
|
-
* @memberof DataTypes
|
|
82
|
-
*/
|
|
83
|
-
public static isDate(dataType: number): boolean {
|
|
84
|
-
const dateTypes = ['DATETIME', 'SMALLDATETIME', 'DATE', 'TIME'];
|
|
85
|
-
return dateTypes.includes(this.toString(dataType));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 获取字符串数据类型
|
|
90
|
-
* @author lxm
|
|
91
|
-
* @date 2023-08-25 04:53:58
|
|
92
|
-
* @static
|
|
93
|
-
* @param {number} dataType 数据类型(数值)
|
|
94
|
-
* @return {*} {string}
|
|
95
|
-
*/
|
|
96
|
-
public static toString(dataType: number): string {
|
|
97
|
-
return this.typeMap[dataType];
|
|
98
|
-
}
|
|
99
|
-
}
|
|
@@ -1,109 +0,0 @@
|
|
|
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: string): string {
|
|
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
|
-
*
|
|
66
|
-
* @author lxm
|
|
67
|
-
* @date 2022-11-21 13:11:23
|
|
68
|
-
* @export
|
|
69
|
-
* @param {string} fileName
|
|
70
|
-
* @returns {*} {boolean}
|
|
71
|
-
*/
|
|
72
|
-
export function isImage(fileName: string): boolean {
|
|
73
|
-
const ext = fileName.split('.').pop();
|
|
74
|
-
if (!ext) {
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
const imageTypes = ['.jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
|
|
78
|
-
return imageTypes.includes(ext);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* 纯JS触发下载文件
|
|
83
|
-
*
|
|
84
|
-
* @author lxm
|
|
85
|
-
* @date 2022-11-16 22:11:24
|
|
86
|
-
* @export
|
|
87
|
-
* @param {Blob} file 文件流Blob
|
|
88
|
-
* @param {string} fileName 文件名称
|
|
89
|
-
*/
|
|
90
|
-
export function downloadFileFromBlob(file: Blob, fileName: string): void {
|
|
91
|
-
// 获取文件名
|
|
92
|
-
const filetype = calcMimeByFileName(fileName);
|
|
93
|
-
// 用blob对象获取文件流
|
|
94
|
-
const blob = new Blob([file], { type: filetype });
|
|
95
|
-
// 通过文件流创建下载链接
|
|
96
|
-
const href = URL.createObjectURL(blob);
|
|
97
|
-
// 创建一个a元素并设置相关属性
|
|
98
|
-
const a = document.createElement('a');
|
|
99
|
-
a.href = href;
|
|
100
|
-
a.download = fileName;
|
|
101
|
-
// 添加a元素到当前网页
|
|
102
|
-
document.body.appendChild(a);
|
|
103
|
-
// 触发a元素的点击事件,实现下载
|
|
104
|
-
a.click();
|
|
105
|
-
// 从当前网页移除a元素
|
|
106
|
-
document.body.removeChild(a);
|
|
107
|
-
// 释放blob对象
|
|
108
|
-
URL.revokeObjectURL(href);
|
|
109
|
-
}
|
package/src/utils/event/event.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
-
|
|
3
|
-
import { NOOP } from '../../constant';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 计算event的composedPath返回事件路径(兼容了IE)
|
|
7
|
-
*
|
|
8
|
-
* @author lxm
|
|
9
|
-
* @date 2022-10-28 17:10:14
|
|
10
|
-
* @param {MouseEvent} event
|
|
11
|
-
* @returns {*}
|
|
12
|
-
*/
|
|
13
|
-
export function eventPath(event: MouseEvent): (EventTarget | null)[] {
|
|
14
|
-
const path = ((event.composedPath && event.composedPath()) ||
|
|
15
|
-
(event as any).path) as HTMLElement[] | undefined;
|
|
16
|
-
|
|
17
|
-
if (path != null) return path;
|
|
18
|
-
|
|
19
|
-
// 浏览器没有提供的,自己递归计算
|
|
20
|
-
function getParents(
|
|
21
|
-
node: HTMLElement,
|
|
22
|
-
memo: HTMLElement[] = [],
|
|
23
|
-
): HTMLElement[] {
|
|
24
|
-
const parentNode = node.parentNode as HTMLElement | null;
|
|
25
|
-
|
|
26
|
-
return parentNode
|
|
27
|
-
? getParents(parentNode, memo.concat([parentNode]))
|
|
28
|
-
: memo;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return [event.target].concat(getParents(event.target as HTMLElement));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 监听JS原生事件,返回cleanup回调,调用后删除该监听
|
|
36
|
-
*
|
|
37
|
-
* @author lxm
|
|
38
|
-
* @date 2022-10-28 18:10:36
|
|
39
|
-
* @export
|
|
40
|
-
* @param {EventTarget} target 监听对象
|
|
41
|
-
* @param {string} eventName 监听事件名称
|
|
42
|
-
* @param {(..._args: any[]) => any} listener 监听回调
|
|
43
|
-
* @param {AddEventListenerOptions} options 额外参数
|
|
44
|
-
* @returns {*} {() => void}
|
|
45
|
-
*/
|
|
46
|
-
export function listenJSEvent(
|
|
47
|
-
target: EventTarget,
|
|
48
|
-
eventName: string,
|
|
49
|
-
listener: (..._args: any[]) => any,
|
|
50
|
-
options: AddEventListenerOptions = {},
|
|
51
|
-
): () => void {
|
|
52
|
-
target.addEventListener(eventName, listener, options);
|
|
53
|
-
|
|
54
|
-
let cleanup = (): void => {
|
|
55
|
-
target.removeEventListener(eventName, listener, options);
|
|
56
|
-
// cleanup方法只能调用一次
|
|
57
|
-
cleanup = NOOP;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
return () => {
|
|
61
|
-
cleanup();
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* event是否是在目标元素内部触发的
|
|
67
|
-
*
|
|
68
|
-
* @author lxm
|
|
69
|
-
* @date 2022-10-31 11:10:49
|
|
70
|
-
* @export
|
|
71
|
-
* @param {MouseEvent} event 原生事件
|
|
72
|
-
* @param {HTMLElement} el 目标元素
|
|
73
|
-
* @returns {*} {boolean}
|
|
74
|
-
*/
|
|
75
|
-
export function isEventInside(event: MouseEvent, el: HTMLElement): boolean {
|
|
76
|
-
return el && (event.target === el || eventPath(event).includes(el));
|
|
77
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { clone } from 'ramda';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 历史项
|
|
5
|
-
*
|
|
6
|
-
* @author chitanda
|
|
7
|
-
* @date 2023-12-28 21:12:38
|
|
8
|
-
* @export
|
|
9
|
-
* @class History
|
|
10
|
-
* @template E
|
|
11
|
-
*/
|
|
12
|
-
export class HistoryItem<E> {
|
|
13
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
-
static readonly Undefined = new HistoryItem<any>(undefined);
|
|
15
|
-
|
|
16
|
-
_prev: HistoryItem<E>;
|
|
17
|
-
|
|
18
|
-
_next: HistoryItem<E>;
|
|
19
|
-
|
|
20
|
-
data: E;
|
|
21
|
-
|
|
22
|
-
constructor(data: unknown = {}) {
|
|
23
|
-
this.data = data as E;
|
|
24
|
-
this._prev = HistoryItem.Undefined;
|
|
25
|
-
this._next = HistoryItem.Undefined;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 克隆整个历史链
|
|
30
|
-
*
|
|
31
|
-
* @author chitanda
|
|
32
|
-
* @date 2023-12-28 23:12:56
|
|
33
|
-
* @return {*} {HistoryItem<E>}
|
|
34
|
-
*/
|
|
35
|
-
clone(): HistoryItem<E> {
|
|
36
|
-
const history = new HistoryItem<E>(clone(this.data));
|
|
37
|
-
if (history._prev && history._prev !== HistoryItem.Undefined) {
|
|
38
|
-
history._prev = clone(this._prev);
|
|
39
|
-
}
|
|
40
|
-
if (history._next && history._next !== HistoryItem.Undefined) {
|
|
41
|
-
history._next = clone(this._next);
|
|
42
|
-
}
|
|
43
|
-
return history;
|
|
44
|
-
}
|
|
45
|
-
}
|