@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,47 @@
1
+ import { merge } from 'lodash-es';
2
+ /**
3
+ * 文件List转数组
4
+ *
5
+ * @author lxm
6
+ * @date 2022-11-18 13:11:03
7
+ * @export
8
+ * @param {FileList} fileList
9
+ * @returns {*}
10
+ */
11
+ export function fileListToArr(fileList) {
12
+ const files = [];
13
+ for (let i = 0; i < fileList.length; i++) {
14
+ files.push(fileList[i]);
15
+ }
16
+ return files;
17
+ }
18
+ /**
19
+ * JS打开文件上传操作
20
+ *
21
+ * @author lxm
22
+ * @date 2022-11-20 21:11:31
23
+ * @export
24
+ * @param {SelectFileOpts} _opts 配置参数
25
+ */
26
+ export function selectFile(_opts) {
27
+ const opts = merge({
28
+ multiple: true,
29
+ accept: '',
30
+ }, _opts);
31
+ const input = document.createElement('input');
32
+ input.setAttribute('type', 'file');
33
+ input.setAttribute('multiple', `${opts.multiple}`);
34
+ input.setAttribute('accept', opts.accept);
35
+ input.onchange = e => {
36
+ const inputEl = e.target;
37
+ const files = inputEl.files ? fileListToArr(inputEl.files) : [];
38
+ if (files.length === 0) {
39
+ return;
40
+ }
41
+ opts.onSelected(files);
42
+ inputEl.value = ''; // 如果不置空,相同的文件不会触发change事件
43
+ };
44
+ document.body.appendChild(input);
45
+ input.click();
46
+ document.body.removeChild(input);
47
+ }
@@ -0,0 +1,46 @@
1
+ import { HttpResponse } from '../net/http-response';
2
+ export interface IUploadFile {
3
+ name: string;
4
+ uid: string;
5
+ status: 'uploading' | 'finished' | 'fail' | 'cancel';
6
+ percentage: number;
7
+ response?: HttpResponse;
8
+ error?: unknown;
9
+ }
10
+ export interface IUploadFileOpts {
11
+ uploadUrl: string;
12
+ /**
13
+ * 接受的文件类型
14
+ *
15
+ * @author lxm
16
+ * @date 2022-11-20 21:11:52
17
+ * @type {string}
18
+ */
19
+ accept?: string;
20
+ /**
21
+ * 是否支持多选
22
+ *
23
+ * @author lxm
24
+ * @date 2022-11-20 21:11:52
25
+ * @type {Boolean}
26
+ */
27
+ multiple?: boolean;
28
+ separate?: string;
29
+ request?: (_files: File[]) => Promise<HttpResponse>;
30
+ beforeUpload?: (_fileData: File[], _files: IUploadFile[]) => boolean;
31
+ finish?: (_resultFiles: IUploadFile[]) => void;
32
+ success?: (_resultFiles: IUploadFile[], _res: HttpResponse) => void;
33
+ error?: (_resultFiles: IUploadFile[], _error: unknown) => void;
34
+ progress?: (_files: IUploadFile[]) => void;
35
+ }
36
+ /**
37
+ * 使用上传文件逻辑
38
+ *
39
+ * @author lxm
40
+ * @date 2022-11-20 21:11:52
41
+ * @export
42
+ * @param {IUploadFileOpts} _opts
43
+ * @returns {*}
44
+ */
45
+ export declare function uploadFile(_opts: IUploadFileOpts): void;
46
+ //# sourceMappingURL=upload-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upload-file.d.ts","sourceRoot":"","sources":["../../../src/utils/upload/upload-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGpD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,WAAW,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;IACrD,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,YAAY,CAAC;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;IACpD,YAAY,CAAC,EAAE,CAAC,SAAS,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,KAAK,OAAO,CAAC;IACrE,MAAM,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,IAAI,EAAE,YAAY,KAAK,IAAI,CAAC;IACpE,KAAK,CAAC,EAAE,CAAC,YAAY,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,OAAO,KAAK,IAAI,CAAC;IAC/D,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,WAAW,EAAE,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,QA0JhD"}
@@ -0,0 +1,150 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-function */
2
+ /* eslint-disable no-param-reassign */
3
+ import { cloneDeep, isFunction, merge, round, uniqueId } from 'lodash-es';
4
+ import { selectFile } from './select-file';
5
+ /**
6
+ * 使用上传文件逻辑
7
+ *
8
+ * @author lxm
9
+ * @date 2022-11-20 21:11:52
10
+ * @export
11
+ * @param {IUploadFileOpts} _opts
12
+ * @returns {*}
13
+ */
14
+ export function uploadFile(_opts) {
15
+ const opts = merge({
16
+ multiple: true,
17
+ accept: '',
18
+ separate: true,
19
+ beforeUpload: (_fileData, _files) => true,
20
+ finish: (_resultFiles) => { },
21
+ success: (_resultFiles, _res) => { },
22
+ error: (_resultFiles, _error) => { },
23
+ progress: (_files) => { },
24
+ }, _opts);
25
+ /**
26
+ * 进度条回调
27
+ *
28
+ * @author lxm
29
+ * @date 2022-11-20 21:11:47
30
+ * @param {IParams} event
31
+ * @param {IUploadFile[]} files
32
+ */
33
+ const onUploadProgress = (event, files) => {
34
+ files.forEach(file => {
35
+ file.percentage = round(event.progress * 100);
36
+ });
37
+ opts.progress(cloneDeep(files));
38
+ };
39
+ /**
40
+ * 上传请求方法,返回响应对象
41
+ *
42
+ * @author lxm
43
+ * @date 2022-11-18 13:11:57
44
+ * @param {File[]} files
45
+ * @returns {*} {Promise<HttpResponse>}
46
+ */
47
+ const uploadRequest = async (files, onProgress) => {
48
+ // 自定义上传请求
49
+ if (opts.request && isFunction(opts.request)) {
50
+ return opts.request(files);
51
+ }
52
+ // 默认每次单个文件上传,可能存在接口一次上传多个文件,
53
+ const data = new FormData();
54
+ files.forEach(file => {
55
+ data.append('file', file);
56
+ });
57
+ const res = await ibiz.net.request(opts.uploadUrl, {
58
+ method: 'post',
59
+ baseURL: '',
60
+ data,
61
+ headers: { 'Content-Type': 'multipart/form-data' },
62
+ onUploadProgress: onProgress,
63
+ });
64
+ return res;
65
+ };
66
+ /**
67
+ * 执行一次上传,可能是一个文件也可能是多个文件
68
+ *
69
+ * @author lxm
70
+ * @date 2022-11-18 14:11:54
71
+ * @param {File[]} files 此次上传文件的集合
72
+ * @returns {*} {Promise<IUploadFile[]>}
73
+ */
74
+ const executeSingleUpload = async (files) => {
75
+ const resultFiles = files.map(file => {
76
+ return {
77
+ status: 'uploading',
78
+ name: file.name,
79
+ uid: uniqueId(),
80
+ percentage: 0,
81
+ };
82
+ });
83
+ // 上传前回调,可以取消此次下载
84
+ const pass = opts.beforeUpload(files, resultFiles);
85
+ if (!pass) {
86
+ resultFiles.forEach(file => {
87
+ file.status = 'cancel';
88
+ });
89
+ ibiz.log.debug('取消上传', resultFiles);
90
+ return resultFiles;
91
+ }
92
+ try {
93
+ const res = await uploadRequest(files, event => {
94
+ onUploadProgress(event, resultFiles);
95
+ });
96
+ resultFiles.forEach(file => {
97
+ file.status = 'finished';
98
+ });
99
+ // 上传成功事件
100
+ opts.success(resultFiles, res);
101
+ resultFiles.forEach(file => {
102
+ file.response = res;
103
+ });
104
+ }
105
+ catch (error) {
106
+ resultFiles.forEach(file => {
107
+ file.status = 'fail';
108
+ });
109
+ // 上传失败事件
110
+ opts.error(resultFiles, error);
111
+ resultFiles.forEach(file => {
112
+ file.error = error;
113
+ });
114
+ ibiz.log.error(error);
115
+ ibiz.log.error(`${files.map(file => file.name).join(',')}上传失败`);
116
+ }
117
+ return resultFiles;
118
+ };
119
+ /**
120
+ * 执行上传文件逻辑
121
+ *
122
+ * @author lxm
123
+ * @date 2022-11-18 13:11:21
124
+ * @param {files} File[] 文件集合
125
+ */
126
+ const uploadFiles = async (files) => {
127
+ const uploadSequence = opts.separate ? files.map(file => [file]) : [files];
128
+ const res = await Promise.allSettled(uploadSequence.map(async (sequence) => {
129
+ return executeSingleUpload(sequence);
130
+ }));
131
+ // 整合所有的返回文件
132
+ const resultFiles = [];
133
+ res.forEach(result => {
134
+ if (result.status === 'fulfilled') {
135
+ resultFiles.push(...result.value);
136
+ }
137
+ });
138
+ opts.finish(resultFiles);
139
+ };
140
+ const select = () => {
141
+ selectFile({
142
+ accept: opts.accept,
143
+ multiple: opts.multiple,
144
+ onSelected: files => {
145
+ uploadFiles(files);
146
+ },
147
+ });
148
+ };
149
+ select();
150
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 路径解析助手
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-11 14:10:12
6
+ * @export
7
+ * @class UrlHelper
8
+ */
9
+ export declare class UrlHelper {
10
+ /**
11
+ * 路由路径前面的基础路径
12
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
13
+ * 返回:http://172.16.103.120:30061/portalwebapp/#
14
+ *
15
+ * @author lxm
16
+ * @date 2022-10-11 20:10:29
17
+ * @returns {*}
18
+ */
19
+ static get routeBase(): string;
20
+ /**
21
+ * 应用的的基础路径
22
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
23
+ * 返回:http://172.16.103.120:30061/portalwebapp
24
+ *
25
+ * @author lxm
26
+ * @date 2022-10-11 20:10:29
27
+ * @returns {*}
28
+ */
29
+ static get appBase(): string;
30
+ /**
31
+ * #开始到末尾,即路由地址
32
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
33
+ * 返回:/index/appportalview?params=123
34
+ *
35
+ * @author lxm
36
+ * @date 2022-10-11 16:10:40
37
+ * @returns {*}
38
+ */
39
+ static get routePath(): string;
40
+ /**
41
+ * 当前地址的全路径,包含域名和参数
42
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
43
+ *
44
+ * @author lxm
45
+ * @date 2022-10-11 21:10:39
46
+ * @readonly
47
+ * @static
48
+ */
49
+ static get fullPath(): string;
50
+ }
51
+ //# sourceMappingURL=url-helper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"url-helper.d.ts","sourceRoot":"","sources":["../../../src/utils/url-helper/url-helper.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,SAAS;IACpB;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,OAAO,WAGjB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,SAAS,WAEnB;IAED;;;;;;;;OAQG;IACH,MAAM,KAAK,QAAQ,WAElB;CACF"}
@@ -0,0 +1,59 @@
1
+ /**
2
+ * 路径解析助手
3
+ *
4
+ * @author lxm
5
+ * @date 2022-10-11 14:10:12
6
+ * @export
7
+ * @class UrlHelper
8
+ */
9
+ export class UrlHelper {
10
+ /**
11
+ * 路由路径前面的基础路径
12
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
13
+ * 返回:http://172.16.103.120:30061/portalwebapp/#
14
+ *
15
+ * @author lxm
16
+ * @date 2022-10-11 20:10:29
17
+ * @returns {*}
18
+ */
19
+ static get routeBase() {
20
+ return `${this.appBase}/#`;
21
+ }
22
+ /**
23
+ * 应用的的基础路径
24
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
25
+ * 返回:http://172.16.103.120:30061/portalwebapp
26
+ *
27
+ * @author lxm
28
+ * @date 2022-10-11 20:10:29
29
+ * @returns {*}
30
+ */
31
+ static get appBase() {
32
+ const { origin, pathname } = window.location;
33
+ return `${origin}${pathname}`.replace(/\/$/, '');
34
+ }
35
+ /**
36
+ * #开始到末尾,即路由地址
37
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
38
+ * 返回:/index/appportalview?params=123
39
+ *
40
+ * @author lxm
41
+ * @date 2022-10-11 16:10:40
42
+ * @returns {*}
43
+ */
44
+ static get routePath() {
45
+ return window.location.hash.replace('#', '');
46
+ }
47
+ /**
48
+ * 当前地址的全路径,包含域名和参数
49
+ * 如:http://172.16.103.120:30061/portalwebapp/#/index/appportalview?params=123
50
+ *
51
+ * @author lxm
52
+ * @date 2022-10-11 21:10:39
53
+ * @readonly
54
+ * @static
55
+ */
56
+ static get fullPath() {
57
+ return window.location.href;
58
+ }
59
+ }
@@ -1,4 +1,3 @@
1
- import { DebounceSettings } from 'lodash-es';
2
1
  /**
3
2
  * 获取认证令牌
4
3
  *
@@ -20,7 +19,8 @@ export declare function getToken(): string | null;
20
19
  */
21
20
  export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
22
21
  /**
23
- * 防抖并合并每次的参数
22
+ * 防抖并合并每次的参数,
23
+ * 最后一次才会执行
24
24
  *
25
25
  * @author lxm
26
26
  * @date 2022-09-20 21:09:53
@@ -32,8 +32,24 @@ export declare function isOverlap(arr1: any[], arr2: any[]): boolean;
32
32
  * newParams: Parameters<T>,
33
33
  * ) => Parameters<T>} mergeFunc 合并的回调函数
34
34
  * @param {number} [wait] 防抖的延迟毫秒数
35
- * @param {DebounceSettings} [options] 防抖函数的额外参数
36
35
  * @returns {*}
37
36
  */
38
- export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number, options?: DebounceSettings): (...args: Parameters<T>) => any;
37
+ export declare function debounceAndMerge<T extends (...args: any[]) => any>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): (...args: Parameters<T>) => any;
38
+ /**
39
+ * 防抖并合并每次的参数,最后一次才会执行
40
+ * 绑定方法为异步方法,给每次调用返回最终执行那次的结果
41
+ *
42
+ * @author lxm
43
+ * @date 2022-09-20 21:09:53
44
+ * @export
45
+ * @template T
46
+ * @param {T} func 要防抖的函数
47
+ * @param {(
48
+ * oldParams: Parameters<T>,
49
+ * newParams: Parameters<T>,
50
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
51
+ * @param {number} [wait] 防抖的延迟毫秒数
52
+ * @returns {*}
53
+ */
54
+ export declare function debounceAndAsyncMerge<T extends (...args: any[]) => Promise<any>>(func: T, mergeFunc: (oldParams: Parameters<T>, newParams: Parameters<T>) => Parameters<T>, wait?: number): T;
39
55
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AACA,OAAO,EAAY,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAIvD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAG3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,EACb,OAAO,CAAC,EAAE,gBAAgB,aAaT,WAAW,CAAC,CAAC,SAS/B"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../src/utils/util/util.ts"],"names":[],"mappings":"AAKA;;;;;;;GAOG;AACH,wBAAgB,QAAQ,IAAI,MAAM,GAAG,IAAI,CAExC;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAG3D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EAChE,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,aASI,WAAW,CAAC,CAAC,SAS/B;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CACnC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EAE1C,IAAI,EAAE,CAAC,EACP,SAAS,EAAE,CACT,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,EACxB,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,KACrB,UAAU,CAAC,CAAC,CAAC,EAClB,IAAI,CAAC,EAAE,MAAM,GACZ,CAAC,CAoCH"}
@@ -25,10 +25,11 @@ export function getToken() {
25
25
  */
26
26
  export function isOverlap(arr1, arr2) {
27
27
  const newArr = Array.from(new Set([...arr1, ...arr2]));
28
- return newArr.length === arr1.length + arr2.length;
28
+ return newArr.length !== arr1.length + arr2.length;
29
29
  }
30
30
  /**
31
- * 防抖并合并每次的参数
31
+ * 防抖并合并每次的参数,
32
+ * 最后一次才会执行
32
33
  *
33
34
  * @author lxm
34
35
  * @date 2022-09-20 21:09:53
@@ -40,17 +41,16 @@ export function isOverlap(arr1, arr2) {
40
41
  * newParams: Parameters<T>,
41
42
  * ) => Parameters<T>} mergeFunc 合并的回调函数
42
43
  * @param {number} [wait] 防抖的延迟毫秒数
43
- * @param {DebounceSettings} [options] 防抖函数的额外参数
44
44
  * @returns {*}
45
45
  */
46
- export function debounceAndMerge(func, mergeFunc, wait, options) {
46
+ export function debounceAndMerge(func, mergeFunc, wait) {
47
47
  // 缓存上一次的函数参数
48
48
  let oldParams;
49
49
  const debounceFunc = debounce((...params) => {
50
50
  // 防抖函数执行的时候清空缓存参数
51
51
  oldParams = undefined;
52
52
  return func(...params);
53
- }, wait, options);
53
+ }, wait);
54
54
  return (...args) => {
55
55
  // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
56
56
  let newParams = args;
@@ -61,3 +61,57 @@ export function debounceAndMerge(func, mergeFunc, wait, options) {
61
61
  return debounceFunc(...newParams);
62
62
  };
63
63
  }
64
+ /**
65
+ * 防抖并合并每次的参数,最后一次才会执行
66
+ * 绑定方法为异步方法,给每次调用返回最终执行那次的结果
67
+ *
68
+ * @author lxm
69
+ * @date 2022-09-20 21:09:53
70
+ * @export
71
+ * @template T
72
+ * @param {T} func 要防抖的函数
73
+ * @param {(
74
+ * oldParams: Parameters<T>,
75
+ * newParams: Parameters<T>,
76
+ * ) => Parameters<T>} mergeFunc 合并的回调函数
77
+ * @param {number} [wait] 防抖的延迟毫秒数
78
+ * @returns {*}
79
+ */
80
+ export function debounceAndAsyncMerge(func, mergeFunc, wait) {
81
+ // 缓存上一次的函数参数
82
+ let oldParams;
83
+ let promises = [];
84
+ const debounceFunc = debounce(async (...params) => {
85
+ // 防抖函数执行的时候清空缓存参数
86
+ oldParams = undefined;
87
+ try {
88
+ const result = await func(...params);
89
+ promises.forEach(promise => {
90
+ promise.resolve(result);
91
+ });
92
+ promises = [];
93
+ return result;
94
+ }
95
+ catch (error) {
96
+ promises.forEach(promise => {
97
+ promise.reject(error);
98
+ });
99
+ promises = [];
100
+ }
101
+ }, wait);
102
+ const fun = async (...args) => {
103
+ // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
104
+ let newParams = args;
105
+ if (oldParams) {
106
+ newParams = mergeFunc(oldParams, newParams);
107
+ }
108
+ oldParams = newParams;
109
+ // 执行防抖函数
110
+ debounceFunc(...newParams);
111
+ return new Promise((resolve, reject) => {
112
+ // 阻塞当前调用,当防抖函数被执行后返回
113
+ promises.push({ resolve, reject });
114
+ });
115
+ };
116
+ return fun;
117
+ }
package/package.json CHANGED
@@ -1,27 +1,37 @@
1
1
  {
2
2
  "name": "@ibiz-template/core",
3
- "version": "0.0.1-alpha.6",
3
+ "version": "0.0.1-beta.17",
4
4
  "description": "核心包",
5
+ "type": "module",
5
6
  "main": "out/index.js",
6
7
  "types": "out/index.d.ts",
8
+ "system": "./dist/system/index.system.js",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "https://gitee.com/iBizModeling/ibiz-template.git"
12
+ },
7
13
  "files": [
14
+ "dist",
8
15
  "out",
9
16
  "src"
10
17
  ],
11
18
  "scripts": {
12
19
  "dev": "tsc --watch",
13
- "build": "npm run lint && npm run clean && tsc --build",
20
+ "build": "npm run lint && npm run clean && npm run build:rollup && tsc --build",
21
+ "build:rollup": "rollup -c",
14
22
  "lint": "eslint 'src/**/*.ts'",
15
23
  "lint:fix": "eslint --fix 'src/**/*.ts'",
16
- "clean": "rimraf out",
24
+ "clean": "rimraf out dist",
17
25
  "test": "jest",
18
- "publish:next": "npm run build && npm publish --access public --tag next",
19
- "publish:npm": "npm run build && npm publish --access public"
26
+ "prepublish": "npm run build",
27
+ "publish:next": "npm publish --access public --tag next",
28
+ "publish:npm": "npm publish --access public"
20
29
  },
21
30
  "author": "chitanda",
22
31
  "license": "MIT",
23
32
  "dependencies": {
24
- "axios": "^0.27.2",
33
+ "axios": "^1.2.1",
34
+ "loglevel": "^1.8.0",
25
35
  "pluralize": "^8.0.0",
26
36
  "qs": "^6.11.0"
27
37
  },
@@ -29,11 +39,11 @@
29
39
  "@types/pluralize": "^0.0.29",
30
40
  "@types/qs": "^6.9.7",
31
41
  "lodash-es": "^4.17.21",
32
- "qx-util": "^0.4.1"
42
+ "qx-util": "^0.4.4"
33
43
  },
34
44
  "peerDependencies": {
35
45
  "lodash-es": "^4.17.21",
36
- "qx-util": "^0.4.1"
46
+ "qx-util": "^0.4.4"
37
47
  },
38
- "gitHead": "0af61790674d0f38ffcf2697fc8b2d2324507ce7"
48
+ "gitHead": "ec02483ab23e246c852c28e4973fd7b086416657"
39
49
  }