@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.
Files changed (113) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/constant/http-status-message/http-status-message.d.ts +5 -0
  3. package/out/constant/http-status-message/http-status-message.d.ts.map +1 -0
  4. package/out/constant/http-status-message/http-status-message.js +20 -0
  5. package/out/constant/index.d.ts +4 -0
  6. package/out/constant/index.d.ts.map +1 -1
  7. package/out/constant/index.js +4 -0
  8. package/out/constant/login-mode/login-mode.d.ts +23 -0
  9. package/out/constant/login-mode/login-mode.d.ts.map +1 -0
  10. package/out/constant/login-mode/login-mode.js +24 -0
  11. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts +23 -0
  12. package/out/constant/menu-permission-mode/menu-permission-mode.d.ts.map +1 -0
  13. package/out/constant/menu-permission-mode/menu-permission-mode.js +24 -0
  14. package/out/constant/util/util.d.ts +5 -0
  15. package/out/constant/util/util.d.ts.map +1 -0
  16. package/out/constant/util/util.js +5 -0
  17. package/out/context/index.d.ts +2 -39
  18. package/out/context/index.d.ts.map +1 -1
  19. package/out/context/index.js +33 -64
  20. package/out/environment/environment.d.ts.map +1 -1
  21. package/out/environment/environment.js +11 -2
  22. package/out/error/http-error/http-error.d.ts.map +1 -1
  23. package/out/error/http-error/http-error.js +7 -0
  24. package/out/factory-center.d.ts +11 -0
  25. package/out/factory-center.d.ts.map +1 -0
  26. package/out/factory-center.js +10 -0
  27. package/out/ibizsys.d.ts +8 -1
  28. package/out/ibizsys.d.ts.map +1 -1
  29. package/out/ibizsys.js +8 -1
  30. package/out/index.d.ts +2 -1
  31. package/out/index.d.ts.map +1 -1
  32. package/out/index.js +2 -1
  33. package/out/install.d.ts.map +1 -1
  34. package/out/install.js +4 -2
  35. package/out/interface/click-outside/click-outside.d.ts +70 -0
  36. package/out/interface/click-outside/click-outside.d.ts.map +1 -0
  37. package/out/interface/click-outside/click-outside.js +1 -0
  38. package/out/interface/i-environment/i-environment.d.ts +72 -4
  39. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  40. package/out/interface/index.d.ts +1 -0
  41. package/out/interface/index.d.ts.map +1 -1
  42. package/out/interface/index.js +1 -1
  43. package/out/types.d.ts +10 -0
  44. package/out/types.d.ts.map +1 -1
  45. package/out/utils/click-outside/click-outside.d.ts +14 -0
  46. package/out/utils/click-outside/click-outside.d.ts.map +1 -0
  47. package/out/utils/click-outside/click-outside.js +85 -0
  48. package/out/utils/color/color.d.ts +13 -0
  49. package/out/utils/color/color.d.ts.map +1 -0
  50. package/out/utils/color/color.js +76 -0
  51. package/out/utils/download-file/download-file.d.ts +21 -0
  52. package/out/utils/download-file/download-file.d.ts.map +1 -0
  53. package/out/utils/download-file/download-file.js +87 -0
  54. package/out/utils/event/event.d.ts +34 -0
  55. package/out/utils/event/event.d.ts.map +1 -0
  56. package/out/utils/event/event.js +60 -0
  57. package/out/utils/index.d.ts +7 -1
  58. package/out/utils/index.d.ts.map +1 -1
  59. package/out/utils/index.js +7 -1
  60. package/out/utils/interceptor/core-interceptor.d.ts +15 -0
  61. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -0
  62. package/out/utils/interceptor/core-interceptor.js +30 -0
  63. package/out/utils/interceptor/index.d.ts +3 -0
  64. package/out/utils/interceptor/index.d.ts.map +1 -0
  65. package/out/utils/interceptor/index.js +2 -0
  66. package/out/utils/interceptor/interceptor.d.ts +74 -3
  67. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  68. package/out/utils/interceptor/interceptor.js +73 -22
  69. package/out/utils/logger/logger.d.ts +3 -0
  70. package/out/utils/logger/logger.d.ts.map +1 -0
  71. package/out/utils/logger/logger.js +2 -0
  72. package/out/utils/net/http-response.d.ts +4 -9
  73. package/out/utils/net/http-response.d.ts.map +1 -1
  74. package/out/utils/net/http-response.js +0 -7
  75. package/out/utils/net/net.d.ts +82 -31
  76. package/out/utils/net/net.d.ts.map +1 -1
  77. package/out/utils/net/net.js +109 -40
  78. package/out/utils/url-helper/url-helper.d.ts +51 -0
  79. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  80. package/out/utils/url-helper/url-helper.js +59 -0
  81. package/out/utils/util/util.d.ts +20 -4
  82. package/out/utils/util/util.d.ts.map +1 -1
  83. package/out/utils/util/util.js +59 -5
  84. package/package.json +21 -9
  85. package/src/constant/http-status-message/http-status-message.ts +20 -0
  86. package/src/constant/index.ts +4 -0
  87. package/src/constant/login-mode/login-mode.ts +23 -0
  88. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  89. package/src/constant/util/util.ts +5 -0
  90. package/src/context/index.ts +34 -68
  91. package/src/environment/environment.ts +11 -2
  92. package/src/error/http-error/http-error.ts +7 -0
  93. package/src/factory-center.ts +9 -0
  94. package/src/ibizsys.ts +9 -1
  95. package/src/index.ts +2 -1
  96. package/src/install.ts +4 -2
  97. package/src/interface/click-outside/click-outside.ts +71 -0
  98. package/src/interface/i-environment/i-environment.ts +81 -4
  99. package/src/interface/index.ts +1 -0
  100. package/src/types.ts +10 -0
  101. package/src/utils/click-outside/click-outside.ts +110 -0
  102. package/src/utils/color/color.ts +84 -0
  103. package/src/utils/download-file/download-file.ts +88 -0
  104. package/src/utils/event/event.ts +77 -0
  105. package/src/utils/index.ts +7 -1
  106. package/src/utils/interceptor/core-interceptor.ts +35 -0
  107. package/src/utils/interceptor/index.ts +2 -0
  108. package/src/utils/interceptor/interceptor.ts +109 -22
  109. package/src/utils/logger/logger.ts +3 -0
  110. package/src/utils/net/http-response.ts +6 -9
  111. package/src/utils/net/net.ts +144 -51
  112. package/src/utils/url-helper/url-helper.ts +62 -0
  113. package/src/utils/util/util.ts +72 -14
@@ -0,0 +1,70 @@
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
+ export declare type OnClickOutsideHandler = (_evt: PointerEvent | MouseEvent) => void;
39
+ /**
40
+ * OnClickOutside返回对象类型
41
+ *
42
+ * @author lxm
43
+ * @date 2022-10-31 11:10:59
44
+ * @export
45
+ * @interface OnClickOutsideResult
46
+ */
47
+ export interface OnClickOutsideResult {
48
+ /**
49
+ * 停止监听,并移除相关监听事件
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-31 11:10:28
53
+ */
54
+ stop: () => void;
55
+ /**
56
+ * 暂停监听
57
+ *
58
+ * @author lxm
59
+ * @date 2022-10-31 11:10:30
60
+ */
61
+ pause: () => void;
62
+ /**
63
+ * 继续监听
64
+ *
65
+ * @author lxm
66
+ * @date 2022-10-31 11:10:32
67
+ */
68
+ proceed: () => void;
69
+ }
70
+ //# sourceMappingURL=click-outside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"click-outside.d.ts","sourceRoot":"","sources":["../../../src/interface/click-outside/click-outside.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,WAAW,qBAAqB;IACpC;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;IACvB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;GAEG;AACH,oBAAY,qBAAqB,GAAG,CAAC,IAAI,EAAE,YAAY,GAAG,UAAU,KAAK,IAAI,CAAC;AAE9E;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;OAKG;IACH,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB;;;;;OAKG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;;;OAKG;IACH,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB"}
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,5 @@
1
+ import { LogLevelDesc } from 'loglevel';
2
+ import { LoginMode, MenuPermissionMode } from '../../constant';
1
3
  /**
2
4
  * 配置参数
3
5
  *
@@ -15,6 +17,32 @@ export interface IEnvironment {
15
17
  * @type {string}
16
18
  */
17
19
  namespace?: string;
20
+ /**
21
+ * 是否为开发模式
22
+ *
23
+ * @default false
24
+ * @author chitanda
25
+ * @date 2022-10-21 11:10:29
26
+ * @type {boolean}
27
+ */
28
+ dev: boolean;
29
+ /**
30
+ * 日志级别
31
+ *
32
+ * @author chitanda
33
+ * @date 2022-10-25 20:10:55
34
+ * @type {LogLevelDesc}
35
+ */
36
+ logLevel: LogLevelDesc;
37
+ /**
38
+ * js 静态文件 cdn 地址
39
+ *
40
+ * @default https://cdn.jsdelivr.net/
41
+ * @author chitanda
42
+ * @date 2022-10-24 11:10:14
43
+ * @type {string}
44
+ */
45
+ jsCdn: string;
18
46
  /**
19
47
  * 请求根路径
20
48
  *
@@ -23,6 +51,30 @@ export interface IEnvironment {
23
51
  * @type {string}
24
52
  */
25
53
  baseUrl: string;
54
+ /**
55
+ * 插件默认所在目录
56
+ *
57
+ * @author chitanda
58
+ * @date 2022-10-31 14:10:49
59
+ * @type {string}
60
+ */
61
+ pluginBaseUrl: string;
62
+ /**
63
+ * 登录模式
64
+ *
65
+ * @author lxm
66
+ * @date 2022-10-12 14:10:51
67
+ * @type {LoginMode}
68
+ */
69
+ loginMode: LoginMode;
70
+ /**
71
+ * 中央认证登录地址
72
+ *
73
+ * @author lxm
74
+ * @date 2022-10-11 12:10:21
75
+ * @type {string}
76
+ */
77
+ casLoginUrl: string;
26
78
  /**
27
79
  * 远程模型路径
28
80
  *
@@ -48,20 +100,36 @@ export interface IEnvironment {
48
100
  */
49
101
  dcSystem: string;
50
102
  /**
51
- * 文件导出
103
+ * 文件下载url
52
104
  *
53
105
  * @author chitanda
54
106
  * @date 2022-08-22 23:08:46
55
107
  * @type {string}
56
108
  */
57
- ExportFile: string;
109
+ downloadFileUrl: string;
58
110
  /**
59
- * 文件上传
111
+ * 文件上传url
60
112
  *
61
113
  * @author chitanda
62
114
  * @date 2022-08-22 23:08:46
63
115
  * @type {string}
64
116
  */
65
- UploadFile: string;
117
+ uploadFileUrl: string;
118
+ /**
119
+ * 是否启用权限校验(默认true)
120
+ *
121
+ * @author lxm
122
+ * @date 2022-10-12 18:10:25
123
+ * @type {boolean}
124
+ */
125
+ enablePermission: boolean;
126
+ /**
127
+ * 菜单权限校验模式(默认MIXIN)
128
+ *
129
+ * @author lxm
130
+ * @date 2022-10-12 18:10:27
131
+ * @type {MenuPermissionMode}
132
+ */
133
+ menuPermissionMode: MenuPermissionMode;
66
134
  }
67
135
  //# sourceMappingURL=i-environment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;;;;;OAMG;IACH,UAAU,EAAE,MAAM,CAAC;CACpB"}
1
+ {"version":3,"file":"i-environment.d.ts","sourceRoot":"","sources":["../../../src/interface/i-environment/i-environment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;;;;;;OAOG;IACH,GAAG,EAAE,OAAO,CAAC;IAEb;;;;;;OAMG;IACH,QAAQ,EAAE,YAAY,CAAC;IAEvB;;;;;;;OAOG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;;;OAMG;IACH,OAAO,EAAE,MAAM,CAAC;IAEhB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB;;;;;;OAMG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,cAAc,EAAE,MAAM,CAAC;IAEvB;;;;;;OAMG;IACH,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;;OAMG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;;;;;OAMG;IACH,eAAe,EAAE,MAAM,CAAC;IAExB;;;;;;OAMG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;;;OAMG;IACH,gBAAgB,EAAE,OAAO,CAAC;IAE1B;;;;;;OAMG;IACH,kBAAkB,EAAE,kBAAkB,CAAC;CACxC"}
@@ -1,3 +1,4 @@
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';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,cAAc,+BAA+B,CAAC"}
@@ -1 +1 @@
1
- export {};
1
+ export * from './click-outside/click-outside';
package/out/types.d.ts CHANGED
@@ -1,8 +1,18 @@
1
+ import { FactoryCenter } from './factory-center';
1
2
  import { IBizSys } from './ibizsys';
2
3
  declare global {
3
4
  const ibiz: IBizSys;
5
+ const ___fc: FactoryCenter;
4
6
  interface Window {
5
7
  ibiz: IBizSys;
8
+ /**
9
+ * 全局工厂中心
10
+ *
11
+ * @author lxm
12
+ * @date 2022-10-17 15:10:43
13
+ * @type {FactoryCenter}
14
+ */
15
+ ___fc: FactoryCenter;
6
16
  }
7
17
  /**
8
18
  * 上下文
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,IAAI,EAAE,OAAO,CAAC;IAEpB,UAAU,MAAM;QACd,IAAI,EAAE,OAAO,CAAC;KACf;IAED;;;;;;OAMG;IACH,UAAU,QAAQ;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,KAAK;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;CACF"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,IAAI,EAAE,OAAO,CAAC;IACpB,MAAM,KAAK,EAAE,aAAa,CAAC;IAE3B,UAAU,MAAM;QACd,IAAI,EAAE,OAAO,CAAC;QACd;;;;;;WAMG;QACH,KAAK,EAAE,aAAa,CAAC;KACtB;IAED;;;;;;OAMG;IACH,UAAU,QAAQ;QAChB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,KAAK;QACb,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;IAED;;;;;;OAMG;IACH,UAAU,OAAO;QACf,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,CAAC;KAC7B;CACF"}
@@ -0,0 +1,14 @@
1
+ import { OnClickOutsideHandler, OnClickOutsideOptions, OnClickOutsideResult } from '../../interface';
2
+ /**
3
+ * 监听目标元素之外的点击事件回调
4
+ *
5
+ * @author lxm
6
+ * @date 2022-10-28 18:10:25
7
+ * @export
8
+ * @param {HTMLElement} target 目标元素
9
+ * @param {OnClickOutsideHandler} handler 触发的时间回调
10
+ * @param {OnClickOutsideOptions} [options={}] 额外配置参数
11
+ * @returns {*} {OnClickOutsideResult}
12
+ */
13
+ export declare function onClickOutside(target: HTMLElement, handler: OnClickOutsideHandler, options?: OnClickOutsideOptions): OnClickOutsideResult;
14
+ //# sourceMappingURL=click-outside.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"click-outside.d.ts","sourceRoot":"","sources":["../../../src/utils/click-outside/click-outside.ts"],"names":[],"mappings":"AACA,OAAO,EACL,qBAAqB,EACrB,qBAAqB,EACrB,oBAAoB,EACrB,MAAM,iBAAiB,CAAC;AAKzB;;;;;;;;;;GAUG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,EAC9B,OAAO,GAAE,qBAA0B,GAClC,oBAAoB,CAoFtB"}
@@ -0,0 +1,85 @@
1
+ import { RuntimeError } from '../../error';
2
+ import { eventPath, isEventInside, listenJSEvent } from '../event/event';
3
+ const defaultWindow = typeof window !== 'undefined' ? window : undefined;
4
+ /**
5
+ * 监听目标元素之外的点击事件回调
6
+ *
7
+ * @author lxm
8
+ * @date 2022-10-28 18:10:25
9
+ * @export
10
+ * @param {HTMLElement} target 目标元素
11
+ * @param {OnClickOutsideHandler} handler 触发的时间回调
12
+ * @param {OnClickOutsideOptions} [options={}] 额外配置参数
13
+ * @returns {*} {OnClickOutsideResult}
14
+ */
15
+ export function onClickOutside(target, handler, options = {}) {
16
+ const { window = defaultWindow, ignore = [], capture = true } = options;
17
+ if (!target)
18
+ throw new RuntimeError('target元素不存在');
19
+ if (!window)
20
+ throw new RuntimeError('找不到window');
21
+ /** 是否需要监听,为false时handler不会执行 */
22
+ let shouldListen = true;
23
+ /**
24
+ * 判断event的触发是否是在元素的外部(排除了ignore元素)
25
+ * @param event 事件对象
26
+ * @returns
27
+ */
28
+ const isOutside = (event) => {
29
+ // 有一个判断是在内部,则不算外部,返回false
30
+ return ![target, ...ignore].some(el => {
31
+ return isEventInside(event, el);
32
+ });
33
+ };
34
+ /** 暂停,所有监听的回调都不执行,用于增强某些ignore无法实现的场景 */
35
+ let isPaused = false;
36
+ const pause = () => {
37
+ isPaused = true;
38
+ };
39
+ const proceed = () => {
40
+ isPaused = false;
41
+ };
42
+ /** pointerup延时触发标识 */
43
+ let fallback;
44
+ /**
45
+ * 事件监听处理回调
46
+ * @param event 事件对象
47
+ * @returns
48
+ */
49
+ const listener = (event) => {
50
+ if (isPaused)
51
+ return;
52
+ window.clearTimeout(fallback);
53
+ // 当需要监听并且最终触发在外部时才需要执行回调
54
+ if (!(shouldListen && isOutside(event)))
55
+ return;
56
+ handler(event);
57
+ };
58
+ // 鼠标左键单击先后触发pointerdown,pointerup,click
59
+ // 鼠标右键单击先后触发pointerdown,pointerup
60
+ const cleanups = [
61
+ listenJSEvent(window, 'click', listener, { passive: true, capture }),
62
+ listenJSEvent(window, 'pointerdown', e => {
63
+ if (isPaused)
64
+ return;
65
+ // 当pointerdown是在内部触发则不需要后续监听
66
+ shouldListen = isOutside(e);
67
+ }, { passive: true }),
68
+ listenJSEvent(window, 'pointerup', e => {
69
+ if (isPaused)
70
+ return;
71
+ // 鼠标左键触发才执行
72
+ if (e.button === 0) {
73
+ // 锁死结果避免延时执行时变更
74
+ const path = eventPath(e);
75
+ e.composedPath = () => path;
76
+ fallback = window.setTimeout(() => listener(e), 50);
77
+ }
78
+ }, { passive: true }),
79
+ ].filter(Boolean);
80
+ /**
81
+ * 停止事件监听,移除监听
82
+ */
83
+ const stop = () => cleanups.forEach(fn => fn());
84
+ return { stop, pause, proceed };
85
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 混合两种颜色,颜色格式支持hex和rgb
3
+ * 如:#46b5d555,#fff
4
+ * rgb(245 245 245 / 80%)
5
+ *
6
+ * @param {string} color1 颜色1
7
+ * @param {string} color2 颜色2
8
+ * @param {number} [p=0.5] 颜色1占多少百分比,小数格式
9
+ * @param {("hex" | "rgb")} [format="hex"] 输出的格式,hex或rgb
10
+ * @returns {*}
11
+ */
12
+ export declare function colorBlend(color1: string, color2: string, p?: number, format?: 'hex' | 'rgb'): string;
13
+ //# sourceMappingURL=color.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../src/utils/color/color.ts"],"names":[],"mappings":"AA8CA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,CAAC,SAAM,EACP,MAAM,GAAE,KAAK,GAAG,KAAa,GAC5B,MAAM,CAqBR"}
@@ -0,0 +1,76 @@
1
+ /* eslint-disable no-bitwise */
2
+ /* eslint-disable no-nested-ternary */
3
+ const r = Math.round;
4
+ /**
5
+ * 把颜色字符串转成RGBA数组
6
+ *
7
+ * @param {string} color 颜色字符串
8
+ * @returns {*} {number[]}
9
+ */
10
+ function toRGBA(color) {
11
+ const l = color.length;
12
+ const rgba = [];
13
+ if (color.slice(0, 3).toLowerCase() === 'rgb') {
14
+ const d = color.match(/([\d|.%]{1,3})/g);
15
+ rgba[0] = parseInt(d[0], 10);
16
+ rgba[1] = parseInt(d[1], 10);
17
+ rgba[2] = parseInt(d[2], 10);
18
+ rgba[3] = d[3]
19
+ ? d[3].indexOf('%') !== -1
20
+ ? parseInt(d[3], 10) / 100
21
+ : parseFloat(d[3])
22
+ : 1;
23
+ }
24
+ else {
25
+ let d;
26
+ if (l < 6)
27
+ d = parseInt(String(color[1]) +
28
+ color[1] +
29
+ color[2] +
30
+ color[2] +
31
+ color[3] +
32
+ color[3] +
33
+ (l > 4 ? String(color[4]) + color[4] : ''), 16);
34
+ else
35
+ 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
+ * 混合两种颜色,颜色格式支持hex和rgb
46
+ * 如:#46b5d555,#fff
47
+ * rgb(245 245 245 / 80%)
48
+ *
49
+ * @param {string} color1 颜色1
50
+ * @param {string} color2 颜色2
51
+ * @param {number} [p=0.5] 颜色1占多少百分比,小数格式
52
+ * @param {("hex" | "rgb")} [format="hex"] 输出的格式,hex或rgb
53
+ * @returns {*}
54
+ */
55
+ export function colorBlend(color1, color2, p = 0.5, format = 'hex') {
56
+ color1 = color1.trim();
57
+ color2 = color2.trim();
58
+ const c1 = toRGBA(color1);
59
+ const c2 = toRGBA(color2);
60
+ const result = [
61
+ r((1 - p) * c1[0] + p * c2[0]),
62
+ r((1 - p) * c1[1] + p * c2[1]),
63
+ r((1 - p) * c1[2] + p * c2[2]),
64
+ (1 - p) * c1[3] + p * c2[3],
65
+ ];
66
+ if (format === 'hex') {
67
+ const hex = [
68
+ result[0].toString(16),
69
+ result[1].toString(16),
70
+ result[2].toString(16),
71
+ result[3] === 0 ? '00' : r(result[3] * 255).toString(16),
72
+ ];
73
+ return `#${hex[0]}${hex[1]}${hex[2]}${hex[3]}`;
74
+ }
75
+ return `rgb(${result[0]} ${result[1]} ${result[2]} / ${result[3]})`;
76
+ }
@@ -0,0 +1,21 @@
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 declare function calcMimeByFileName(fileName: string): string;
11
+ /**
12
+ * 纯JS触发下载文件
13
+ *
14
+ * @author lxm
15
+ * @date 2022-11-16 22:11:24
16
+ * @export
17
+ * @param {Blob} file 文件流Blob
18
+ * @param {string} fileName 文件名称
19
+ */
20
+ export declare function downloadFileFromBlob(file: Blob, fileName: string): void;
21
+ //# sourceMappingURL=download-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"download-file.d.ts","sourceRoot":"","sources":["../../../src/utils/download-file/download-file.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,UAgDlD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,QAmBhE"}
@@ -0,0 +1,87 @@
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) {
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
+ default:
55
+ mime = '';
56
+ }
57
+ return mime;
58
+ }
59
+ /**
60
+ * 纯JS触发下载文件
61
+ *
62
+ * @author lxm
63
+ * @date 2022-11-16 22:11:24
64
+ * @export
65
+ * @param {Blob} file 文件流Blob
66
+ * @param {string} fileName 文件名称
67
+ */
68
+ export function downloadFileFromBlob(file, fileName) {
69
+ // 获取文件名
70
+ const filetype = calcMimeByFileName(fileName);
71
+ // 用blob对象获取文件流
72
+ const blob = new Blob([file], { type: filetype });
73
+ // 通过文件流创建下载链接
74
+ const href = URL.createObjectURL(blob);
75
+ // 创建一个a元素并设置相关属性
76
+ const a = document.createElement('a');
77
+ a.href = href;
78
+ a.download = fileName;
79
+ // 添加a元素到当前网页
80
+ document.body.appendChild(a);
81
+ // 触发a元素的点击事件,实现下载
82
+ a.click();
83
+ // 从当前网页移除a元素
84
+ document.body.removeChild(a);
85
+ // 释放blob对象
86
+ URL.revokeObjectURL(href);
87
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * 计算event的composedPath返回事件路径(兼容了IE)
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-28 17:10:14
6
+ * @param {MouseEvent} event
7
+ * @returns {*}
8
+ */
9
+ export declare function eventPath(event: MouseEvent): (EventTarget | null)[];
10
+ /**
11
+ * 监听JS原生事件,返回cleanup回调,调用后删除该监听
12
+ *
13
+ * @author lxm
14
+ * @date 2022-10-28 18:10:36
15
+ * @export
16
+ * @param {EventTarget} target 监听对象
17
+ * @param {string} eventName 监听事件名称
18
+ * @param {(..._args: any[]) => any} listener 监听回调
19
+ * @param {AddEventListenerOptions} options 额外参数
20
+ * @returns {*} {() => void}
21
+ */
22
+ export declare function listenJSEvent(target: EventTarget, eventName: string, listener: (..._args: any[]) => any, options?: AddEventListenerOptions): () => void;
23
+ /**
24
+ * event是否是在目标元素内部触发的
25
+ *
26
+ * @author lxm
27
+ * @date 2022-10-31 11:10:49
28
+ * @export
29
+ * @param {MouseEvent} event 原生事件
30
+ * @param {HTMLElement} el 目标元素
31
+ * @returns {*} {boolean}
32
+ */
33
+ export declare function isEventInside(event: MouseEvent, el: HTMLElement): boolean;
34
+ //# sourceMappingURL=event.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"event.d.ts","sourceRoot":"","sources":["../../../src/utils/event/event.ts"],"names":[],"mappings":"AAIA;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,UAAU,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,EAAE,CAmBnE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,CAAC,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,GAAG,EAClC,OAAO,GAAE,uBAA4B,GACpC,MAAM,IAAI,CAYZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,GAAG,OAAO,CAEzE"}
@@ -0,0 +1,60 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { NOOP } from '../../constant';
3
+ /**
4
+ * 计算event的composedPath返回事件路径(兼容了IE)
5
+ *
6
+ * @author lxm
7
+ * @date 2022-10-28 17:10:14
8
+ * @param {MouseEvent} event
9
+ * @returns {*}
10
+ */
11
+ export function eventPath(event) {
12
+ const path = ((event.composedPath && event.composedPath()) ||
13
+ event.path);
14
+ if (path != null)
15
+ return path;
16
+ // 浏览器没有提供的,自己递归计算
17
+ function getParents(node, memo = []) {
18
+ const parentNode = node.parentNode;
19
+ return parentNode
20
+ ? getParents(parentNode, memo.concat([parentNode]))
21
+ : memo;
22
+ }
23
+ return [event.target].concat(getParents(event.target));
24
+ }
25
+ /**
26
+ * 监听JS原生事件,返回cleanup回调,调用后删除该监听
27
+ *
28
+ * @author lxm
29
+ * @date 2022-10-28 18:10:36
30
+ * @export
31
+ * @param {EventTarget} target 监听对象
32
+ * @param {string} eventName 监听事件名称
33
+ * @param {(..._args: any[]) => any} listener 监听回调
34
+ * @param {AddEventListenerOptions} options 额外参数
35
+ * @returns {*} {() => void}
36
+ */
37
+ export function listenJSEvent(target, eventName, listener, options = {}) {
38
+ target.addEventListener(eventName, listener, options);
39
+ let cleanup = () => {
40
+ target.removeEventListener(eventName, listener, options);
41
+ // cleanup方法只能调用一次
42
+ cleanup = NOOP;
43
+ };
44
+ return () => {
45
+ cleanup();
46
+ };
47
+ }
48
+ /**
49
+ * event是否是在目标元素内部触发的
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-31 11:10:49
53
+ * @export
54
+ * @param {MouseEvent} event 原生事件
55
+ * @param {HTMLElement} el 目标元素
56
+ * @returns {*} {boolean}
57
+ */
58
+ export function isEventInside(event, el) {
59
+ return el && (event.target === el || eventPath(event).includes(el));
60
+ }
@@ -1,7 +1,13 @@
1
- export { Interceptor } from './interceptor/interceptor';
1
+ export * from './interceptor';
2
+ export { Logger } from './logger/logger';
2
3
  export { Namespace } from './namespace/namespace';
3
4
  export { IHttpResponse, HttpResponse } from './net/http-response';
4
5
  export { Net } from './net/net';
5
6
  export { plural, pluralLower } from './plural/plural';
6
7
  export * from './util/util';
8
+ export * from './url-helper/url-helper';
9
+ export * from './event/event';
10
+ export * from './click-outside/click-outside';
11
+ export * from './color/color';
12
+ export * from './download-file/download-file';
7
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAChC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACtD,cAAc,aAAa,CAAC;AAC5B,cAAc,yBAAyB,CAAC;AACxC,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC;AAC9C,cAAc,eAAe,CAAC;AAC9B,cAAc,+BAA+B,CAAC"}