@ibiz-template/core 0.7.41-alpha.101 → 0.7.41-alpha.113
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 +2 -1
- package/dist/index.system.min.js +1 -1
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +1 -0
- package/out/interface/api/environment/i-environment.d.ts +8 -0
- package/out/interface/api/environment/i-environment.d.ts.map +1 -1
- package/package.json +3 -2
- 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 +65 -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 +532 -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,131 @@
|
|
|
1
|
+
/* eslint-disable no-constructor-return */
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 视图参数处理类
|
|
5
|
+
* @export
|
|
6
|
+
* @class IBizParams
|
|
7
|
+
* @implements {IParams}
|
|
8
|
+
*/
|
|
9
|
+
export class IBizParams implements IParams {
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
11
|
+
[key: string | symbol]: any;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @description 自身的属性
|
|
15
|
+
* @protected
|
|
16
|
+
* @type {IParams}
|
|
17
|
+
* @memberof IBizParams
|
|
18
|
+
*/
|
|
19
|
+
declare protected _params: IParams;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @description 父视图参数
|
|
23
|
+
* @protected
|
|
24
|
+
* @type {IParams}
|
|
25
|
+
* @memberof IBizParams
|
|
26
|
+
*/
|
|
27
|
+
declare protected _parent?: IParams;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Creates an instance of IBizParams.
|
|
31
|
+
* @param {IParams} [params] 自身的参数
|
|
32
|
+
* @param {IParams} [parent] 父视图参数
|
|
33
|
+
* @memberof IBizParams
|
|
34
|
+
*/
|
|
35
|
+
constructor(params?: IParams, parent?: IParams) {
|
|
36
|
+
// 定义私有变量,存放父视图参数源对象
|
|
37
|
+
Object.defineProperty(this, '_parent', {
|
|
38
|
+
enumerable: false,
|
|
39
|
+
configurable: true,
|
|
40
|
+
writable: true,
|
|
41
|
+
value: parent,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// 定义私有变量,用于存储对父已有视图参数的修改。
|
|
45
|
+
Object.defineProperty(this, '_params', {
|
|
46
|
+
enumerable: false,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true,
|
|
49
|
+
value: params || {},
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
return this.createProxy();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description 创建代理对象
|
|
57
|
+
* @protected
|
|
58
|
+
* @returns {*} {IBizParams}
|
|
59
|
+
* @memberof IBizParams
|
|
60
|
+
*/
|
|
61
|
+
protected createProxy(): IBizParams {
|
|
62
|
+
// 更新属性,缺的补充定义
|
|
63
|
+
function updateKeyDefine(target: IParams, keys: string[]): void {
|
|
64
|
+
keys.forEach(key => {
|
|
65
|
+
if (!Object.prototype.hasOwnProperty.call(target, key)) {
|
|
66
|
+
Object.defineProperty(target, key, {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true,
|
|
69
|
+
writable: true,
|
|
70
|
+
value: undefined,
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return new Proxy(this, {
|
|
77
|
+
set(target: IBizParams, p: string, value: unknown): boolean {
|
|
78
|
+
if (['_params', '_parent'].includes(p)) {
|
|
79
|
+
target[p] = value;
|
|
80
|
+
} else {
|
|
81
|
+
target._params[p] = value;
|
|
82
|
+
}
|
|
83
|
+
return true;
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
get(target: IBizParams, p: string | symbol, _receiver: unknown): unknown {
|
|
87
|
+
if (target[p] !== undefined) {
|
|
88
|
+
return target[p];
|
|
89
|
+
}
|
|
90
|
+
if (target._params[p] !== undefined) {
|
|
91
|
+
return target._params[p];
|
|
92
|
+
}
|
|
93
|
+
if (target._parent && target._parent[p] !== undefined) {
|
|
94
|
+
return target._parent[p];
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
ownKeys(target: IBizParams): ArrayLike<string | symbol> {
|
|
99
|
+
// 整合所有并排重
|
|
100
|
+
const allKeys = [
|
|
101
|
+
...new Set([
|
|
102
|
+
...Object.keys(target._params),
|
|
103
|
+
...Object.keys(target._parent || {}),
|
|
104
|
+
]),
|
|
105
|
+
];
|
|
106
|
+
updateKeyDefine(target, allKeys);
|
|
107
|
+
return allKeys;
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* @description 在不改变对象引用的情况下,重置视图参数,等效于重新实例化,但是引用不变
|
|
114
|
+
* @param {IParams} [params] 视图参数
|
|
115
|
+
* @param {IParams} [parent] 父视图参数
|
|
116
|
+
* @memberof IBizParams
|
|
117
|
+
*/
|
|
118
|
+
reset(params?: IParams, parent?: IParams): void {
|
|
119
|
+
this._params = params || {};
|
|
120
|
+
this._parent = parent;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description 销毁视图参数,避免内存泄漏
|
|
125
|
+
* @memberof IBizParams
|
|
126
|
+
*/
|
|
127
|
+
destroy(): void {
|
|
128
|
+
this._params = {};
|
|
129
|
+
this._parent = undefined;
|
|
130
|
+
}
|
|
131
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { IBizSys } from './ibizsys';
|
|
3
|
+
import {
|
|
4
|
+
IApiContext,
|
|
5
|
+
IApiData,
|
|
6
|
+
IApiObject,
|
|
7
|
+
IApiParams,
|
|
8
|
+
IEnvironment,
|
|
9
|
+
} from './interface';
|
|
10
|
+
|
|
11
|
+
declare global {
|
|
12
|
+
const ibiz: IBizSys;
|
|
13
|
+
|
|
14
|
+
interface Window {
|
|
15
|
+
ibiz: IBizSys;
|
|
16
|
+
Environment: IEnvironment;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
type IContext = IApiContext;
|
|
20
|
+
|
|
21
|
+
type IParams = IApiParams;
|
|
22
|
+
|
|
23
|
+
type IData = IApiData;
|
|
24
|
+
|
|
25
|
+
type IObject = IApiObject;
|
|
26
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/* eslint-disable default-param-last */
|
|
2
|
+
/* eslint-disable no-bitwise */
|
|
3
|
+
|
|
4
|
+
import { RuntimeError } from '../../error';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @description 检查权限码是否有效,权限码是否是2的幂
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* validate(1) // => true
|
|
11
|
+
* validate(3) // => false
|
|
12
|
+
* ```
|
|
13
|
+
* @static
|
|
14
|
+
* @param {number} permission
|
|
15
|
+
*/
|
|
16
|
+
function validate(permission: number): boolean {
|
|
17
|
+
return !!permission && !(permission & (permission - 1));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @description 检查权限码是否有效,无效抛错
|
|
22
|
+
* @param {number} permission
|
|
23
|
+
*/
|
|
24
|
+
function validateAndThrow(permission: number): void {
|
|
25
|
+
const isPowerOf2 = validate(permission);
|
|
26
|
+
if (!isPowerOf2) {
|
|
27
|
+
throw new RuntimeError(
|
|
28
|
+
ibiz.i18n.t('core.utils.powerOfTwo', { permission }),
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* @description 设置权限,数字转二进制后进行|运算, 设置对应bit位为1(bit位为1代表有权限,bit位为0代表没有权限)
|
|
35
|
+
* @example
|
|
36
|
+
* ```typescript
|
|
37
|
+
* setPermission(0, 1) // => 1
|
|
38
|
+
* setPermission(1, 4) // => 5
|
|
39
|
+
* ```
|
|
40
|
+
* @param {number} [allPermissions=0]
|
|
41
|
+
* @param {number} permission
|
|
42
|
+
* @returns {*} {number}
|
|
43
|
+
*/
|
|
44
|
+
function setPermission(allPermissions: number = 0, permission: number): number {
|
|
45
|
+
validateAndThrow(permission);
|
|
46
|
+
return allPermissions | permission;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* @description 移出权限,数字转二进制后进行取反并且进行&运算, 设置对应bit位为0(bit位为1代表有权限,bit位为0代表没有权限)
|
|
51
|
+
* @param {number} [allPermissions=0] 当前所有权限
|
|
52
|
+
* @param {number} permission 要移出的权限
|
|
53
|
+
* @returns {*} {number}
|
|
54
|
+
*/
|
|
55
|
+
function removePermission(
|
|
56
|
+
allPermissions: number = 0,
|
|
57
|
+
permission: number,
|
|
58
|
+
): number {
|
|
59
|
+
validateAndThrow(permission);
|
|
60
|
+
return allPermissions & ~permission;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @description 检查是否有某个权限,数字转二进制后进行&运算,为1则有权限,为0则没有权限
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* checkPermission(0, 1) // => false
|
|
68
|
+
* checkPermission(5, 4) // => true
|
|
69
|
+
* ```
|
|
70
|
+
* @param {number} [allPermissions=0]
|
|
71
|
+
* @param {number} permission
|
|
72
|
+
* @returns {*} {boolean}
|
|
73
|
+
*/
|
|
74
|
+
function checkPermission(
|
|
75
|
+
allPermissions: number = 0,
|
|
76
|
+
permission: number,
|
|
77
|
+
): boolean {
|
|
78
|
+
validateAndThrow(permission);
|
|
79
|
+
return (allPermissions & permission) !== 0;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export const BitMask = {
|
|
83
|
+
validate,
|
|
84
|
+
setPermission,
|
|
85
|
+
removePermission,
|
|
86
|
+
checkPermission,
|
|
87
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
* @description 监听目标元素之外的点击事件回调
|
|
13
|
+
* @export
|
|
14
|
+
* @param {HTMLElement} target 目标元素
|
|
15
|
+
* @param {OnClickOutsideHandler} handler 触发的时间回调
|
|
16
|
+
* @param {OnClickOutsideOptions} [options={}] 额外配置参数
|
|
17
|
+
* @returns {*} {OnClickOutsideResult}
|
|
18
|
+
*/
|
|
19
|
+
export function onClickOutside(
|
|
20
|
+
target: HTMLElement,
|
|
21
|
+
handler: OnClickOutsideHandler,
|
|
22
|
+
options: OnClickOutsideOptions = {},
|
|
23
|
+
): OnClickOutsideResult {
|
|
24
|
+
const { window = defaultWindow, ignore = [], capture = true } = options;
|
|
25
|
+
|
|
26
|
+
if (!target) throw new RuntimeError(ibiz.i18n.t('core.utils.targetElement'));
|
|
27
|
+
if (!window)
|
|
28
|
+
throw new RuntimeError(ibiz.i18n.t('core.utils.cannotFindWindow'));
|
|
29
|
+
|
|
30
|
+
/** 是否需要监听,为false时handler不会执行 */
|
|
31
|
+
let shouldListen = true;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* 判断event的触发是否是在元素的外部(排除了ignore元素)
|
|
35
|
+
* @param event 事件对象
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
const isOutside = (event: MouseEvent): boolean => {
|
|
39
|
+
// 有一个判断是在内部,则不算外部,返回false
|
|
40
|
+
return ![target, ...ignore].some(el => {
|
|
41
|
+
return isEventInside(event, el);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
|
|
46
|
+
let isPaused = false;
|
|
47
|
+
const pause = (): void => {
|
|
48
|
+
isPaused = true;
|
|
49
|
+
};
|
|
50
|
+
const proceed = (): void => {
|
|
51
|
+
isPaused = false;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** pointerup延时触发标识 */
|
|
55
|
+
let fallback: number;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 事件监听处理回调
|
|
59
|
+
* @param event 事件对象
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
const listener = (event: MouseEvent): void => {
|
|
63
|
+
if (isPaused) return;
|
|
64
|
+
window.clearTimeout(fallback);
|
|
65
|
+
|
|
66
|
+
// 当需要监听并且最终触发在外部时才需要执行回调
|
|
67
|
+
if (!(shouldListen && isOutside(event))) return;
|
|
68
|
+
|
|
69
|
+
handler(event);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// 鼠标左键单击先后触发pointerdown,pointerup,click
|
|
73
|
+
// 鼠标右键单击先后触发pointerdown,pointerup
|
|
74
|
+
const cleanups = [
|
|
75
|
+
listenJSEvent(window, 'click', listener, { passive: true, capture }),
|
|
76
|
+
listenJSEvent(
|
|
77
|
+
window,
|
|
78
|
+
'pointerdown',
|
|
79
|
+
e => {
|
|
80
|
+
if (isPaused) return;
|
|
81
|
+
// 当pointerdown是在内部触发则不需要后续监听
|
|
82
|
+
shouldListen = isOutside(e);
|
|
83
|
+
},
|
|
84
|
+
{ passive: true },
|
|
85
|
+
),
|
|
86
|
+
listenJSEvent(
|
|
87
|
+
window,
|
|
88
|
+
'pointerup',
|
|
89
|
+
e => {
|
|
90
|
+
if (isPaused) return;
|
|
91
|
+
// 鼠标左键触发才执行
|
|
92
|
+
if (e.button === 0) {
|
|
93
|
+
// 锁死结果避免延时执行时变更
|
|
94
|
+
const path = eventPath(e);
|
|
95
|
+
e.composedPath = (): (EventTarget | null)[] => path;
|
|
96
|
+
fallback = window.setTimeout(() => listener(e), 50);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
{ passive: true },
|
|
100
|
+
),
|
|
101
|
+
].filter(Boolean);
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* 停止事件监听,移除监听
|
|
105
|
+
*/
|
|
106
|
+
const stop = (): void => cleanups.forEach(fn => fn());
|
|
107
|
+
return { stop, pause, proceed };
|
|
108
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { cloneDeepWith, cloneWith, isFunction, isObject } from 'lodash-es';
|
|
2
|
+
import { mergeDeepRight } from 'ramda';
|
|
3
|
+
|
|
4
|
+
export type CloneOpts = {
|
|
5
|
+
deep?: boolean;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @description 自定义克隆逻辑,有clone方法的拿clone方法,否则直接用lodash的clone
|
|
10
|
+
* @template T
|
|
11
|
+
* @param {T} value
|
|
12
|
+
* @returns {*} {(T | undefined)}
|
|
13
|
+
*/
|
|
14
|
+
function customizeFn<T>(value: T): T | undefined {
|
|
15
|
+
if (isObject(value) && isFunction((value as IData).clone)) {
|
|
16
|
+
return (value as IData).clone();
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const DefaultCloneOpts: CloneOpts = {
|
|
21
|
+
deep: true,
|
|
22
|
+
} as const;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @description 克隆方法(如果对象有clone方法会用clone方法调用clone)
|
|
26
|
+
* @export
|
|
27
|
+
* @template T
|
|
28
|
+
* @param {T} value
|
|
29
|
+
* @param {CloneOpts} [opts]
|
|
30
|
+
* @returns {*} {T}
|
|
31
|
+
*/
|
|
32
|
+
export function clone<T>(value: T, opts?: CloneOpts): T {
|
|
33
|
+
const options = mergeDeepRight(DefaultCloneOpts, opts || {})!;
|
|
34
|
+
if (options.deep) {
|
|
35
|
+
return cloneDeepWith(value, customizeFn);
|
|
36
|
+
}
|
|
37
|
+
return cloneWith(value, customizeFn);
|
|
38
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* eslint-disable no-bitwise */
|
|
2
|
+
/* eslint-disable no-nested-ternary */
|
|
3
|
+
const r = Math.round;
|
|
4
|
+
/**
|
|
5
|
+
* @description 把颜色字符串转成RGBA数组
|
|
6
|
+
* @param {string} color 颜色字符串
|
|
7
|
+
* @returns {*} {number[]}
|
|
8
|
+
*/
|
|
9
|
+
function toRGBA(color: string): number[] {
|
|
10
|
+
const l = color.length;
|
|
11
|
+
const rgba = [];
|
|
12
|
+
if (color.slice(0, 3).toLowerCase() === 'rgb') {
|
|
13
|
+
const d = color.match(/([\d|.%]{1,3})/g)!;
|
|
14
|
+
rgba[0] = parseInt(d[0], 10);
|
|
15
|
+
rgba[1] = parseInt(d[1], 10);
|
|
16
|
+
rgba[2] = parseInt(d[2], 10);
|
|
17
|
+
rgba[3] = d[3]
|
|
18
|
+
? d[3].indexOf('%') !== -1
|
|
19
|
+
? parseInt(d[3], 10) / 100
|
|
20
|
+
: parseFloat(d[3])
|
|
21
|
+
: 1;
|
|
22
|
+
} else {
|
|
23
|
+
let d: number;
|
|
24
|
+
if (l < 6)
|
|
25
|
+
d = parseInt(
|
|
26
|
+
String(color[1]) +
|
|
27
|
+
color[1] +
|
|
28
|
+
color[2] +
|
|
29
|
+
color[2] +
|
|
30
|
+
color[3] +
|
|
31
|
+
color[3] +
|
|
32
|
+
(l > 4 ? String(color[4]) + color[4] : ''),
|
|
33
|
+
16,
|
|
34
|
+
);
|
|
35
|
+
else d = parseInt(color.slice(1), 16);
|
|
36
|
+
rgba[0] = (d >> 16) & 255;
|
|
37
|
+
rgba[1] = (d >> 8) & 255;
|
|
38
|
+
rgba[2] = d & 255;
|
|
39
|
+
rgba[3] =
|
|
40
|
+
l === 9 || l === 5 ? r((((d >> 24) & 255) / 255) * 10000) / 10000 : 1;
|
|
41
|
+
}
|
|
42
|
+
return rgba;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @description 混合两种颜色,颜色格式支持hex和rgb,如:#46b5d555,#fff,转化结果为rgb(245 245 245 / 80%)
|
|
47
|
+
* @export
|
|
48
|
+
* @param {string} color1 颜色1
|
|
49
|
+
* @param {string} color2 颜色2
|
|
50
|
+
* @param {number} [p=0.5] 颜色1占多少百分比,小数格式
|
|
51
|
+
* @param {('hex' | 'rgb')} [format='hex'] 输出的格式,hex或rgb
|
|
52
|
+
* @returns {*} {string}
|
|
53
|
+
*/
|
|
54
|
+
export function colorBlend(
|
|
55
|
+
color1: string,
|
|
56
|
+
color2: string,
|
|
57
|
+
p = 0.5,
|
|
58
|
+
format: 'hex' | 'rgb' = 'hex',
|
|
59
|
+
): string {
|
|
60
|
+
color1 = color1.trim();
|
|
61
|
+
color2 = color2.trim();
|
|
62
|
+
const c1 = toRGBA(color1);
|
|
63
|
+
const c2 = toRGBA(color2);
|
|
64
|
+
const result = [
|
|
65
|
+
r((1 - p) * c1[0] + p * c2[0]),
|
|
66
|
+
r((1 - p) * c1[1] + p * c2[1]),
|
|
67
|
+
r((1 - p) * c1[2] + p * c2[2]),
|
|
68
|
+
(1 - p) * c1[3] + p * c2[3],
|
|
69
|
+
];
|
|
70
|
+
if (format === 'hex') {
|
|
71
|
+
const hex = [
|
|
72
|
+
result[0].toString(16).padStart(2, '0'),
|
|
73
|
+
result[1].toString(16).padStart(2, '0'),
|
|
74
|
+
result[2].toString(16).padStart(2, '0'),
|
|
75
|
+
result[3] === 0
|
|
76
|
+
? '00'
|
|
77
|
+
: r(result[3] * 255)
|
|
78
|
+
.toString(16)
|
|
79
|
+
.padStart(2, '0'),
|
|
80
|
+
];
|
|
81
|
+
return `#${hex[0]}${hex[1]}${hex[2]}${hex[3]}`;
|
|
82
|
+
}
|
|
83
|
+
return `rgb(${result[0]} ${result[1]} ${result[2]} / ${result[3]})`;
|
|
84
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { CoreConst } from '../../constant';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @description 获取所有的访问数据键名称
|
|
5
|
+
* @returns {string[]} 包含所有访问数据键名称的数组,如果出现错误则返回空数组
|
|
6
|
+
*/
|
|
7
|
+
function getAccessStoreAreakeys(): string[] {
|
|
8
|
+
try {
|
|
9
|
+
const key = CoreConst.ACCESS_STORE_AREA_KEYS;
|
|
10
|
+
let cookieAlls;
|
|
11
|
+
switch (ibiz.env.accessStoreArea) {
|
|
12
|
+
case 'LOCALSTORAGE':
|
|
13
|
+
cookieAlls = localStorage.getItem(key);
|
|
14
|
+
break;
|
|
15
|
+
case 'SESSIONSTORAGE':
|
|
16
|
+
cookieAlls = sessionStorage.getItem(key);
|
|
17
|
+
break;
|
|
18
|
+
default:
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
return JSON.parse(cookieAlls || '[]');
|
|
22
|
+
} catch (error) {
|
|
23
|
+
ibiz.log.error(error);
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @description 将新的访问数据键名称添加到已有的名称列表中
|
|
30
|
+
* @param {string} name 要添加的访问数据键名称
|
|
31
|
+
*/
|
|
32
|
+
function setAccessStoreAreakeys(name: string): void {
|
|
33
|
+
try {
|
|
34
|
+
const cookieAlls: string[] = [
|
|
35
|
+
...new Set(getAccessStoreAreakeys().concat([name])),
|
|
36
|
+
];
|
|
37
|
+
const key = CoreConst.ACCESS_STORE_AREA_KEYS;
|
|
38
|
+
switch (ibiz.env.accessStoreArea) {
|
|
39
|
+
case 'LOCALSTORAGE':
|
|
40
|
+
return localStorage.setItem(key, JSON.stringify(cookieAlls));
|
|
41
|
+
case 'SESSIONSTORAGE':
|
|
42
|
+
return sessionStorage.setItem(key, JSON.stringify(cookieAlls));
|
|
43
|
+
default:
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
} catch (error) {
|
|
47
|
+
ibiz.log.error(error);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @description 设置cookie
|
|
53
|
+
* @export
|
|
54
|
+
* @param {string} name cookie名称
|
|
55
|
+
* @param {string} value cookie值
|
|
56
|
+
* @param {number} [day=0] 过期天数
|
|
57
|
+
* @param {boolean} [isDomain=false] 是否设置在主域下
|
|
58
|
+
* @param {string} [path='/'] 默认归属路径
|
|
59
|
+
* @param {string} [childDoMain=''] 子域,如果外部有传递,则需把cookie数据设置到传入子域上
|
|
60
|
+
*/
|
|
61
|
+
export function setCookie(
|
|
62
|
+
name: string,
|
|
63
|
+
value: string,
|
|
64
|
+
day = 0,
|
|
65
|
+
isDomain = false,
|
|
66
|
+
path = '/',
|
|
67
|
+
childDoMain: string = '',
|
|
68
|
+
): void {
|
|
69
|
+
let domain = '';
|
|
70
|
+
setAccessStoreAreakeys(name);
|
|
71
|
+
switch (ibiz.env.accessStoreArea) {
|
|
72
|
+
case 'LOCALSTORAGE':
|
|
73
|
+
return localStorage.setItem(name, value);
|
|
74
|
+
case 'SESSIONSTORAGE':
|
|
75
|
+
return sessionStorage.setItem(name, value);
|
|
76
|
+
default:
|
|
77
|
+
// 设置cookie到主域下
|
|
78
|
+
if (isDomain) {
|
|
79
|
+
// 是否为ip正则
|
|
80
|
+
const regExpr =
|
|
81
|
+
/^(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)\.(25[0-5]|2[0-4]\d|[0-1]\d{2}|[1-9]?\d)$/;
|
|
82
|
+
// 为ip时忽略
|
|
83
|
+
if (!regExpr.test(window.location.hostname)) {
|
|
84
|
+
const host = window.location.hostname;
|
|
85
|
+
if (host.indexOf('.') !== host.lastIndexOf('.')) {
|
|
86
|
+
domain = `;domain=${host.substring(host.indexOf('.'), host.length)}`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
} else if (childDoMain) {
|
|
90
|
+
domain = `;domain=${childDoMain}`;
|
|
91
|
+
}
|
|
92
|
+
// 当设置的时间等于0时,不设置expires属性,cookie在浏览器关闭后删除
|
|
93
|
+
if (day !== 0) {
|
|
94
|
+
const expires = day * 24 * 60 * 60 * 1000;
|
|
95
|
+
const date = new Date(new Date().getTime() + expires);
|
|
96
|
+
document.cookie = `${name}=${escape(
|
|
97
|
+
value,
|
|
98
|
+
)};path=${path};expires=${date.toUTCString()}${domain}`;
|
|
99
|
+
} else {
|
|
100
|
+
document.cookie = `${name}=${escape(value)};path=${path}${domain}`;
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @description 设置应用cookie
|
|
108
|
+
* @export
|
|
109
|
+
* @param {string} name 名称
|
|
110
|
+
* @param {string} value 值
|
|
111
|
+
* @param {number} [day=0] 过期天数
|
|
112
|
+
*/
|
|
113
|
+
export function setAppCookie(
|
|
114
|
+
name: string,
|
|
115
|
+
value: string,
|
|
116
|
+
day: number = 0,
|
|
117
|
+
): void {
|
|
118
|
+
if (
|
|
119
|
+
ibiz.env.cookieDomain &&
|
|
120
|
+
window.location.href.indexOf(ibiz.env.cookieDomain) !== -1
|
|
121
|
+
) {
|
|
122
|
+
setCookie(name, value, day, false, '/', ibiz.env.cookieDomain);
|
|
123
|
+
} else {
|
|
124
|
+
setCookie(name, value, day, true);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @description 清除应用cookie
|
|
130
|
+
* @export
|
|
131
|
+
* @param {string} cookieName
|
|
132
|
+
*/
|
|
133
|
+
export function clearAppCookie(cookieName: string): void {
|
|
134
|
+
if (
|
|
135
|
+
ibiz.env.cookieDomain &&
|
|
136
|
+
window.location.href.indexOf(ibiz.env.cookieDomain) !== -1
|
|
137
|
+
) {
|
|
138
|
+
setCookie(cookieName, '', -1, false, '/', ibiz.env.cookieDomain);
|
|
139
|
+
} else {
|
|
140
|
+
setCookie(cookieName, '', -1, true);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @description 获取cookie
|
|
145
|
+
* @export
|
|
146
|
+
* @param {string} name
|
|
147
|
+
* @returns {*} {(string | null)}
|
|
148
|
+
*/
|
|
149
|
+
export function getAppCookie(name: string): string | null {
|
|
150
|
+
const reg = new RegExp(`(^| )${name}=([^;]*)(;|$)`);
|
|
151
|
+
const arr = document.cookie.match(reg);
|
|
152
|
+
switch (ibiz.env.accessStoreArea) {
|
|
153
|
+
case 'LOCALSTORAGE':
|
|
154
|
+
return localStorage.getItem(name);
|
|
155
|
+
case 'SESSIONSTORAGE':
|
|
156
|
+
return sessionStorage.getItem(name);
|
|
157
|
+
default:
|
|
158
|
+
if (arr && arr.length > 1) {
|
|
159
|
+
return unescape(arr[2]);
|
|
160
|
+
}
|
|
161
|
+
return null;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @description 重置应用cookie
|
|
167
|
+
* @export
|
|
168
|
+
*/
|
|
169
|
+
export function resetAppCookie(): void {
|
|
170
|
+
const cookies = document.cookie.split(';');
|
|
171
|
+
const cookieAlls = getAccessStoreAreakeys().concat([
|
|
172
|
+
CoreConst.ACCESS_STORE_AREA_KEYS,
|
|
173
|
+
]);
|
|
174
|
+
switch (ibiz.env.accessStoreArea) {
|
|
175
|
+
case 'LOCALSTORAGE':
|
|
176
|
+
for (const name of cookieAlls) {
|
|
177
|
+
localStorage.removeItem(name);
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
case 'SESSIONSTORAGE':
|
|
181
|
+
for (const name of cookieAlls) {
|
|
182
|
+
sessionStorage.removeItem(name);
|
|
183
|
+
}
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
for (const cookie of cookies) {
|
|
187
|
+
const [cookieName, cookieValue] = cookie.split('=');
|
|
188
|
+
document.cookie = `${cookieName}=${cookieValue};expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/;domain=${window.location.host}`;
|
|
189
|
+
}
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
}
|