@ibiz-template/core 0.0.1-alpha.6 → 0.0.1-beta.17

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.
Files changed (165) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/command/command-register.d.ts +66 -0
  3. package/out/command/command-register.d.ts.map +1 -0
  4. package/out/command/command-register.js +113 -0
  5. package/out/command/command.d.ts +54 -0
  6. package/out/command/command.d.ts.map +1 -0
  7. package/out/command/command.js +71 -0
  8. package/out/command/index.d.ts +10 -0
  9. package/out/command/index.d.ts.map +1 -0
  10. package/out/command/index.js +9 -0
  11. package/out/command/interface/command/command-option.d.ts +23 -0
  12. package/out/command/interface/command/command-option.d.ts.map +1 -0
  13. package/out/command/interface/command/command-option.js +1 -0
  14. package/out/command/interface/command/command.d.ts +74 -0
  15. package/out/command/interface/command/command.d.ts.map +1 -0
  16. package/out/command/interface/command/command.js +1 -0
  17. package/out/command/interface/disposable/disposable.d.ts +4 -0
  18. package/out/command/interface/disposable/disposable.d.ts.map +1 -0
  19. package/out/command/interface/disposable/disposable.js +1 -0
  20. package/out/command/interface/index.d.ts +4 -0
  21. package/out/command/interface/index.d.ts.map +1 -0
  22. package/out/command/interface/index.js +1 -0
  23. package/out/command/utils/index.d.ts +3 -0
  24. package/out/command/utils/index.d.ts.map +1 -0
  25. package/out/command/utils/index.js +2 -0
  26. package/out/command/utils/linked-list.d.ts +16 -0
  27. package/out/command/utils/linked-list.d.ts.map +1 -0
  28. package/out/command/utils/linked-list.js +120 -0
  29. package/out/command/utils/util.d.ts +27 -0
  30. package/out/command/utils/util.d.ts.map +1 -0
  31. package/out/command/utils/util.js +77 -0
  32. package/out/constant/index.d.ts +3 -0
  33. package/out/constant/index.d.ts.map +1 -1
  34. package/out/constant/index.js +3 -0
  35. package/out/constant/login-mode/login-mode.d.ts +23 -0
  36. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  37. package/out/constant/login-mode/login-mode.js +24 -0
  38. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  39. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  40. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  41. package/out/constant/util/util.d.ts +5 -0
  42. package/out/constant/util/util.d.ts.map +1 -0
  43. package/out/constant/util/util.js +5 -0
  44. package/out/context/index.d.ts +19 -32
  45. package/out/context/index.d.ts.map +1 -1
  46. package/out/context/index.js +52 -60
  47. package/out/environment/environment.d.ts.map +1 -1
  48. package/out/environment/environment.js +11 -2
  49. package/out/error/http-error/http-error.d.ts.map +1 -1
  50. package/out/error/http-error/http-error.js +0 -4
  51. package/out/factory-center.d.ts +11 -0
  52. package/out/factory-center.d.ts.map +1 -0
  53. package/out/factory-center.js +10 -0
  54. package/out/ibizsys.d.ts +17 -1
  55. package/out/ibizsys.d.ts.map +1 -1
  56. package/out/ibizsys.js +17 -1
  57. package/out/index.d.ts +3 -1
  58. package/out/index.d.ts.map +1 -1
  59. package/out/index.js +3 -1
  60. package/out/install.d.ts.map +1 -1
  61. package/out/install.js +4 -2
  62. package/out/interface/click-outside/click-outside.d.ts +70 -0
  63. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  64. package/out/interface/click-outside/click-outside.js +1 -0
  65. package/out/interface/i-environment/i-environment.d.ts +72 -4
  66. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  67. package/out/interface/index.d.ts +1 -0
  68. package/out/interface/index.d.ts.map +1 -1
  69. package/out/interface/index.js +1 -1
  70. package/out/types.d.ts +10 -0
  71. package/out/types.d.ts.map +1 -1
  72. package/out/utils/click-outside/click-outside.d.ts +14 -0
  73. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  74. package/out/utils/click-outside/click-outside.js +85 -0
  75. package/out/utils/color/color.d.ts +13 -0
  76. package/out/utils/color/color.d.ts.map +1 -0
  77. package/out/utils/color/color.js +76 -0
  78. package/out/utils/download-file/download-file.d.ts +31 -0
  79. package/out/utils/download-file/download-file.d.ts.map +1 -0
  80. package/out/utils/download-file/download-file.js +107 -0
  81. package/out/utils/event/event.d.ts +34 -0
  82. package/out/utils/event/event.d.ts.map +1 -0
  83. package/out/utils/event/event.js +60 -0
  84. package/out/utils/index.d.ts +10 -1
  85. package/out/utils/index.d.ts.map +1 -1
  86. package/out/utils/index.js +10 -1
  87. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  88. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  89. package/out/utils/interceptor/core-interceptor.js +30 -0
  90. package/out/utils/interceptor/index.d.ts +3 -0
  91. package/out/utils/interceptor/index.d.ts.map +1 -0
  92. package/out/utils/interceptor/index.js +2 -0
  93. package/out/utils/interceptor/interceptor.d.ts +74 -3
  94. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  95. package/out/utils/interceptor/interceptor.js +73 -22
  96. package/out/utils/logger/logger.d.ts +3 -0
  97. package/out/utils/logger/logger.d.ts.map +1 -0
  98. package/out/utils/logger/logger.js +2 -0
  99. package/out/utils/net/http-response.d.ts +4 -9
  100. package/out/utils/net/http-response.d.ts.map +1 -1
  101. package/out/utils/net/http-response.js +0 -7
  102. package/out/utils/net/net.d.ts +82 -31
  103. package/out/utils/net/net.d.ts.map +1 -1
  104. package/out/utils/net/net.js +109 -40
  105. package/out/utils/sync/count-latch.d.ts +60 -0
  106. package/out/utils/sync/count-latch.d.ts.map +1 -0
  107. package/out/utils/sync/count-latch.js +93 -0
  108. package/out/utils/sync/index.d.ts +2 -0
  109. package/out/utils/sync/index.d.ts.map +1 -0
  110. package/out/utils/sync/index.js +1 -0
  111. package/out/utils/upload/select-file.d.ts +53 -0
  112. package/out/utils/upload/select-file.d.ts.map +1 -0
  113. package/out/utils/upload/select-file.js +47 -0
  114. package/out/utils/upload/upload-file.d.ts +46 -0
  115. package/out/utils/upload/upload-file.d.ts.map +1 -0
  116. package/out/utils/upload/upload-file.js +150 -0
  117. package/out/utils/url-helper/url-helper.d.ts +51 -0
  118. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  119. package/out/utils/url-helper/url-helper.js +59 -0
  120. package/out/utils/util/util.d.ts +20 -4
  121. package/out/utils/util/util.d.ts.map +1 -1
  122. package/out/utils/util/util.js +59 -5
  123. package/package.json +19 -9
  124. package/src/command/command-register.ts +135 -0
  125. package/src/command/command.ts +79 -0
  126. package/src/command/index.ts +11 -0
  127. package/src/command/interface/command/command-option.ts +22 -0
  128. package/src/command/interface/command/command.ts +86 -0
  129. package/src/command/interface/disposable/disposable.ts +3 -0
  130. package/src/command/interface/index.ts +9 -0
  131. package/src/command/utils/index.ts +2 -0
  132. package/src/command/utils/linked-list.ts +136 -0
  133. package/src/command/utils/util.ts +95 -0
  134. package/src/constant/index.ts +3 -0
  135. package/src/constant/login-mode/login-mode.ts +23 -0
  136. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  137. package/src/constant/util/util.ts +5 -0
  138. package/src/context/index.ts +69 -59
  139. package/src/environment/environment.ts +11 -2
  140. package/src/error/http-error/http-error.ts +0 -4
  141. package/src/factory-center.ts +9 -0
  142. package/src/ibizsys.ts +19 -1
  143. package/src/index.ts +3 -1
  144. package/src/install.ts +4 -2
  145. package/src/interface/click-outside/click-outside.ts +71 -0
  146. package/src/interface/i-environment/i-environment.ts +81 -4
  147. package/src/interface/index.ts +1 -0
  148. package/src/types.ts +10 -0
  149. package/src/utils/click-outside/click-outside.ts +110 -0
  150. package/src/utils/color/color.ts +84 -0
  151. package/src/utils/download-file/download-file.ts +109 -0
  152. package/src/utils/event/event.ts +77 -0
  153. package/src/utils/index.ts +10 -1
  154. package/src/utils/interceptor/core-interceptor.ts +35 -0
  155. package/src/utils/interceptor/index.ts +2 -0
  156. package/src/utils/interceptor/interceptor.ts +109 -22
  157. package/src/utils/logger/logger.ts +3 -0
  158. package/src/utils/net/http-response.ts +6 -9
  159. package/src/utils/net/net.ts +144 -51
  160. package/src/utils/sync/count-latch.ts +99 -0
  161. package/src/utils/sync/index.ts +1 -0
  162. package/src/utils/upload/select-file.ts +86 -0
  163. package/src/utils/upload/upload-file.ts +206 -0
  164. package/src/utils/url-helper/url-helper.ts +62 -0
  165. package/src/utils/util/util.ts +72 -14
@@ -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
  *
@@ -44,14 +11,23 @@ export class IBizContext implements IContext {
44
11
  [key: string | symbol]: any;
45
12
 
46
13
  /**
47
- * 父上下文
14
+ * 修改的父上下文
48
15
  *
49
- * @author chitanda
50
- * @date 2022-07-14 10:07:06
16
+ * @author lxm
17
+ * @date 2022-12-08 18:12:16
51
18
  * @protected
52
- * @type {(IBizContext | null)}
19
+ * @type {IContext}
53
20
  */
54
- protected _parent: IContext | null = null;
21
+ protected _context!: IContext;
22
+
23
+ /**
24
+ * 父的上下文源对象
25
+ *
26
+ * @author lxm
27
+ * @date 2022-12-08 18:12:31
28
+ * @type {IBizContext}
29
+ */
30
+ declare _parent?: IBizContext;
55
31
 
56
32
  /**
57
33
  * Creates an instance of IBizContext.
@@ -61,33 +37,67 @@ export class IBizContext implements IContext {
61
37
  * @param {IContext} [context={}] 自身的上下文
62
38
  * @param {IBizContext} [parent]
63
39
  */
64
- constructor(public context: IContext = {}, parent?: IContext) {
40
+ // eslint-disable-next-line default-param-last
41
+ constructor(context: IContext = {}, parent?: IBizContext) {
65
42
  if (parent) {
66
- this._parent = parent;
67
- }
68
- return this.createProxy();
69
- }
43
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
44
+ const self = this;
45
+ // 定义私有变量,存放父上下文源对象
46
+ Object.defineProperty(this, '_parent', {
47
+ enumerable: false,
48
+ value: parent,
49
+ });
70
50
 
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());
51
+ // 定义私有变量,用于存储对父已有上下文的修改。
52
+ Object.defineProperty(this, '_context', {
53
+ enumerable: false,
54
+ value: {},
55
+ });
56
+ // 监控父上下文参数,自身不存在时从父取
57
+ const properties: { [key: string]: PropertyDescriptor } = {};
58
+ const keys = Object.keys(parent);
59
+ keys.forEach(key => {
60
+ properties[key] = {
61
+ enumerable: true,
62
+ set(val: unknown) {
63
+ if (val == null) {
64
+ self._context[key] = null;
65
+ } else {
66
+ self._context[key] = val;
67
+ }
68
+ },
69
+ get() {
70
+ if (self._context[key] !== undefined) {
71
+ return self._context[key];
72
+ }
73
+ return parent[key];
74
+ },
75
+ };
76
+ });
77
+ Object.defineProperties(this, properties);
78
+ }
79
+ // 合并给入上下文
80
+ Object.assign(this, context);
81
81
  }
82
82
 
83
83
  /**
84
- * 销毁上下文,避免内存泄漏
84
+ * 返回自身的上下文,独有的和与父有差异的。
85
85
  *
86
- * @author chitanda
87
- * @date 2022-07-14 11:07:45
86
+ * @author lxm
87
+ * @date 2022-12-08 17:12:26
88
+ * @returns {*} {IContext}
88
89
  */
89
- destroy(): void {
90
- this.context = {};
91
- this._parent = null;
90
+ getOwnContext(): IContext {
91
+ const result: IContext = {};
92
+ Object.keys(this).forEach(key => {
93
+ // 父没有的,或者修改了父的上下文
94
+ if (
95
+ !Object.prototype.hasOwnProperty.call(this._parent, key) ||
96
+ Object.prototype.hasOwnProperty.call(this._context, key)
97
+ ) {
98
+ result[key] = this[key];
99
+ }
100
+ });
101
+ return result;
92
102
  }
93
103
  }
@@ -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
- ExportFile: '/ibizutil/download',
12
- UploadFile: '/ibizutil/upload',
16
+ downloadFileUrl: '/ibizutil/download',
17
+ uploadFileUrl: '/ibizutil/upload',
18
+ casLoginUrl: '',
19
+ loginMode: LoginMode.DEFAULT,
20
+ menuPermissionMode: MenuPermissionMode.MIXIN,
21
+ enablePermission: true,
13
22
  };
@@ -1,5 +1,4 @@
1
1
  import { AxiosError, AxiosResponse } from 'axios';
2
- import { HttpStatusMessageConst } from '../../constant';
3
2
 
4
3
  /**
5
4
  * 请求异常
@@ -28,9 +27,6 @@ export class HttpError implements Error {
28
27
  } else {
29
28
  this.message = res.statusText;
30
29
  }
31
- if (!this.message) {
32
- this.message = HttpStatusMessageConst[res.status];
33
- }
34
30
  if (!this.message) {
35
31
  this.message = '网络异常,请稍后重试!';
36
32
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 工厂类挂载中心,挂载各种解耦用创建工厂
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-17 15:10:04
6
+ * @export
7
+ * @class FactoryCenter
8
+ */
9
+ export class FactoryCenter {}
package/src/ibizsys.ts CHANGED
@@ -1,6 +1,7 @@
1
+ import { CommandController } from './command';
1
2
  import { Environment } from './environment/environment';
2
3
  import { OrgData } from './interface';
3
- import { Net } from './utils';
4
+ import { Logger, Net } from './utils';
4
5
 
5
6
  /**
6
7
  * 全局对象
@@ -19,6 +20,14 @@ export class IBizSys {
19
20
  */
20
21
  env = Environment;
21
22
 
23
+ /**
24
+ * 日志对象
25
+ *
26
+ * @author chitanda
27
+ * @date 2022-10-25 20:10:22
28
+ */
29
+ log = Logger;
30
+
22
31
  /**
23
32
  * 网络请求工具类
24
33
  *
@@ -28,6 +37,15 @@ export class IBizSys {
28
37
  */
29
38
  net: Net = new Net();
30
39
 
40
+ /**
41
+ * 认证服务
42
+ *
43
+ * @author chitanda
44
+ * @date 2022-07-20 10:07:33
45
+ * @type {AuthService}
46
+ */
47
+ commands: CommandController = new CommandController();
48
+
31
49
  /**
32
50
  * sass 模式下的中心系统标识
33
51
  *
package/src/index.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import './types';
2
2
 
3
+ export * from './command';
3
4
  export * from './constant';
4
- export { IBizContext, IBizContextProxyHandle } from './context';
5
+ export { IBizContext } from './context';
5
6
  export { Environment } from './environment/environment';
6
7
  export * from './error';
7
8
  export * from './interface';
8
9
  export * from './utils';
9
10
  export { IBizSys } from './ibizsys';
11
+ export { FactoryCenter } from './factory-center';
10
12
  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 { Interceptor } from './utils';
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 Interceptor();
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
- ExportFile: string;
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
- UploadFile: string;
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
  }
@@ -1,2 +1,3 @@
1
1
  export { IEnvironment } from './i-environment/i-environment';
2
2
  export { OrgData } from './org-data/org-data';
3
+ export * from './click-outside/click-outside';
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
+ }