@ibiz-template/core 0.0.1-alpha.5 → 0.0.1-beta.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/dist/system/index.system.js +1 -0
- package/out/constant/http-status-message/http-status-message.d.ts +5 -0
- package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
- package/out/constant/http-status-message/http-status-message.js +20 -0
- package/out/constant/index.d.ts +4 -0
- package/out/constant/index.d.ts.map +1 -1
- package/out/constant/index.js +4 -0
- package/out/constant/login-mode/login-mode.d.ts +23 -0
- package/out/constant/login-mode/login-mode.d.ts.map +1 -0
- package/out/constant/login-mode/login-mode.js +24 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
- package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
- package/out/constant/util/util.d.ts +5 -0
- package/out/constant/util/util.d.ts.map +1 -0
- package/out/constant/util/util.js +5 -0
- package/out/context/index.d.ts +2 -39
- package/out/context/index.d.ts.map +1 -1
- package/out/context/index.js +33 -64
- package/out/environment/environment.d.ts.map +1 -1
- package/out/environment/environment.js +11 -2
- package/out/error/http-error/http-error.d.ts.map +1 -1
- package/out/error/http-error/http-error.js +7 -0
- package/out/factory-center.d.ts +11 -0
- package/out/factory-center.d.ts.map +1 -0
- package/out/factory-center.js +10 -0
- package/out/ibizsys.d.ts +8 -1
- package/out/ibizsys.d.ts.map +1 -1
- package/out/ibizsys.js +8 -1
- package/out/index.d.ts +2 -1
- package/out/index.d.ts.map +1 -1
- package/out/index.js +2 -1
- package/out/install.d.ts.map +1 -1
- package/out/install.js +4 -2
- package/out/interface/click-outside/click-outside.d.ts +70 -0
- package/out/interface/click-outside/click-outside.d.ts.map +1 -0
- package/out/interface/click-outside/click-outside.js +1 -0
- package/out/interface/i-environment/i-environment.d.ts +72 -4
- package/out/interface/i-environment/i-environment.d.ts.map +1 -1
- package/out/interface/index.d.ts +1 -0
- package/out/interface/index.d.ts.map +1 -1
- package/out/interface/index.js +1 -1
- package/out/types.d.ts +10 -0
- package/out/types.d.ts.map +1 -1
- package/out/utils/click-outside/click-outside.d.ts +14 -0
- package/out/utils/click-outside/click-outside.d.ts.map +1 -0
- package/out/utils/click-outside/click-outside.js +85 -0
- package/out/utils/color/color.d.ts +13 -0
- package/out/utils/color/color.d.ts.map +1 -0
- package/out/utils/color/color.js +76 -0
- package/out/utils/download-file/download-file.d.ts +21 -0
- package/out/utils/download-file/download-file.d.ts.map +1 -0
- package/out/utils/download-file/download-file.js +87 -0
- package/out/utils/event/event.d.ts +34 -0
- package/out/utils/event/event.d.ts.map +1 -0
- package/out/utils/event/event.js +60 -0
- package/out/utils/index.d.ts +7 -1
- package/out/utils/index.d.ts.map +1 -1
- package/out/utils/index.js +7 -1
- package/out/utils/interceptor/core-interceptor.d.ts +15 -0
- package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
- package/out/utils/interceptor/core-interceptor.js +30 -0
- package/out/utils/interceptor/index.d.ts +3 -0
- package/out/utils/interceptor/index.d.ts.map +1 -0
- package/out/utils/interceptor/index.js +2 -0
- package/out/utils/interceptor/interceptor.d.ts +74 -3
- package/out/utils/interceptor/interceptor.d.ts.map +1 -1
- package/out/utils/interceptor/interceptor.js +73 -22
- package/out/utils/logger/logger.d.ts +3 -0
- package/out/utils/logger/logger.d.ts.map +1 -0
- package/out/utils/logger/logger.js +2 -0
- package/out/utils/net/http-response.d.ts +4 -9
- package/out/utils/net/http-response.d.ts.map +1 -1
- package/out/utils/net/http-response.js +0 -7
- package/out/utils/net/net.d.ts +82 -31
- package/out/utils/net/net.d.ts.map +1 -1
- package/out/utils/net/net.js +109 -40
- package/out/utils/url-helper/url-helper.d.ts +51 -0
- package/out/utils/url-helper/url-helper.d.ts.map +1 -0
- package/out/utils/url-helper/url-helper.js +59 -0
- package/out/utils/util/util.d.ts +20 -4
- package/out/utils/util/util.d.ts.map +1 -1
- package/out/utils/util/util.js +59 -5
- package/package.json +21 -9
- package/src/constant/http-status-message/http-status-message.ts +20 -0
- package/src/constant/index.ts +4 -0
- package/src/constant/login-mode/login-mode.ts +23 -0
- package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
- package/src/constant/util/util.ts +5 -0
- package/src/context/index.ts +34 -68
- package/src/environment/environment.ts +11 -2
- package/src/error/http-error/http-error.ts +7 -0
- package/src/factory-center.ts +9 -0
- package/src/ibizsys.ts +9 -1
- package/src/index.ts +2 -1
- package/src/install.ts +4 -2
- package/src/interface/click-outside/click-outside.ts +71 -0
- package/src/interface/i-environment/i-environment.ts +81 -4
- package/src/interface/index.ts +1 -0
- package/src/types.ts +10 -0
- package/src/utils/click-outside/click-outside.ts +110 -0
- package/src/utils/color/color.ts +84 -0
- package/src/utils/download-file/download-file.ts +88 -0
- package/src/utils/event/event.ts +77 -0
- package/src/utils/index.ts +7 -1
- package/src/utils/interceptor/core-interceptor.ts +35 -0
- package/src/utils/interceptor/index.ts +2 -0
- package/src/utils/interceptor/interceptor.ts +109 -22
- package/src/utils/logger/logger.ts +3 -0
- package/src/utils/net/http-response.ts +6 -9
- package/src/utils/net/net.ts +144 -51
- package/src/utils/url-helper/url-helper.ts +62 -0
- package/src/utils/util/util.ts +72 -14
package/src/context/index.ts
CHANGED
|
@@ -1,36 +1,3 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
/* eslint-disable no-constructor-return */
|
|
3
|
-
/* eslint-disable no-underscore-dangle */
|
|
4
|
-
/* eslint-disable max-classes-per-file */
|
|
5
|
-
/**
|
|
6
|
-
* 上下文代理处理
|
|
7
|
-
*
|
|
8
|
-
* @author chitanda
|
|
9
|
-
* @date 2022-07-14 10:07:45
|
|
10
|
-
* @class IBizContextProxyHandle
|
|
11
|
-
* @implements {ProxyHandler<IBizContext>}
|
|
12
|
-
*/
|
|
13
|
-
export class IBizContextProxyHandle implements ProxyHandler<IBizContext> {
|
|
14
|
-
set(target: IBizContext, p: string | symbol, value: unknown): boolean {
|
|
15
|
-
target.context[p] = value;
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
get(target: IBizContext, p: string | symbol, _receiver: unknown): unknown {
|
|
20
|
-
if (target[p] !== undefined) {
|
|
21
|
-
return target[p];
|
|
22
|
-
}
|
|
23
|
-
if (target.context[p] !== undefined) {
|
|
24
|
-
return target.context[p];
|
|
25
|
-
}
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
27
|
-
if ((target as any)._parent && (target as any)._parent[p] !== undefined) {
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
-
return (target as any)._parent[p];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
1
|
/**
|
|
35
2
|
* 上下文处理类
|
|
36
3
|
*
|
|
@@ -43,15 +10,7 @@ export class IBizContext implements IContext {
|
|
|
43
10
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
11
|
[key: string | symbol]: any;
|
|
45
12
|
|
|
46
|
-
|
|
47
|
-
* 父上下文
|
|
48
|
-
*
|
|
49
|
-
* @author chitanda
|
|
50
|
-
* @date 2022-07-14 10:07:06
|
|
51
|
-
* @protected
|
|
52
|
-
* @type {(IBizContext | null)}
|
|
53
|
-
*/
|
|
54
|
-
protected _parent: IContext | null = null;
|
|
13
|
+
protected _context!: IContext;
|
|
55
14
|
|
|
56
15
|
/**
|
|
57
16
|
* Creates an instance of IBizContext.
|
|
@@ -61,33 +20,40 @@ export class IBizContext implements IContext {
|
|
|
61
20
|
* @param {IContext} [context={}] 自身的上下文
|
|
62
21
|
* @param {IBizContext} [parent]
|
|
63
22
|
*/
|
|
64
|
-
|
|
23
|
+
// eslint-disable-next-line default-param-last
|
|
24
|
+
constructor(context: IContext = {}, parent?: IBizContext) {
|
|
65
25
|
if (parent) {
|
|
66
|
-
|
|
26
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
27
|
+
const self = this;
|
|
28
|
+
// 定义私有变量,用于存储父已有上下文,方便覆盖
|
|
29
|
+
Object.defineProperty(this, '_context', {
|
|
30
|
+
enumerable: false,
|
|
31
|
+
value: {},
|
|
32
|
+
});
|
|
33
|
+
// 监控父上下文参数,自身不存在时从父取
|
|
34
|
+
const properties: { [key: string]: PropertyDescriptor } = {};
|
|
35
|
+
const keys = Object.keys(parent);
|
|
36
|
+
keys.forEach(key => {
|
|
37
|
+
properties[key] = {
|
|
38
|
+
enumerable: true,
|
|
39
|
+
set(val: unknown) {
|
|
40
|
+
if (val == null) {
|
|
41
|
+
self._context[key] = null;
|
|
42
|
+
} else {
|
|
43
|
+
self._context[key] = val;
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
get() {
|
|
47
|
+
if (self._context[key] !== undefined) {
|
|
48
|
+
return self._context[key];
|
|
49
|
+
}
|
|
50
|
+
return parent[key];
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperties(this, properties);
|
|
67
55
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 创建代理
|
|
73
|
-
*
|
|
74
|
-
* @author chitanda
|
|
75
|
-
* @date 2022-07-14 11:07:37
|
|
76
|
-
* @protected
|
|
77
|
-
* @return {*} {IBizContext}
|
|
78
|
-
*/
|
|
79
|
-
protected createProxy(): IBizContext {
|
|
80
|
-
return new Proxy(this, new IBizContextProxyHandle());
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* 销毁上下文,避免内存泄漏
|
|
85
|
-
*
|
|
86
|
-
* @author chitanda
|
|
87
|
-
* @date 2022-07-14 11:07:45
|
|
88
|
-
*/
|
|
89
|
-
destroy(): void {
|
|
90
|
-
this.context = {};
|
|
91
|
-
this._parent = null;
|
|
56
|
+
// 合并给入上下文
|
|
57
|
+
Object.assign(this, context);
|
|
92
58
|
}
|
|
93
59
|
}
|
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
import { LoginMode, MenuPermissionMode } from '../constant';
|
|
1
2
|
import { IEnvironment } from '../interface';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 环境变量
|
|
5
6
|
*/
|
|
6
7
|
export const Environment: IEnvironment = {
|
|
8
|
+
dev: false,
|
|
9
|
+
logLevel: 'ERROR',
|
|
10
|
+
jsCdn: 'https://cdn.jsdelivr.net',
|
|
7
11
|
baseUrl: '',
|
|
12
|
+
pluginBaseUrl: './plugins',
|
|
8
13
|
remoteModelUrl: '/remotemodel',
|
|
9
14
|
assetsUrl: './assets',
|
|
10
15
|
dcSystem: '',
|
|
11
|
-
|
|
12
|
-
|
|
16
|
+
downloadFileUrl: '/ibizutil/download',
|
|
17
|
+
uploadFileUrl: '/ibizutil/upload',
|
|
18
|
+
casLoginUrl: '',
|
|
19
|
+
loginMode: LoginMode.DEFAULT,
|
|
20
|
+
menuPermissionMode: MenuPermissionMode.MIXIN,
|
|
21
|
+
enablePermission: true,
|
|
13
22
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AxiosError, AxiosResponse } from 'axios';
|
|
2
|
+
import { HttpStatusMessageConst } from '../../constant';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* 请求异常
|
|
@@ -27,6 +28,12 @@ export class HttpError implements Error {
|
|
|
27
28
|
} else {
|
|
28
29
|
this.message = res.statusText;
|
|
29
30
|
}
|
|
31
|
+
if (!this.message) {
|
|
32
|
+
this.message = HttpStatusMessageConst[res.status];
|
|
33
|
+
}
|
|
34
|
+
if (!this.message) {
|
|
35
|
+
this.message = '网络异常,请稍后重试!';
|
|
36
|
+
}
|
|
30
37
|
this.status = res.status;
|
|
31
38
|
} else {
|
|
32
39
|
this.message = err.message;
|
package/src/ibizsys.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Environment } from './environment/environment';
|
|
2
2
|
import { OrgData } from './interface';
|
|
3
|
-
import { Net } from './utils';
|
|
3
|
+
import { Logger, Net } from './utils';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* 全局对象
|
|
@@ -19,6 +19,14 @@ export class IBizSys {
|
|
|
19
19
|
*/
|
|
20
20
|
env = Environment;
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 日志对象
|
|
24
|
+
*
|
|
25
|
+
* @author chitanda
|
|
26
|
+
* @date 2022-10-25 20:10:22
|
|
27
|
+
*/
|
|
28
|
+
log = Logger;
|
|
29
|
+
|
|
22
30
|
/**
|
|
23
31
|
* 网络请求工具类
|
|
24
32
|
*
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import './types';
|
|
2
2
|
|
|
3
3
|
export * from './constant';
|
|
4
|
-
export { IBizContext
|
|
4
|
+
export { IBizContext } from './context';
|
|
5
5
|
export { Environment } from './environment/environment';
|
|
6
6
|
export * from './error';
|
|
7
7
|
export * from './interface';
|
|
8
8
|
export * from './utils';
|
|
9
9
|
export { IBizSys } from './ibizsys';
|
|
10
|
+
export { FactoryCenter } from './factory-center';
|
|
10
11
|
export { install } from './install';
|
package/src/install.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { FactoryCenter } from './factory-center';
|
|
1
2
|
import { IBizSys } from './ibizsys';
|
|
2
|
-
import {
|
|
3
|
+
import { CoreInterceptor } from './utils';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* 初始化全局对象
|
|
@@ -13,5 +14,6 @@ export function install(): void {
|
|
|
13
14
|
throw new Error('ibiz 已经存在, 无需重复安装');
|
|
14
15
|
}
|
|
15
16
|
window.ibiz = new IBizSys();
|
|
16
|
-
new
|
|
17
|
+
window.___fc = new FactoryCenter();
|
|
18
|
+
ibiz.net.addInterceptor('CoreInterceptor', new CoreInterceptor());
|
|
17
19
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 可选配置参数
|
|
3
|
+
*
|
|
4
|
+
* @author lxm
|
|
5
|
+
* @date 2022-10-28 16:10:48
|
|
6
|
+
* @export
|
|
7
|
+
* @interface OnClickOutsideOptions
|
|
8
|
+
* @extends {ConfigurableWindow}
|
|
9
|
+
* @template E
|
|
10
|
+
*/
|
|
11
|
+
export interface OnClickOutsideOptions {
|
|
12
|
+
/**
|
|
13
|
+
* 指定使用的window,不给就用默认的window
|
|
14
|
+
* 一般是在iframe或测试环境中使用。
|
|
15
|
+
*
|
|
16
|
+
* @author lxm
|
|
17
|
+
* @date 2022-10-28 17:10:49
|
|
18
|
+
* @type {Window}
|
|
19
|
+
*/
|
|
20
|
+
window?: Window;
|
|
21
|
+
/**
|
|
22
|
+
* 指定需要忽略的元素,用于排除某些外部的元素
|
|
23
|
+
*
|
|
24
|
+
* @author lxm
|
|
25
|
+
* @date 2022-10-28 17:10:50
|
|
26
|
+
* @type {HTMLElement[]}
|
|
27
|
+
*/
|
|
28
|
+
ignore?: HTMLElement[];
|
|
29
|
+
/**
|
|
30
|
+
* 是否捕获内部元素。默认为是,内部元素不会触发回调。
|
|
31
|
+
* @default true
|
|
32
|
+
*/
|
|
33
|
+
capture?: boolean;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 回调处理函数类型
|
|
38
|
+
*/
|
|
39
|
+
export type OnClickOutsideHandler = (_evt: PointerEvent | MouseEvent) => void;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* OnClickOutside返回对象类型
|
|
43
|
+
*
|
|
44
|
+
* @author lxm
|
|
45
|
+
* @date 2022-10-31 11:10:59
|
|
46
|
+
* @export
|
|
47
|
+
* @interface OnClickOutsideResult
|
|
48
|
+
*/
|
|
49
|
+
export interface OnClickOutsideResult {
|
|
50
|
+
/**
|
|
51
|
+
* 停止监听,并移除相关监听事件
|
|
52
|
+
*
|
|
53
|
+
* @author lxm
|
|
54
|
+
* @date 2022-10-31 11:10:28
|
|
55
|
+
*/
|
|
56
|
+
stop: () => void;
|
|
57
|
+
/**
|
|
58
|
+
* 暂停监听
|
|
59
|
+
*
|
|
60
|
+
* @author lxm
|
|
61
|
+
* @date 2022-10-31 11:10:30
|
|
62
|
+
*/
|
|
63
|
+
pause: () => void;
|
|
64
|
+
/**
|
|
65
|
+
* 继续监听
|
|
66
|
+
*
|
|
67
|
+
* @author lxm
|
|
68
|
+
* @date 2022-10-31 11:10:32
|
|
69
|
+
*/
|
|
70
|
+
proceed: () => void;
|
|
71
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { LogLevelDesc } from 'loglevel';
|
|
2
|
+
import { LoginMode, MenuPermissionMode } from '../../constant';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* 配置参数
|
|
3
6
|
*
|
|
@@ -16,6 +19,35 @@ export interface IEnvironment {
|
|
|
16
19
|
*/
|
|
17
20
|
namespace?: string;
|
|
18
21
|
|
|
22
|
+
/**
|
|
23
|
+
* 是否为开发模式
|
|
24
|
+
*
|
|
25
|
+
* @default false
|
|
26
|
+
* @author chitanda
|
|
27
|
+
* @date 2022-10-21 11:10:29
|
|
28
|
+
* @type {boolean}
|
|
29
|
+
*/
|
|
30
|
+
dev: boolean;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 日志级别
|
|
34
|
+
*
|
|
35
|
+
* @author chitanda
|
|
36
|
+
* @date 2022-10-25 20:10:55
|
|
37
|
+
* @type {LogLevelDesc}
|
|
38
|
+
*/
|
|
39
|
+
logLevel: LogLevelDesc;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* js 静态文件 cdn 地址
|
|
43
|
+
*
|
|
44
|
+
* @default https://cdn.jsdelivr.net/
|
|
45
|
+
* @author chitanda
|
|
46
|
+
* @date 2022-10-24 11:10:14
|
|
47
|
+
* @type {string}
|
|
48
|
+
*/
|
|
49
|
+
jsCdn: string;
|
|
50
|
+
|
|
19
51
|
/**
|
|
20
52
|
* 请求根路径
|
|
21
53
|
*
|
|
@@ -25,6 +57,33 @@ export interface IEnvironment {
|
|
|
25
57
|
*/
|
|
26
58
|
baseUrl: string;
|
|
27
59
|
|
|
60
|
+
/**
|
|
61
|
+
* 插件默认所在目录
|
|
62
|
+
*
|
|
63
|
+
* @author chitanda
|
|
64
|
+
* @date 2022-10-31 14:10:49
|
|
65
|
+
* @type {string}
|
|
66
|
+
*/
|
|
67
|
+
pluginBaseUrl: string;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* 登录模式
|
|
71
|
+
*
|
|
72
|
+
* @author lxm
|
|
73
|
+
* @date 2022-10-12 14:10:51
|
|
74
|
+
* @type {LoginMode}
|
|
75
|
+
*/
|
|
76
|
+
loginMode: LoginMode;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 中央认证登录地址
|
|
80
|
+
*
|
|
81
|
+
* @author lxm
|
|
82
|
+
* @date 2022-10-11 12:10:21
|
|
83
|
+
* @type {string}
|
|
84
|
+
*/
|
|
85
|
+
casLoginUrl: string;
|
|
86
|
+
|
|
28
87
|
/**
|
|
29
88
|
* 远程模型路径
|
|
30
89
|
*
|
|
@@ -53,20 +112,38 @@ export interface IEnvironment {
|
|
|
53
112
|
dcSystem: string;
|
|
54
113
|
|
|
55
114
|
/**
|
|
56
|
-
*
|
|
115
|
+
* 文件下载url
|
|
57
116
|
*
|
|
58
117
|
* @author chitanda
|
|
59
118
|
* @date 2022-08-22 23:08:46
|
|
60
119
|
* @type {string}
|
|
61
120
|
*/
|
|
62
|
-
|
|
121
|
+
downloadFileUrl: string;
|
|
63
122
|
|
|
64
123
|
/**
|
|
65
|
-
* 文件上传
|
|
124
|
+
* 文件上传url
|
|
66
125
|
*
|
|
67
126
|
* @author chitanda
|
|
68
127
|
* @date 2022-08-22 23:08:46
|
|
69
128
|
* @type {string}
|
|
70
129
|
*/
|
|
71
|
-
|
|
130
|
+
uploadFileUrl: string;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* 是否启用权限校验(默认true)
|
|
134
|
+
*
|
|
135
|
+
* @author lxm
|
|
136
|
+
* @date 2022-10-12 18:10:25
|
|
137
|
+
* @type {boolean}
|
|
138
|
+
*/
|
|
139
|
+
enablePermission: boolean;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 菜单权限校验模式(默认MIXIN)
|
|
143
|
+
*
|
|
144
|
+
* @author lxm
|
|
145
|
+
* @date 2022-10-12 18:10:27
|
|
146
|
+
* @type {MenuPermissionMode}
|
|
147
|
+
*/
|
|
148
|
+
menuPermissionMode: MenuPermissionMode;
|
|
72
149
|
}
|
package/src/interface/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,11 +1,21 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import { FactoryCenter } from './factory-center';
|
|
2
3
|
import { IBizSys } from './ibizsys';
|
|
3
4
|
|
|
4
5
|
declare global {
|
|
5
6
|
const ibiz: IBizSys;
|
|
7
|
+
const ___fc: FactoryCenter;
|
|
6
8
|
|
|
7
9
|
interface Window {
|
|
8
10
|
ibiz: IBizSys;
|
|
11
|
+
/**
|
|
12
|
+
* 全局工厂中心
|
|
13
|
+
*
|
|
14
|
+
* @author lxm
|
|
15
|
+
* @date 2022-10-17 15:10:43
|
|
16
|
+
* @type {FactoryCenter}
|
|
17
|
+
*/
|
|
18
|
+
___fc: FactoryCenter;
|
|
9
19
|
}
|
|
10
20
|
|
|
11
21
|
/**
|
|
@@ -0,0 +1,110 @@
|
|
|
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) => {
|
|
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 = () => {
|
|
50
|
+
isPaused = true;
|
|
51
|
+
};
|
|
52
|
+
const proceed = () => {
|
|
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) => {
|
|
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 = () => path;
|
|
98
|
+
fallback = window.setTimeout(() => listener(e), 50);
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{ passive: true },
|
|
102
|
+
),
|
|
103
|
+
].filter(Boolean);
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* 停止事件监听,移除监听
|
|
107
|
+
*/
|
|
108
|
+
const stop = () => cleanups.forEach(fn => fn());
|
|
109
|
+
return { stop, pause, proceed };
|
|
110
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|