@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
@@ -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,15 @@
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';
@@ -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';
@@ -1,8 +1,8 @@
1
- import axios from 'axios';
2
- import { getToken } from '../util/util';
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
3
3
 
4
4
  /**
5
- * 默认请求拦截器
5
+ * 拦截器基类
6
6
  *
7
7
  * @author chitanda
8
8
  * @date 2022-07-20 18:07:11
@@ -10,26 +10,113 @@ import { getToken } from '../util/util';
10
10
  * @class Interceptor
11
11
  */
12
12
  export class Interceptor {
13
- constructor() {
14
- this.init();
13
+ /**
14
+ * 请求拦截器绑定标识
15
+ *
16
+ * @author lxm
17
+ * @date 2022-10-27 17:10:20
18
+ * @private
19
+ * @type {number}
20
+ */
21
+ private requestTag?: number;
22
+
23
+ /**
24
+ * 响应拦截器绑定标识
25
+ *
26
+ * @author lxm
27
+ * @date 2022-10-27 17:10:19
28
+ * @private
29
+ * @type {number}
30
+ */
31
+ private responseTag?: number;
32
+
33
+ /**
34
+ * 请求之前处理
35
+ *
36
+ * @author lxm
37
+ * @date 2022-10-27 17:10:41
38
+ * @protected
39
+ * @param {AxiosRequestConfig} config
40
+ * @returns {*} {Promise<AxiosRequestConfig>}
41
+ */
42
+ protected async onBeforeRequest(
43
+ config: AxiosRequestConfig,
44
+ ): Promise<AxiosRequestConfig> {
45
+ return config;
46
+ }
47
+
48
+ /**
49
+ * 请求失败之后处理
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-27 17:10:40
53
+ * @protected
54
+ * @param {*} error
55
+ */
56
+ protected onRequestError(error: any) {
57
+ // 处理请求错误
58
+ return Promise.reject(error);
59
+ }
60
+
61
+ /**
62
+ * 响应成功之后处理
63
+ *
64
+ * @author lxm
65
+ * @date 2022-10-27 17:10:38
66
+ * @protected
67
+ * @param {AxiosResponse} config
68
+ * @returns {*} {Promise<AxiosRequestConfig>}
69
+ */
70
+ protected async onResponseSuccess(
71
+ config: AxiosResponse,
72
+ ): Promise<AxiosResponse> {
73
+ return config;
74
+ }
75
+
76
+ /**
77
+ * 响应失败之后处理
78
+ *
79
+ * @author lxm
80
+ * @date 2022-10-27 17:10:37
81
+ * @protected
82
+ * @param {*} _error
83
+ */
84
+ protected onResponseError(error: any) {
85
+ // 处理响应错误
86
+ return Promise.reject(error);
87
+ }
88
+
89
+ /**
90
+ * 使用拦截器
91
+ *
92
+ * @author lxm
93
+ * @date 2022-10-27 17:10:28
94
+ * @param {AxiosInstance} instance
95
+ */
96
+ use(instance: AxiosInstance): void {
97
+ this.requestTag = instance.interceptors.request.use(
98
+ this.onBeforeRequest,
99
+ this.onRequestError,
100
+ );
101
+ this.responseTag = instance.interceptors.response.use(
102
+ this.onResponseSuccess,
103
+ this.onResponseError,
104
+ );
15
105
  }
16
106
 
17
- protected init(): void {
18
- axios.interceptors.request.use(config => {
19
- if (!config.headers) {
20
- config.headers = {};
21
- }
22
- config.headers.Authorization = `Bearer ${getToken()}`;
23
- const { orgData } = ibiz;
24
- if (orgData) {
25
- if (orgData.systemid) {
26
- config.headers.srfsystemid = orgData.systemid;
27
- }
28
- if (orgData.orgid) {
29
- config.headers.srforgid = orgData.orgid;
30
- }
31
- }
32
- return config;
33
- });
107
+ /**
108
+ * 移出拦截器
109
+ *
110
+ * @author lxm
111
+ * @date 2022-10-27 17:10:27
112
+ * @param {AxiosInstance} instance
113
+ */
114
+ eject(instance: AxiosInstance) {
115
+ if (this.requestTag) {
116
+ instance.interceptors.request.eject(this.requestTag);
117
+ }
118
+ if (this.responseTag) {
119
+ instance.interceptors.response.eject(this.responseTag);
120
+ }
34
121
  }
35
122
  }
@@ -0,0 +1,3 @@
1
+ import * as Logger from 'loglevel';
2
+
3
+ export { Logger };
@@ -28,7 +28,7 @@ export interface IHttpResponse<T = IData> extends AxiosResponse {
28
28
  * @date 2022-08-18 15:08:44
29
29
  * @type {boolean}
30
30
  */
31
- local?: boolean;
31
+ local: boolean;
32
32
 
33
33
  data: T;
34
34
 
@@ -75,14 +75,11 @@ export class HttpResponse<T = IData> implements IHttpResponse<T> {
75
75
 
76
76
  statusText: string;
77
77
 
78
- /**
79
- * header 本地仿造时值为空
80
- *
81
- * @author chitanda
82
- * @date 2022-08-18 15:08:46
83
- * @type {AxiosResponseHeaders}
84
- */
85
- headers: AxiosResponseHeaders = {};
78
+ headers:
79
+ | AxiosResponseHeaders
80
+ | Partial<
81
+ Record<string, string> & { 'set-cookie'?: string[] | undefined }
82
+ > = {};
86
83
 
87
84
  /**
88
85
  * AxiosResponse 本地仿造时值为空