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

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 (141) hide show
  1. package/dist/system/index.system.js +1 -0
  2. package/out/constant/core/core.d.ts +9 -0
  3. package/out/constant/core/core.d.ts.map +1 -1
  4. package/out/constant/core/core.js +9 -0
  5. package/out/constant/index.d.ts +3 -0
  6. package/out/constant/index.d.ts.map +1 -1
  7. package/out/constant/index.js +3 -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 +49 -27
  18. package/out/context/index.d.ts.map +1 -1
  19. package/out/context/index.js +94 -55
  20. package/out/environment/environment.d.ts.map +1 -1
  21. package/out/environment/environment.js +16 -2
  22. package/out/error/http-error/http-error.d.ts.map +1 -1
  23. package/out/error/http-error/http-error.js +0 -4
  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 +108 -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 +41 -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 +31 -0
  52. package/out/utils/download-file/download-file.d.ts.map +1 -0
  53. package/out/utils/download-file/download-file.js +107 -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 +11 -1
  58. package/out/utils/index.d.ts.map +1 -1
  59. package/out/utils/index.js +11 -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 +98 -30
  76. package/out/utils/net/net.d.ts.map +1 -1
  77. package/out/utils/net/net.js +133 -38
  78. package/out/utils/plural/plural.d.ts.map +1 -1
  79. package/out/utils/plural/plural.js +2 -0
  80. package/out/utils/string-util/string-util.d.ts +46 -0
  81. package/out/utils/string-util/string-util.d.ts.map +1 -0
  82. package/out/utils/string-util/string-util.js +71 -0
  83. package/out/utils/sync/await-timeout.d.ts +14 -0
  84. package/out/utils/sync/await-timeout.d.ts.map +1 -0
  85. package/out/utils/sync/await-timeout.js +23 -0
  86. package/out/utils/sync/count-latch.d.ts +60 -0
  87. package/out/utils/sync/count-latch.d.ts.map +1 -0
  88. package/out/utils/sync/count-latch.js +90 -0
  89. package/out/utils/sync/index.d.ts +3 -0
  90. package/out/utils/sync/index.d.ts.map +1 -0
  91. package/out/utils/sync/index.js +2 -0
  92. package/out/utils/upload/select-file.d.ts +53 -0
  93. package/out/utils/upload/select-file.d.ts.map +1 -0
  94. package/out/utils/upload/select-file.js +47 -0
  95. package/out/utils/upload/upload-file.d.ts +46 -0
  96. package/out/utils/upload/upload-file.d.ts.map +1 -0
  97. package/out/utils/upload/upload-file.js +150 -0
  98. package/out/utils/url-helper/url-helper.d.ts +51 -0
  99. package/out/utils/url-helper/url-helper.d.ts.map +1 -0
  100. package/out/utils/url-helper/url-helper.js +59 -0
  101. package/out/utils/util/util.d.ts +20 -4
  102. package/out/utils/util/util.d.ts.map +1 -1
  103. package/out/utils/util/util.js +59 -5
  104. package/package.json +21 -10
  105. package/src/constant/core/core.ts +10 -0
  106. package/src/constant/index.ts +3 -0
  107. package/src/constant/login-mode/login-mode.ts +23 -0
  108. package/src/constant/menu-permission-mode/menu-permission-mode.ts +23 -0
  109. package/src/constant/util/util.ts +5 -0
  110. package/src/context/index.ts +127 -51
  111. package/src/environment/environment.ts +16 -2
  112. package/src/error/http-error/http-error.ts +0 -4
  113. package/src/factory-center.ts +9 -0
  114. package/src/ibizsys.ts +9 -1
  115. package/src/index.ts +2 -1
  116. package/src/install.ts +4 -2
  117. package/src/interface/click-outside/click-outside.ts +71 -0
  118. package/src/interface/i-environment/i-environment.ts +122 -4
  119. package/src/interface/index.ts +1 -0
  120. package/src/types.ts +45 -0
  121. package/src/utils/click-outside/click-outside.ts +110 -0
  122. package/src/utils/color/color.ts +84 -0
  123. package/src/utils/download-file/download-file.ts +109 -0
  124. package/src/utils/event/event.ts +77 -0
  125. package/src/utils/index.ts +11 -1
  126. package/src/utils/interceptor/core-interceptor.ts +35 -0
  127. package/src/utils/interceptor/index.ts +2 -0
  128. package/src/utils/interceptor/interceptor.ts +109 -22
  129. package/src/utils/logger/logger.ts +3 -0
  130. package/src/utils/net/http-response.ts +6 -9
  131. package/src/utils/net/net.ts +171 -50
  132. package/src/utils/plural/plural.ts +3 -0
  133. package/src/utils/string-util/string-util.ts +75 -0
  134. package/src/utils/sync/await-timeout.ts +27 -0
  135. package/src/utils/sync/count-latch.ts +96 -0
  136. package/src/utils/sync/index.ts +2 -0
  137. package/src/utils/upload/select-file.ts +86 -0
  138. package/src/utils/upload/upload-file.ts +206 -0
  139. package/src/utils/url-helper/url-helper.ts +62 -0
  140. package/src/utils/util/util.ts +72 -14
  141. package/LICENSE +0 -21
@@ -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,79 @@ 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;
149
+
150
+ /**
151
+ * 是否让所有工作流history接口走all
152
+ *
153
+ * @type {boolean}
154
+ * @memberof IEnvironment
155
+ */
156
+ enableWfAllHistory: boolean;
157
+
158
+ /**
159
+ * 路由占位符
160
+ *
161
+ * @type {string}
162
+ * @memberof IEnvironment
163
+ */
164
+ routePlaceholder: string;
165
+
166
+ /**
167
+ * 登录页视图组件名称
168
+ *
169
+ * @type {string}
170
+ * @memberof IEnvironment
171
+ */
172
+ loginViewName: string;
173
+
174
+ /**
175
+ * 版本
176
+ *
177
+ * @type {string}
178
+ * @memberof IEnvironment
179
+ */
180
+ version: string;
181
+
182
+ /**
183
+ * 应用图标地址
184
+ *
185
+ * @author chitanda
186
+ * @date 2023-07-17 17:07:23
187
+ * @type {string}
188
+ */
189
+ favicon?: string;
72
190
  }
@@ -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
  /**
@@ -17,6 +27,41 @@ declare global {
17
27
  */
18
28
  interface IContext {
19
29
  [key: string | symbol]: any;
30
+
31
+ /**
32
+ * 沙箱标识
33
+ *
34
+ * @author chitanda
35
+ * @date 2022-07-22 15:07:23
36
+ * @type {string}
37
+ */
38
+ srfsandbox?: string;
39
+
40
+ /**
41
+ * 返回自身的上下文,独有的和与父有差异的
42
+ *
43
+ * @author chitanda
44
+ * @date 2023-03-13 17:03:10
45
+ * @return {*} {IData}
46
+ */
47
+ getOwnContext(): IData;
48
+
49
+ /**
50
+ * 销毁当前上下文
51
+ *
52
+ * @author chitanda
53
+ * @date 2023-03-13 17:03:37
54
+ */
55
+ destroy(): void;
56
+
57
+ /**
58
+ * 克隆当前上下文
59
+ *
60
+ * @author chitanda
61
+ * @date 2023-03-13 17:03:45
62
+ * @return {*} {IContext}
63
+ */
64
+ clone(): IContext;
20
65
  }
21
66
 
22
67
  /**
@@ -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
+ }
@@ -0,0 +1,109 @@
1
+ /**
2
+ * 根据文件名称计算Mime类型
3
+ *
4
+ * @author lxm
5
+ * @date 2022-11-16 22:11:02
6
+ * @export
7
+ * @param {string} fileName
8
+ * @returns {*}
9
+ */
10
+ export function calcMimeByFileName(fileName: string) {
11
+ const ext = fileName.split('.').pop();
12
+ let mime = '';
13
+ switch (ext) {
14
+ case '.wps':
15
+ mime = 'application/kswps';
16
+ break;
17
+ case '.doc':
18
+ mime = 'application/msword';
19
+ break;
20
+ case '.docx':
21
+ mime =
22
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
23
+ break;
24
+ case '.txt':
25
+ mime = 'text/plain';
26
+ break;
27
+ case '.zip':
28
+ mime = 'application/zip';
29
+ break;
30
+ case '.png':
31
+ mime = 'image/png';
32
+ break;
33
+ case '.gif':
34
+ mime = 'image/gif';
35
+ break;
36
+ case '.jpeg':
37
+ mime = 'image/jpeg';
38
+ break;
39
+ case '.jpg':
40
+ mime = 'image/jpeg';
41
+ break;
42
+ case '.rtf':
43
+ mime = 'application/rtf';
44
+ break;
45
+ case '.avi':
46
+ mime = 'video/x-msvideo';
47
+ break;
48
+ case '.gz':
49
+ mime = 'application/x-gzip';
50
+ break;
51
+ case '.tar':
52
+ mime = 'application/x-tar';
53
+ break;
54
+ case '.xlsx':
55
+ mime = 'application/vnd.ms-excel';
56
+ break;
57
+ default:
58
+ mime = '';
59
+ }
60
+ return mime;
61
+ }
62
+
63
+ /**
64
+ * 判断是否是图片格式
65
+ *
66
+ * @author lxm
67
+ * @date 2022-11-21 13:11:23
68
+ * @export
69
+ * @param {string} fileName
70
+ * @returns {*} {boolean}
71
+ */
72
+ export function isImage(fileName: string): boolean {
73
+ const ext = fileName.split('.').pop();
74
+ if (!ext) {
75
+ return false;
76
+ }
77
+ const imageTypes = ['.jpeg', 'jpg', 'gif', 'png', 'bmp', 'svg'];
78
+ return imageTypes.includes(ext);
79
+ }
80
+
81
+ /**
82
+ * 纯JS触发下载文件
83
+ *
84
+ * @author lxm
85
+ * @date 2022-11-16 22:11:24
86
+ * @export
87
+ * @param {Blob} file 文件流Blob
88
+ * @param {string} fileName 文件名称
89
+ */
90
+ export function downloadFileFromBlob(file: Blob, fileName: string) {
91
+ // 获取文件名
92
+ const filetype = calcMimeByFileName(fileName);
93
+ // 用blob对象获取文件流
94
+ const blob = new Blob([file], { type: filetype });
95
+ // 通过文件流创建下载链接
96
+ const href = URL.createObjectURL(blob);
97
+ // 创建一个a元素并设置相关属性
98
+ const a = document.createElement('a');
99
+ a.href = href;
100
+ a.download = fileName;
101
+ // 添加a元素到当前网页
102
+ document.body.appendChild(a);
103
+ // 触发a元素的点击事件,实现下载
104
+ a.click();
105
+ // 从当前网页移除a元素
106
+ document.body.removeChild(a);
107
+ // 释放blob对象
108
+ URL.revokeObjectURL(href);
109
+ }
@@ -0,0 +1,77 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+
3
+ import { NOOP } from '../../constant';
4
+
5
+ /**
6
+ * 计算event的composedPath返回事件路径(兼容了IE)
7
+ *
8
+ * @author lxm
9
+ * @date 2022-10-28 17:10:14
10
+ * @param {MouseEvent} event
11
+ * @returns {*}
12
+ */
13
+ export function eventPath(event: MouseEvent): (EventTarget | null)[] {
14
+ const path = ((event.composedPath && event.composedPath()) ||
15
+ (event as any).path) as HTMLElement[] | undefined;
16
+
17
+ if (path != null) return path;
18
+
19
+ // 浏览器没有提供的,自己递归计算
20
+ function getParents(
21
+ node: HTMLElement,
22
+ memo: HTMLElement[] = [],
23
+ ): HTMLElement[] {
24
+ const parentNode = node.parentNode as HTMLElement | null;
25
+
26
+ return parentNode
27
+ ? getParents(parentNode, memo.concat([parentNode]))
28
+ : memo;
29
+ }
30
+
31
+ return [event.target].concat(getParents(event.target as HTMLElement));
32
+ }
33
+
34
+ /**
35
+ * 监听JS原生事件,返回cleanup回调,调用后删除该监听
36
+ *
37
+ * @author lxm
38
+ * @date 2022-10-28 18:10:36
39
+ * @export
40
+ * @param {EventTarget} target 监听对象
41
+ * @param {string} eventName 监听事件名称
42
+ * @param {(..._args: any[]) => any} listener 监听回调
43
+ * @param {AddEventListenerOptions} options 额外参数
44
+ * @returns {*} {() => void}
45
+ */
46
+ export function listenJSEvent(
47
+ target: EventTarget,
48
+ eventName: string,
49
+ listener: (..._args: any[]) => any,
50
+ options: AddEventListenerOptions = {},
51
+ ): () => void {
52
+ target.addEventListener(eventName, listener, options);
53
+
54
+ let cleanup = () => {
55
+ target.removeEventListener(eventName, listener, options);
56
+ // cleanup方法只能调用一次
57
+ cleanup = NOOP;
58
+ };
59
+
60
+ return () => {
61
+ cleanup();
62
+ };
63
+ }
64
+
65
+ /**
66
+ * event是否是在目标元素内部触发的
67
+ *
68
+ * @author lxm
69
+ * @date 2022-10-31 11:10:49
70
+ * @export
71
+ * @param {MouseEvent} event 原生事件
72
+ * @param {HTMLElement} el 目标元素
73
+ * @returns {*} {boolean}
74
+ */
75
+ export function isEventInside(event: MouseEvent, el: HTMLElement): boolean {
76
+ return el && (event.target === el || eventPath(event).includes(el));
77
+ }
@@ -1,6 +1,16 @@
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';
13
+ export * from './upload/select-file';
14
+ export * from './upload/upload-file';
15
+ export * from './sync';
16
+ export { StringUtil } from './string-util/string-util';
@@ -0,0 +1,35 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { getToken } from '../util/util';
3
+ import { Interceptor } from './interceptor';
4
+
5
+ /**
6
+ * 核心包拦截器
7
+ *
8
+ * @author lxm
9
+ * @date 2022-10-27 17:10:48
10
+ * @export
11
+ * @class CoreInterceptor
12
+ * @extends {Interceptor}
13
+ */
14
+ export class CoreInterceptor extends Interceptor {
15
+ protected async onBeforeRequest(
16
+ config: AxiosRequestConfig,
17
+ ): Promise<AxiosRequestConfig> {
18
+ await super.onBeforeRequest(config);
19
+
20
+ if (!config.headers) {
21
+ config.headers = {};
22
+ }
23
+ config.headers.Authorization = `Bearer ${getToken()}`;
24
+ const { orgData } = ibiz;
25
+ if (orgData) {
26
+ if (orgData.systemid) {
27
+ config.headers.srfsystemid = orgData.systemid;
28
+ }
29
+ if (orgData.orgid) {
30
+ config.headers.srforgid = orgData.orgid;
31
+ }
32
+ }
33
+ return config;
34
+ }
35
+ }
@@ -0,0 +1,2 @@
1
+ export * from './core-interceptor';
2
+ export * from './interceptor';