@ibiz-template/core 0.0.4-beta.5 → 0.1.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 (91) hide show
  1. package/dist/index.esm.js +427 -96
  2. package/dist/index.system.min.js +2 -1
  3. package/dist/index.system.min.js.map +1 -0
  4. package/out/constant/core/core.d.ts +2 -2
  5. package/out/constant/core/core.js +3 -4
  6. package/out/constant/util/util.d.ts.map +1 -1
  7. package/out/context/index.d.ts +17 -7
  8. package/out/context/index.d.ts.map +1 -1
  9. package/out/context/index.js +82 -40
  10. package/out/environment/environment.d.ts.map +1 -1
  11. package/out/environment/environment.js +5 -0
  12. package/out/error/model-error/model-error.d.ts +2 -2
  13. package/out/error/model-error/model-error.d.ts.map +1 -1
  14. package/out/error/model-error/model-error.js +0 -1
  15. package/out/error/runtime-model-error/runtime-model-error.d.ts +2 -2
  16. package/out/error/runtime-model-error/runtime-model-error.d.ts.map +1 -1
  17. package/out/error/runtime-model-error/runtime-model-error.js +0 -1
  18. package/out/ibizsys.d.ts +6 -4
  19. package/out/ibizsys.d.ts.map +1 -1
  20. package/out/ibizsys.js +6 -4
  21. package/out/index.d.ts +0 -1
  22. package/out/index.d.ts.map +1 -1
  23. package/out/index.js +0 -1
  24. package/out/install.d.ts.map +1 -1
  25. package/out/install.js +0 -2
  26. package/out/interface/i-environment/i-environment.d.ts +39 -0
  27. package/out/interface/i-environment/i-environment.d.ts.map +1 -1
  28. package/out/types.d.ts +11 -22
  29. package/out/types.d.ts.map +1 -1
  30. package/out/utils/download-file/download-file.d.ts.map +1 -1
  31. package/out/utils/index.d.ts +1 -1
  32. package/out/utils/index.d.ts.map +1 -1
  33. package/out/utils/index.js +1 -1
  34. package/out/utils/interceptor/core-interceptor.d.ts.map +1 -1
  35. package/out/utils/interceptor/core-interceptor.js +6 -2
  36. package/out/utils/interceptor/interceptor.d.ts +2 -2
  37. package/out/utils/interceptor/interceptor.d.ts.map +1 -1
  38. package/out/utils/logger/logger.d.ts +2 -2
  39. package/out/utils/logger/logger.d.ts.map +1 -1
  40. package/out/utils/logger/logger.js +5 -1
  41. package/out/utils/namespace/namespace.d.ts.map +1 -1
  42. package/out/utils/net/net.d.ts +12 -2
  43. package/out/utils/net/net.d.ts.map +1 -1
  44. package/out/utils/net/net.js +31 -5
  45. package/out/utils/recursive/find-recursive-child.d.ts +43 -0
  46. package/out/utils/recursive/find-recursive-child.d.ts.map +1 -0
  47. package/out/utils/recursive/find-recursive-child.js +90 -0
  48. package/out/utils/string-util/string-util.js +1 -2
  49. package/out/utils/style/remote-style.d.ts.map +1 -1
  50. package/out/utils/style/remote-style.js +1 -2
  51. package/out/utils/sync/count-latch.d.ts.map +1 -1
  52. package/out/utils/upload/select-file.d.ts.map +1 -1
  53. package/out/utils/upload/select-file.js +1 -1
  54. package/out/utils/upload/upload-file.d.ts.map +1 -1
  55. package/out/utils/upload/upload-file.js +2 -1
  56. package/out/utils/url-helper/url-helper.d.ts.map +1 -1
  57. package/out/utils/util/util.d.ts +58 -0
  58. package/out/utils/util/util.d.ts.map +1 -1
  59. package/out/utils/util/util.js +123 -0
  60. package/package.json +9 -8
  61. package/src/constant/core/core.ts +2 -2
  62. package/src/constant/util/util.ts +1 -1
  63. package/src/context/index.ts +91 -47
  64. package/src/environment/environment.ts +5 -0
  65. package/src/error/model-error/model-error.ts +4 -2
  66. package/src/error/runtime-model-error/runtime-model-error.ts +4 -2
  67. package/src/ibizsys.ts +7 -4
  68. package/src/index.ts +0 -1
  69. package/src/install.ts +0 -2
  70. package/src/interface/i-environment/i-environment.ts +44 -0
  71. package/src/types.ts +12 -23
  72. package/src/utils/click-outside/click-outside.ts +6 -6
  73. package/src/utils/download-file/download-file.ts +2 -2
  74. package/src/utils/event/event.ts +1 -1
  75. package/src/utils/index.ts +1 -1
  76. package/src/utils/interceptor/core-interceptor.ts +7 -2
  77. package/src/utils/interceptor/interceptor.ts +3 -3
  78. package/src/utils/logger/logger.ts +8 -1
  79. package/src/utils/namespace/namespace.ts +4 -1
  80. package/src/utils/net/net.ts +35 -11
  81. package/src/utils/recursive/find-recursive-child.ts +133 -0
  82. package/src/utils/style/remote-style.ts +1 -3
  83. package/src/utils/sync/count-latch.ts +5 -5
  84. package/src/utils/upload/select-file.ts +2 -2
  85. package/src/utils/upload/upload-file.ts +6 -5
  86. package/src/utils/url-helper/url-helper.ts +4 -4
  87. package/src/utils/util/util.ts +144 -2
  88. package/out/factory-center.d.ts +0 -11
  89. package/out/factory-center.d.ts.map +0 -1
  90. package/out/factory-center.js +0 -10
  91. package/src/factory-center.ts +0 -9
@@ -0,0 +1,133 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ import { mergeDeepRight } from 'ramda';
3
+
4
+ /** 默认配置参数 */
5
+ const IterateOpts = {
6
+ /** 子集合属性数组 */
7
+ childrenFields: ['children'],
8
+ };
9
+
10
+ const BreakError = new Error('中断操作');
11
+
12
+ /**
13
+ * 获取子属性集合
14
+ * @author lxm
15
+ * @date 2023-04-20 08:54:32
16
+ * @param {IData} parent
17
+ * @param {string[]} fields 子集合可能的属性名称
18
+ * @return {*} {(IData[] | undefined)}
19
+ */
20
+ function getChildField(parent: IData, fields: string[]): IData[] | undefined {
21
+ for (const field of fields) {
22
+ if (parent[field]?.length) {
23
+ return parent[field];
24
+ }
25
+ }
26
+ }
27
+
28
+ function _recursiveIterate(
29
+ parent: IData,
30
+ callback: (item: any) => boolean | void,
31
+ opts?: Partial<typeof IterateOpts>,
32
+ ): void {
33
+ const { childrenFields } = mergeDeepRight(IterateOpts, opts || {});
34
+ const children = getChildField(parent, childrenFields);
35
+ if (children?.length) {
36
+ for (const child of children) {
37
+ // 递归自身的子成员
38
+ const isBreak = callback(child);
39
+ // 如果回调返回true则退出
40
+ if (isBreak) {
41
+ throw BreakError;
42
+ }
43
+
44
+ // 递归孙的成员
45
+ recursiveIterate(child, callback, opts);
46
+ }
47
+ }
48
+ }
49
+
50
+ /**
51
+ * 递归遍历子元素
52
+ * @author lxm
53
+ * @date 2023-04-23 09:07:06
54
+ * @export
55
+ * @param {IData} parent 父元素
56
+ * @param {(item: any) => boolean} callback 每一个子元素的回调
57
+ * @param {Partial<typeof IterateOpts>} [opts]
58
+ */
59
+ export function recursiveIterate(
60
+ parent: IData,
61
+ callback: (item: any) => boolean | void,
62
+ opts?: Partial<typeof IterateOpts>,
63
+ ): void {
64
+ try {
65
+ _recursiveIterate(parent, callback, opts);
66
+ } catch (error) {
67
+ if (error !== BreakError) {
68
+ throw error;
69
+ }
70
+ }
71
+ }
72
+
73
+ /** 默认配置参数 */
74
+ const CompareOpts = {
75
+ ...IterateOpts,
76
+ /** 比较的属性 */
77
+ compareField: 'name',
78
+ };
79
+
80
+ type ICompareOpts = Partial<typeof CompareOpts> & {
81
+ /**
82
+ * 自定义比较回调
83
+ * @author lxm
84
+ * @date 2023-04-23 09:06:42
85
+ */
86
+ compareCallback?: (
87
+ child: IData,
88
+ key: string,
89
+ compareField: string,
90
+ ) => boolean;
91
+ };
92
+
93
+ /**
94
+ * 递归查找子元素
95
+ * @author lxm
96
+ * @date 2023-04-20 08:53:35
97
+ * @export
98
+ * @param {IData} parent 父对象
99
+ * @param {string} key 子元素的比较属性的值
100
+ * @param {ICompareOpts} [opts]
101
+ * @return {*} {(IData | undefined)}
102
+ */
103
+ export function findRecursiveChild(
104
+ parent: IData,
105
+ key: string,
106
+ opts?: ICompareOpts,
107
+ ): IData | undefined {
108
+ const { compareField, compareCallback } = mergeDeepRight(
109
+ CompareOpts,
110
+ opts || {},
111
+ );
112
+
113
+ // 默认比较方法
114
+ const _compareCallback =
115
+ compareCallback ||
116
+ ((child: IData): boolean => {
117
+ return child[compareField] === key;
118
+ });
119
+
120
+ // 递归遍历,找到后中断遍历,返回找到项
121
+ let find;
122
+ recursiveIterate(
123
+ parent,
124
+ item => {
125
+ if (_compareCallback(item, key, compareField)) {
126
+ find = item;
127
+ return true;
128
+ }
129
+ },
130
+ opts,
131
+ );
132
+ return find;
133
+ }
@@ -1,5 +1,3 @@
1
- import { Logger } from '../logger/logger';
2
-
3
1
  /**
4
2
  * 设置远程样式表
5
3
  *
@@ -17,6 +15,6 @@ export async function setRemoteStyle(url: string): Promise<void> {
17
15
  styleDom.innerText = res.data as unknown as string;
18
16
  document.head.appendChild(styleDom);
19
17
  } catch (error) {
20
- Logger.debug('加载远程样式表失败', url);
18
+ ibiz.log.debug('加载远程样式表失败', url);
21
19
  }
22
20
  }
@@ -29,7 +29,7 @@ export class CountLatch {
29
29
  * @date 2022-11-24 19:11:32
30
30
  * @private
31
31
  */
32
- private startPromise() {
32
+ private startPromise(): void {
33
33
  this.promise = new Promise(resolve => {
34
34
  this.resolve = resolve;
35
35
  });
@@ -42,7 +42,7 @@ export class CountLatch {
42
42
  * @date 2022-11-24 19:11:44
43
43
  * @private
44
44
  */
45
- private endPromise() {
45
+ private endPromise(): void {
46
46
  if (this.resolve) {
47
47
  this.resolve();
48
48
  this.resolve = null;
@@ -57,7 +57,7 @@ export class CountLatch {
57
57
  * @author lxm
58
58
  * @date 2022-11-24 19:11:27
59
59
  */
60
- lock() {
60
+ lock(): void {
61
61
  this.count += 1;
62
62
  if (!this.promise) {
63
63
  this.startPromise();
@@ -71,7 +71,7 @@ export class CountLatch {
71
71
  * @author lxm
72
72
  * @date 2022-11-24 19:11:47
73
73
  */
74
- unlock() {
74
+ unlock(): void {
75
75
  if (this.count < 1) {
76
76
  throw new RuntimeError('lock和unlock次数不匹配!');
77
77
  }
@@ -87,7 +87,7 @@ export class CountLatch {
87
87
  * @author lxm
88
88
  * @date 2022-11-24 19:11:20
89
89
  */
90
- async await() {
90
+ async await(): Promise<void> {
91
91
  if (this.promise) {
92
92
  await this.promise;
93
93
  }
@@ -59,7 +59,7 @@ export interface SelectFileOpts {
59
59
  * @export
60
60
  * @param {SelectFileOpts} _opts 配置参数
61
61
  */
62
- export function selectFile(_opts: SelectFileOpts) {
62
+ export function selectFile(_opts: SelectFileOpts): void {
63
63
  const opts: Required<SelectFileOpts> = merge(
64
64
  {
65
65
  multiple: true,
@@ -71,7 +71,7 @@ export function selectFile(_opts: SelectFileOpts) {
71
71
  input.setAttribute('type', 'file');
72
72
  input.setAttribute('multiple', `${opts.multiple}`);
73
73
  input.setAttribute('accept', opts.accept);
74
- input.onchange = e => {
74
+ input.onchange = (e): void => {
75
75
  const inputEl = e.target as HTMLInputElement;
76
76
  const files = inputEl.files ? fileListToArr(inputEl.files) : [];
77
77
  if (files.length === 0) {
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-empty-function */
2
2
  /* eslint-disable no-param-reassign */
3
3
  import { cloneDeep, isFunction, merge, round, uniqueId } from 'lodash-es';
4
+ import { RuntimeError } from '../../error';
4
5
  import { HttpResponse } from '../net/http-response';
5
6
  import { selectFile } from './select-file';
6
7
 
@@ -49,7 +50,7 @@ export interface IUploadFileOpts {
49
50
  * @param {IUploadFileOpts} _opts
50
51
  * @returns {*}
51
52
  */
52
- export function uploadFile(_opts: IUploadFileOpts) {
53
+ export function uploadFile(_opts: IUploadFileOpts): void {
53
54
  const opts: Required<IUploadFileOpts> = merge(
54
55
  {
55
56
  multiple: true,
@@ -72,7 +73,7 @@ export function uploadFile(_opts: IUploadFileOpts) {
72
73
  * @param {IParams} event
73
74
  * @param {IUploadFile[]} files
74
75
  */
75
- const onUploadProgress = (event: IParams, files: IUploadFile[]) => {
76
+ const onUploadProgress = (event: IParams, files: IUploadFile[]): void => {
76
77
  files.forEach(file => {
77
78
  file.percentage = round(event.progress * 100);
78
79
  });
@@ -109,7 +110,7 @@ export function uploadFile(_opts: IUploadFileOpts) {
109
110
  // onUploadProgress: onProgress,
110
111
  // });
111
112
  // return res;
112
- throw new Error(`多应用模式等待重新实现请求`);
113
+ throw new RuntimeError(`多应用模式等待重新实现请求`);
113
114
  };
114
115
 
115
116
  /**
@@ -174,7 +175,7 @@ export function uploadFile(_opts: IUploadFileOpts) {
174
175
  * @date 2022-11-18 13:11:21
175
176
  * @param {files} File[] 文件集合
176
177
  */
177
- const uploadFiles = async (files: File[]) => {
178
+ const uploadFiles = async (files: File[]): Promise<void> => {
178
179
  const uploadSequence = opts.separate ? files.map(file => [file]) : [files];
179
180
  const res = await Promise.allSettled(
180
181
  uploadSequence.map(async sequence => {
@@ -193,7 +194,7 @@ export function uploadFile(_opts: IUploadFileOpts) {
193
194
  opts.finish(resultFiles);
194
195
  };
195
196
 
196
- const select = () => {
197
+ const select = (): void => {
197
198
  selectFile({
198
199
  accept: opts.accept,
199
200
  multiple: opts.multiple,
@@ -16,7 +16,7 @@ export class UrlHelper {
16
16
  * @date 2022-10-11 20:10:29
17
17
  * @returns {*}
18
18
  */
19
- static get routeBase() {
19
+ static get routeBase(): string {
20
20
  const hashIndex = window.location.href.lastIndexOf('#/');
21
21
  return window.location.href.slice(0, hashIndex + 1);
22
22
  }
@@ -30,7 +30,7 @@ export class UrlHelper {
30
30
  * @date 2022-10-11 20:10:29
31
31
  * @returns {*}
32
32
  */
33
- static get appBase() {
33
+ static get appBase(): string {
34
34
  const { origin, pathname } = window.location;
35
35
  return `${origin}${pathname}`.replace(/\/$/, '');
36
36
  }
@@ -44,7 +44,7 @@ export class UrlHelper {
44
44
  * @date 2022-10-11 16:10:40
45
45
  * @returns {*}
46
46
  */
47
- static get routePath() {
47
+ static get routePath(): string {
48
48
  return window.location.hash.replace('#', '');
49
49
  }
50
50
 
@@ -57,7 +57,7 @@ export class UrlHelper {
57
57
  * @readonly
58
58
  * @static
59
59
  */
60
- static get fullPath() {
60
+ static get fullPath(): string {
61
61
  return window.location.href;
62
62
  }
63
63
  }
@@ -1,6 +1,7 @@
1
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
2
2
  import { debounce } from 'lodash-es';
3
3
  import { getCookie } from 'qx-util';
4
+ import { isNotNil, isNil } from 'ramda';
4
5
  import { CoreConst } from '../../constant';
5
6
 
6
7
  /**
@@ -30,6 +31,32 @@ export function isOverlap(arr1: any[], arr2: any[]): boolean {
30
31
  return newArr.length !== arr1.length + arr2.length;
31
32
  }
32
33
 
34
+ /**
35
+ * 是否元素相同
36
+ * @author lxm
37
+ * @date 2023-05-22 12:50:53
38
+ * @export
39
+ * @param {any[]} arr1
40
+ * @param {any[]} arr2
41
+ * @param {string} [field] 比较元素里的某个固定属性
42
+ * @return {*} {boolean}
43
+ */
44
+ export function isElementSame(
45
+ arr1: any[],
46
+ arr2: any[],
47
+ field?: string,
48
+ ): boolean {
49
+ if (arr1.length !== arr2.length) {
50
+ return false;
51
+ }
52
+ const allElements = field
53
+ ? [...arr1.map(item => item[field]), ...arr2.map(item => item[field])]
54
+ : [...arr1, ...arr2];
55
+
56
+ const newArr = Array.from(new Set(allElements));
57
+ return newArr.length === arr1.length;
58
+ }
59
+
33
60
  /**
34
61
  * 防抖并合并每次的参数,
35
62
  * 最后一次才会执行
@@ -53,7 +80,7 @@ export function debounceAndMerge<T extends (...args: any[]) => any>(
53
80
  newParams: Parameters<T>,
54
81
  ) => Parameters<T>,
55
82
  wait?: number,
56
- ) {
83
+ ): (...args: Parameters<T>) => any {
57
84
  // 缓存上一次的函数参数
58
85
  let oldParams: Parameters<T> | undefined;
59
86
  const debounceFunc = debounce((...params: Parameters<T>) => {
@@ -118,7 +145,7 @@ export function debounceAndAsyncMerge<
118
145
  promises = [];
119
146
  }
120
147
  }, wait);
121
- const fun = async (...args: Parameters<T>) => {
148
+ const fun = async (...args: Parameters<T>): Promise<unknown> => {
122
149
  // 合并参数,并把参数缓存到oldParams里,用新参数调用防抖函数
123
150
  let newParams = args;
124
151
  if (oldParams) {
@@ -134,3 +161,118 @@ export function debounceAndAsyncMerge<
134
161
  };
135
162
  return fun as T;
136
163
  }
164
+
165
+ /**
166
+ * 把右侧的对象里非空的属性合并到左侧对象里
167
+ * @author lxm
168
+ * @date 2023-05-16 02:23:39
169
+ * @param {IData} l
170
+ * @param {IData} r
171
+ */
172
+ export function mergeInLeft(l: IData, r: IData): void {
173
+ Object.keys(r).forEach(key => {
174
+ if (isNotNil(r[key])) {
175
+ l[key] = r[key];
176
+ }
177
+ });
178
+ }
179
+
180
+ /**
181
+ * 把右侧的对象里非空的属性合并到左侧对象属性为空里
182
+ *
183
+ * @author zk
184
+ * @date 2023-06-01 02:06:36
185
+ * @export
186
+ * @param {IData} l
187
+ * @param {IData} r
188
+ */
189
+ export function mergeDefaultInLeft(l: IData, r: IData): void {
190
+ Object.keys(r).forEach(key => {
191
+ if (isNotNil(r[key]) && isNil(l[key])) {
192
+ l[key] = r[key];
193
+ }
194
+ });
195
+ }
196
+
197
+ /**
198
+ * 比较两个数组集合,找出相同和不同的元素
199
+ * @author lxm
200
+ * @date 2023-05-29 12:33:55
201
+ * @export
202
+ * @param {IData[]} arr1 数组一
203
+ * @param {IData[]} arr2 数组二
204
+ * @param {string} [keyField] 主键属性,有主键比较主键
205
+ * @return {*} {{
206
+ * more: IData[]; arr1多的元素
207
+ * less: IData[]; arr1少的元素
208
+ * same: IData[]; 相同的元素
209
+ * }}
210
+ */
211
+ export function compareArr(
212
+ arr1: IData[],
213
+ arr2: IData[],
214
+ keyField?: string,
215
+ ): {
216
+ more: IData[];
217
+ less: IData[];
218
+ same: IData[];
219
+ } {
220
+ const all = new Set([...arr1, ...arr2]);
221
+ const more: IData[] = [];
222
+ const less: IData[] = [];
223
+ const same: IData[] = [];
224
+
225
+ if (keyField) {
226
+ const arr1Keys = arr1.map(item => item[keyField]);
227
+ const arr2Keys = arr2.map(item => item[keyField]);
228
+ all.forEach(item => {
229
+ if (!arr1Keys.includes(item[keyField])) {
230
+ less.push(item);
231
+ return;
232
+ }
233
+ if (!arr2Keys.includes(item[keyField])) {
234
+ more.push(item);
235
+ return;
236
+ }
237
+ same.push(item);
238
+ });
239
+ } else {
240
+ all.forEach(item => {
241
+ if (!arr1.includes(item)) {
242
+ less.push(item);
243
+ return;
244
+ }
245
+ if (!arr2.includes(item)) {
246
+ more.push(item);
247
+ return;
248
+ }
249
+ same.push(item);
250
+ });
251
+ }
252
+
253
+ return {
254
+ more,
255
+ less,
256
+ same,
257
+ };
258
+ }
259
+
260
+ /**
261
+ * 转换为数字或undefined
262
+ * - 如果是undefined或null 返回undefined
263
+ * - 其他情况转成数字,能转成数字的返回数字,NaN的返回undefined
264
+ * @author lxm
265
+ * @date 2023-06-08 06:30:57
266
+ * @param {unknown} value 值
267
+ * @return {*} {(number | undefined)}
268
+ */
269
+ export function toNumberOrNil(value: unknown): number | undefined {
270
+ if (isNil(value)) {
271
+ return undefined;
272
+ }
273
+ const num = Number(value);
274
+ if (Number.isNaN(num)) {
275
+ return undefined;
276
+ }
277
+ return num;
278
+ }
@@ -1,11 +0,0 @@
1
- /**
2
- * 工厂类挂载中心,挂载各种解耦用创建工厂
3
- *
4
- * @author lxm
5
- * @date 2022-10-17 15:10:04
6
- * @export
7
- * @class FactoryCenter
8
- */
9
- export declare class FactoryCenter {
10
- }
11
- //# sourceMappingURL=factory-center.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"factory-center.d.ts","sourceRoot":"","sources":["../src/factory-center.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,qBAAa,aAAa;CAAG"}
@@ -1,10 +0,0 @@
1
- /**
2
- * 工厂类挂载中心,挂载各种解耦用创建工厂
3
- *
4
- * @author lxm
5
- * @date 2022-10-17 15:10:04
6
- * @export
7
- * @class FactoryCenter
8
- */
9
- export class FactoryCenter {
10
- }
@@ -1,9 +0,0 @@
1
- /**
2
- * 工厂类挂载中心,挂载各种解耦用创建工厂
3
- *
4
- * @author lxm
5
- * @date 2022-10-17 15:10:04
6
- * @export
7
- * @class FactoryCenter
8
- */
9
- export class FactoryCenter {}