@yelon/util 12.0.10 → 12.0.11
Sign up to get free protection for your applications and to get access to all the features.
- package/LICENSE +21 -21
- package/array/array-type.service.d.ts +68 -68
- package/array/array.service.d.ts +75 -75
- package/array/index.d.ts +2 -2
- package/array/yelon-util-array.d.ts +4 -4
- package/browser/browser.d.ts +4 -4
- package/browser/cookie.service.d.ts +64 -64
- package/browser/copy.d.ts +6 -6
- package/browser/index.d.ts +5 -5
- package/browser/is-empty.d.ts +6 -6
- package/browser/scroll.service.d.ts +34 -34
- package/browser/style.d.ts +21 -21
- package/bundles/browser.umd.js +275 -275
- package/bundles/yelon-util-array.umd.js +602 -602
- package/bundles/yelon-util-config.umd.js +366 -366
- package/bundles/yelon-util-date-time.umd.js +216 -216
- package/bundles/yelon-util-decorator.umd.js +437 -437
- package/bundles/yelon-util-form.umd.js +116 -116
- package/bundles/yelon-util-format.umd.js +726 -726
- package/bundles/yelon-util-math.umd.js +83 -83
- package/bundles/yelon-util-other.umd.js +655 -655
- package/bundles/yelon-util-pipes-currency.umd.js +83 -83
- package/bundles/yelon-util-pipes-filter.umd.js +353 -353
- package/bundles/yelon-util-pipes-format.umd.js +47 -47
- package/bundles/yelon-util-pipes.umd.js +7 -7
- package/bundles/yelon-util-token.umd.js +30 -30
- package/bundles/yelon-util.umd.js +7 -7
- package/config/abc/date-picker.type.d.ts +52 -52
- package/config/abc/error-collect.type.d.ts +10 -10
- package/config/abc/image.type.d.ts +15 -15
- package/config/abc/index.d.ts +16 -16
- package/config/abc/loading.type.d.ts +31 -31
- package/config/abc/lodop.type.d.ts +33 -33
- package/config/abc/media.type.d.ts +11 -11
- package/config/abc/onboarding.type.d.ts +4 -4
- package/config/abc/page-header.type.d.ts +39 -39
- package/config/abc/pdf.type.d.ts +35 -35
- package/config/abc/qr.type.d.ts +25 -25
- package/config/abc/se.type.d.ts +32 -32
- package/config/abc/sg.type.d.ts +10 -10
- package/config/abc/st.type.d.ts +431 -431
- package/config/abc/sv.type.d.ts +14 -14
- package/config/abc/xlsx.type.d.ts +12 -12
- package/config/abc/zip.type.d.ts +10 -10
- package/config/acl/acl.type.d.ts +32 -32
- package/config/auth/auth.type.d.ts +55 -55
- package/config/bis/bis.type.d.ts +7 -7
- package/config/cache/cache.type.d.ts +40 -40
- package/config/chart/chart.type.d.ts +33 -33
- package/config/config.service.d.ts +10 -10
- package/config/config.types.d.ts +49 -49
- package/config/index.d.ts +14 -14
- package/config/mock/mock.type.d.ts +18 -18
- package/config/sf/sf.type.d.ts +127 -127
- package/config/stomp/stomp.type.d.ts +2 -2
- package/config/theme/http.type.d.ts +14 -14
- package/config/theme/i18n.type.d.ts +8 -8
- package/config/theme/index.d.ts +3 -3
- package/config/theme/responsive.type.d.ts +12 -12
- package/config/util/array.type.d.ts +22 -22
- package/config/util/currency.type.d.ts +39 -39
- package/config/yelon-util-config.d.ts +4 -4
- package/date-time/index.d.ts +2 -2
- package/date-time/picker.d.ts +68 -68
- package/date-time/time.d.ts +26 -26
- package/date-time/yelon-util-date-time.d.ts +4 -4
- package/decorator/convert.d.ts +24 -24
- package/decorator/index.d.ts +2 -2
- package/decorator/yelon-util-decorator.d.ts +4 -4
- package/decorator/zone-outside.d.ts +35 -35
- package/esm2015/array/array-type.service.js +1 -1
- package/esm2015/array/array.service.js +249 -249
- package/esm2015/array/index.js +2 -2
- package/esm2015/array/yelon-util-array.js +4 -4
- package/esm2015/browser/browser.js +4 -4
- package/esm2015/browser/cookie.service.js +103 -103
- package/esm2015/browser/copy.js +26 -26
- package/esm2015/browser/index.js +5 -5
- package/esm2015/browser/is-empty.js +18 -18
- package/esm2015/browser/scroll.service.js +88 -88
- package/esm2015/browser/style.js +37 -37
- package/esm2015/config/abc/date-picker.type.js +1 -1
- package/esm2015/config/abc/error-collect.type.js +1 -1
- package/esm2015/config/abc/image.type.js +1 -1
- package/esm2015/config/abc/index.js +16 -16
- package/esm2015/config/abc/loading.type.js +1 -1
- package/esm2015/config/abc/lodop.type.js +1 -1
- package/esm2015/config/abc/media.type.js +1 -1
- package/esm2015/config/abc/onboarding.type.js +1 -1
- package/esm2015/config/abc/page-header.type.js +1 -1
- package/esm2015/config/abc/pdf.type.js +1 -1
- package/esm2015/config/abc/qr.type.js +1 -1
- package/esm2015/config/abc/se.type.js +1 -1
- package/esm2015/config/abc/sg.type.js +1 -1
- package/esm2015/config/abc/st.type.js +1 -1
- package/esm2015/config/abc/sv.type.js +2 -2
- package/esm2015/config/abc/xlsx.type.js +1 -1
- package/esm2015/config/abc/zip.type.js +1 -1
- package/esm2015/config/acl/acl.type.js +1 -1
- package/esm2015/config/auth/auth.type.js +1 -1
- package/esm2015/config/bis/bis.type.js +1 -1
- package/esm2015/config/cache/cache.type.js +1 -1
- package/esm2015/config/chart/chart.type.js +1 -1
- package/esm2015/config/config.service.js +33 -33
- package/esm2015/config/config.types.js +8 -8
- package/esm2015/config/index.js +14 -14
- package/esm2015/config/mock/mock.type.js +1 -1
- package/esm2015/config/sf/sf.type.js +1 -1
- package/esm2015/config/stomp/stomp.type.js +1 -1
- package/esm2015/config/theme/http.type.js +1 -1
- package/esm2015/config/theme/i18n.type.js +1 -1
- package/esm2015/config/theme/index.js +3 -3
- package/esm2015/config/theme/responsive.type.js +1 -1
- package/esm2015/config/util/array.type.js +1 -1
- package/esm2015/config/util/currency.type.js +1 -1
- package/esm2015/config/yelon-util-config.js +4 -4
- package/esm2015/date-time/index.js +2 -2
- package/esm2015/date-time/picker.js +115 -115
- package/esm2015/date-time/time.js +83 -83
- package/esm2015/date-time/yelon-util-date-time.js +4 -4
- package/esm2015/decorator/convert.js +55 -55
- package/esm2015/decorator/index.js +2 -2
- package/esm2015/decorator/yelon-util-decorator.js +4 -4
- package/esm2015/decorator/zone-outside.js +54 -54
- package/esm2015/form/index.js +2 -2
- package/esm2015/form/match-control.js +29 -29
- package/esm2015/form/validators.js +80 -80
- package/esm2015/form/yelon-util-form.js +4 -4
- package/esm2015/format/currency.service.js +224 -224
- package/esm2015/format/currency.types.js +7 -7
- package/esm2015/format/index.js +4 -4
- package/esm2015/format/string.js +75 -75
- package/esm2015/format/validate.js +93 -93
- package/esm2015/format/yelon-util-format.js +4 -4
- package/esm2015/index.js +11 -11
- package/esm2015/math/in-range.js +24 -24
- package/esm2015/math/index.js +2 -2
- package/esm2015/math/round.js +52 -52
- package/esm2015/math/yelon-util-math.js +4 -4
- package/esm2015/other/assert.js +66 -66
- package/esm2015/other/deep.js +75 -75
- package/esm2015/other/index.js +4 -4
- package/esm2015/other/lazy.service.js +117 -117
- package/esm2015/other/logger.js +35 -35
- package/esm2015/other/yelon-util-other.js +4 -4
- package/esm2015/pipes/currency/cny.pipe.js +21 -21
- package/esm2015/pipes/currency/index.js +3 -3
- package/esm2015/pipes/currency/mega.pipe.js +25 -25
- package/esm2015/pipes/currency/module.js +13 -13
- package/esm2015/pipes/currency/price.pipe.js +25 -25
- package/esm2015/pipes/currency/yelon-util-pipes-currency.js +5 -5
- package/esm2015/pipes/filter/filter.pipe.js +14 -14
- package/esm2015/pipes/filter/index.js +2 -2
- package/esm2015/pipes/filter/module.js +11 -11
- package/esm2015/pipes/filter/yelon-util-pipes-filter.js +4 -4
- package/esm2015/pipes/format/index.js +2 -2
- package/esm2015/pipes/format/mask.pipe.js +29 -29
- package/esm2015/pipes/format/module.js +11 -11
- package/esm2015/pipes/format/yelon-util-pipes-format.js +4 -4
- package/esm2015/pipes/index.js +3 -3
- package/esm2015/pipes/yelon-util-pipes.js +4 -4
- package/esm2015/token/index.js +2 -2
- package/esm2015/token/page-visibility.js +15 -15
- package/esm2015/token/window.js +16 -16
- package/esm2015/token/yelon-util-token.js +4 -4
- package/esm2015/yelon-util.js +4 -4
- package/fesm2015/browser.js +257 -257
- package/fesm2015/yelon-util-array.js +245 -245
- package/fesm2015/yelon-util-config.js +36 -36
- package/fesm2015/yelon-util-date-time.js +196 -196
- package/fesm2015/yelon-util-decorator.js +107 -107
- package/fesm2015/yelon-util-form.js +108 -108
- package/fesm2015/yelon-util-format.js +390 -390
- package/fesm2015/yelon-util-math.js +75 -75
- package/fesm2015/yelon-util-other.js +283 -283
- package/fesm2015/yelon-util-pipes-currency.js +72 -72
- package/fesm2015/yelon-util-pipes-filter.js +22 -22
- package/fesm2015/yelon-util-pipes-format.js +36 -36
- package/fesm2015/yelon-util-pipes.js +2 -2
- package/fesm2015/yelon-util-token.js +25 -25
- package/fesm2015/yelon-util.js +2 -2
- package/form/index.d.ts +2 -2
- package/form/match-control.d.ts +15 -15
- package/form/validators.d.ts +62 -62
- package/form/yelon-util-form.d.ts +4 -4
- package/format/currency.service.d.ts +34 -34
- package/format/currency.types.d.ts +77 -77
- package/format/index.d.ts +4 -4
- package/format/string.d.ts +44 -44
- package/format/validate.d.ts +72 -72
- package/format/yelon-util-format.d.ts +4 -4
- package/index.d.ts +11 -11
- package/math/in-range.d.ts +14 -14
- package/math/index.d.ts +2 -2
- package/math/round.d.ts +33 -33
- package/math/yelon-util-math.d.ts +4 -4
- package/other/assert.d.ts +36 -36
- package/other/deep.d.ts +33 -33
- package/other/index.d.ts +4 -4
- package/other/lazy.service.d.ts +22 -22
- package/other/logger.d.ts +6 -6
- package/other/yelon-util-other.d.ts +4 -4
- package/package.json +1 -1
- package/pipes/currency/cny.pipe.d.ts +12 -12
- package/pipes/currency/index.d.ts +3 -3
- package/pipes/currency/mega.pipe.d.ts +13 -13
- package/pipes/currency/module.d.ts +2 -2
- package/pipes/currency/price.pipe.d.ts +16 -16
- package/pipes/currency/yelon-util-pipes-currency.d.ts +5 -5
- package/pipes/filter/filter.pipe.d.ts +10 -10
- package/pipes/filter/index.d.ts +2 -2
- package/pipes/filter/module.d.ts +2 -2
- package/pipes/filter/yelon-util-pipes-filter.d.ts +4 -4
- package/pipes/format/index.d.ts +2 -2
- package/pipes/format/mask.pipe.d.ts +24 -24
- package/pipes/format/module.d.ts +2 -2
- package/pipes/format/yelon-util-pipes-format.d.ts +4 -4
- package/pipes/index.d.ts +3 -3
- package/pipes/yelon-util-pipes.d.ts +4 -4
- package/token/index.d.ts +2 -2
- package/token/page-visibility.d.ts +8 -8
- package/token/window.d.ts +7 -7
- package/token/yelon-util-token.d.ts +4 -4
- package/yelon-util.d.ts +4 -4
@@ -4,253 +4,253 @@ import { NzTreeNode } from 'ng-zorro-antd/core/tree';
|
|
4
4
|
import * as i1 from '@yelon/util/config';
|
5
5
|
import { YunzaiConfigService } from '@yelon/util/config';
|
6
6
|
|
7
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
8
|
-
class ArrayService {
|
9
|
-
constructor(cog) {
|
10
|
-
this.c = cog.merge('utilArray', {
|
11
|
-
deepMapName: 'deep',
|
12
|
-
parentMapName: 'parent',
|
13
|
-
idMapName: 'id',
|
14
|
-
parentIdMapName: 'parent_id',
|
15
|
-
childrenMapName: 'children',
|
16
|
-
titleMapName: 'title',
|
17
|
-
checkedMapname: 'checked',
|
18
|
-
selectedMapname: 'selected',
|
19
|
-
expandedMapname: 'expanded',
|
20
|
-
disabledMapname: 'disabled'
|
21
|
-
});
|
22
|
-
}
|
23
|
-
/**
|
24
|
-
* Convert tree structure to array structure
|
25
|
-
*
|
26
|
-
* 将树结构转换成数组结构
|
27
|
-
*/
|
28
|
-
treeToArr(tree, options) {
|
29
|
-
const opt = Object.assign({ deepMapName: this.c.deepMapName, parentMapName: this.c.parentMapName, childrenMapName: this.c.childrenMapName, clearChildren: true, cb: null }, options);
|
30
|
-
const result = [];
|
31
|
-
const inFn = (list, parent, deep = 0) => {
|
32
|
-
for (const i of list) {
|
33
|
-
i[opt.deepMapName] = deep;
|
34
|
-
i[opt.parentMapName] = parent;
|
35
|
-
if (opt.cb) {
|
36
|
-
opt.cb(i, parent, deep);
|
37
|
-
}
|
38
|
-
result.push(i);
|
39
|
-
const children = i[opt.childrenMapName];
|
40
|
-
if (children != null && Array.isArray(children) && children.length > 0) {
|
41
|
-
inFn(children, i, deep + 1);
|
42
|
-
}
|
43
|
-
if (opt.clearChildren) {
|
44
|
-
delete i[opt.childrenMapName];
|
45
|
-
}
|
46
|
-
}
|
47
|
-
};
|
48
|
-
inFn(tree, null);
|
49
|
-
return result;
|
50
|
-
}
|
51
|
-
/**
|
52
|
-
* Convert array structure to tree structure
|
53
|
-
*
|
54
|
-
* 数组转换成树数据
|
55
|
-
*/
|
56
|
-
arrToTree(arr, options) {
|
57
|
-
if (!Array.isArray(arr) || arr.length === 0) {
|
58
|
-
return [];
|
59
|
-
}
|
60
|
-
const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, childrenMapName: this.c.childrenMapName, cb: null }, options);
|
61
|
-
const tree = [];
|
62
|
-
const childrenOf = {};
|
63
|
-
let rootPid = opt.rootParentIdValue;
|
64
|
-
const arrType = arr;
|
65
|
-
if (!rootPid) {
|
66
|
-
const pids = arrType.map(i => i[opt.parentIdMapName]);
|
67
|
-
const emptyPid = pids.findIndex(w => w == null);
|
68
|
-
rootPid = emptyPid !== -1 ? pids[emptyPid] : pids.sort()[0];
|
69
|
-
}
|
70
|
-
for (const item of arrType) {
|
71
|
-
const id = item[opt.idMapName];
|
72
|
-
const pid = item[opt.parentIdMapName];
|
73
|
-
childrenOf[id] = childrenOf[id] || [];
|
74
|
-
item[opt.childrenMapName] = childrenOf[id];
|
75
|
-
if (opt.cb) {
|
76
|
-
opt.cb(item);
|
77
|
-
}
|
78
|
-
if (pid !== rootPid) {
|
79
|
-
childrenOf[pid] = childrenOf[pid] || [];
|
80
|
-
childrenOf[pid].push(item);
|
81
|
-
}
|
82
|
-
else {
|
83
|
-
tree.push(item);
|
84
|
-
}
|
85
|
-
}
|
86
|
-
return tree;
|
87
|
-
}
|
88
|
-
/**
|
89
|
-
* 数组转换成 `nz-tree` 数据源,通过 `options` 转化项名,也可以使用 `options.cb` 更高级决定数据项
|
90
|
-
*/
|
91
|
-
arrToTreeNode(arr, options) {
|
92
|
-
const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, titleMapName: this.c.titleMapName, isLeafMapName: 'isLeaf', checkedMapname: this.c.checkedMapname, selectedMapname: this.c.selectedMapname, expandedMapname: this.c.expandedMapname, disabledMapname: this.c.disabledMapname, cb: null }, options);
|
93
|
-
const tree = this.arrToTree(arr, {
|
94
|
-
idMapName: opt.idMapName,
|
95
|
-
parentIdMapName: opt.parentIdMapName,
|
96
|
-
childrenMapName: 'children'
|
97
|
-
});
|
98
|
-
this.visitTree(tree, (item, parent, deep) => {
|
99
|
-
item.key = item[opt.idMapName];
|
100
|
-
item.title = item[opt.titleMapName];
|
101
|
-
item.checked = item[opt.checkedMapname];
|
102
|
-
item.selected = item[opt.selectedMapname];
|
103
|
-
item.expanded = item[opt.expandedMapname];
|
104
|
-
item.disabled = item[opt.disabledMapname];
|
105
|
-
if (item[opt.isLeafMapName] == null) {
|
106
|
-
item.isLeaf = item.children.length === 0;
|
107
|
-
}
|
108
|
-
else {
|
109
|
-
item.isLeaf = item[opt.isLeafMapName];
|
110
|
-
}
|
111
|
-
if (opt.cb) {
|
112
|
-
opt.cb(item, parent, deep);
|
113
|
-
}
|
114
|
-
});
|
115
|
-
return tree.map(node => new NzTreeNode(node));
|
116
|
-
}
|
117
|
-
/**
|
118
|
-
* 递归访问整个树
|
119
|
-
*/
|
120
|
-
visitTree(tree, cb, options) {
|
121
|
-
options = Object.assign({ childrenMapName: this.c.childrenMapName }, options);
|
122
|
-
const inFn = (data, parent, deep) => {
|
123
|
-
for (const item of data) {
|
124
|
-
cb(item, parent, deep);
|
125
|
-
const childrenVal = item[options.childrenMapName];
|
126
|
-
if (Array.isArray(childrenVal) && childrenVal.length > 0) {
|
127
|
-
inFn(childrenVal, item, deep + 1);
|
128
|
-
}
|
129
|
-
}
|
130
|
-
};
|
131
|
-
inFn(tree, null, 1);
|
132
|
-
}
|
133
|
-
/**
|
134
|
-
* Return the value of the first tree value in the tree where predicate is true, and `undefined` otherwise
|
135
|
-
*
|
136
|
-
* 根据条件返回树的第一个值,否则返回 `undefined`
|
137
|
-
*/
|
138
|
-
findTree(tree, predicate, options) {
|
139
|
-
let res;
|
140
|
-
this.visitTree(tree, item => {
|
141
|
-
if (res === undefined && predicate(item)) {
|
142
|
-
res = item;
|
143
|
-
}
|
144
|
-
}, options);
|
145
|
-
return res;
|
146
|
-
}
|
147
|
-
/**
|
148
|
-
* 获取所有已经选中的 `key` 值
|
149
|
-
*/
|
150
|
-
getKeysByTreeNode(tree, options) {
|
151
|
-
const opt = Object.assign({ includeHalfChecked: true }, options);
|
152
|
-
const keys = [];
|
153
|
-
this.visitTree(tree, (item, parent, deep) => {
|
154
|
-
if (item.isChecked || (opt.includeHalfChecked && item.isHalfChecked)) {
|
155
|
-
keys.push(opt.cb ? opt.cb(item, parent, deep) : opt.keyMapName ? item.origin[opt.keyMapName] : item.key);
|
156
|
-
}
|
157
|
-
});
|
158
|
-
return keys;
|
159
|
-
}
|
160
|
-
baseFlat(array, depth, result = []) {
|
161
|
-
let index = -1;
|
162
|
-
while (++index < array.length) {
|
163
|
-
const value = array[index];
|
164
|
-
if (depth > 0 && Array.isArray(value)) {
|
165
|
-
if (depth > 1) {
|
166
|
-
this.baseFlat(value, depth - 1, result);
|
167
|
-
}
|
168
|
-
else {
|
169
|
-
let pushIndex = -1;
|
170
|
-
const offset = result.length;
|
171
|
-
while (++pushIndex < value.length) {
|
172
|
-
result[offset + pushIndex] = value[pushIndex];
|
173
|
-
}
|
174
|
-
}
|
175
|
-
}
|
176
|
-
else {
|
177
|
-
result[result.length] = value;
|
178
|
-
}
|
179
|
-
}
|
180
|
-
return result;
|
181
|
-
}
|
182
|
-
/**
|
183
|
-
* Recursively flattens array
|
184
|
-
*
|
185
|
-
* 递归扁平数组
|
186
|
-
* ```ts
|
187
|
-
* srv.flat([1, [2, 3, [4, 5, [6]]]]) => [1,2,3,4,5,6]
|
188
|
-
* srv.flat([1, [2, 3, [4, 5, [6]]]], 1) => [1,2,3,[4, 5, [6]]]
|
189
|
-
* ```
|
190
|
-
*/
|
191
|
-
flat(array, depth = 1 / 0) {
|
192
|
-
return Array.isArray(array) ? this.baseFlat(array, depth) : array;
|
193
|
-
}
|
194
|
-
/**
|
195
|
-
* Group the array
|
196
|
-
*
|
197
|
-
* 对数组进行分组
|
198
|
-
* ```ts
|
199
|
-
* srv.groupBy([6.1, 4.2, 6.3], Math.floor) => {"4":[4.2],"6":[6.1,6.3]}
|
200
|
-
* srv.groupBy(['one', 'two', 'three'], v => v.length) => {"3":["one","two"],"5":["three"]}
|
201
|
-
* ```
|
202
|
-
*/
|
203
|
-
groupBy(array, iteratee) {
|
204
|
-
if (!Array.isArray(array)) {
|
205
|
-
return {};
|
206
|
-
}
|
207
|
-
return array.reduce((result, value) => {
|
208
|
-
const key = iteratee(value);
|
209
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
210
|
-
result[key].push(value);
|
211
|
-
}
|
212
|
-
else {
|
213
|
-
result[key] = [value];
|
214
|
-
}
|
215
|
-
return result;
|
216
|
-
}, {});
|
217
|
-
}
|
218
|
-
/**
|
219
|
-
* Creates a duplicate-free version of an array
|
220
|
-
*
|
221
|
-
* 创建去重后的数组
|
222
|
-
* ```ts
|
223
|
-
* uniq([1, 2, 2, 3, 1]) => [1,2,3]
|
224
|
-
* uniq([{ a: 1 }, { a: 1 }, { a: 2 }], 'a') => [{"a":1},{"a":2}]
|
225
|
-
* uniq([{ a: 1 }, { a: 1 }, { a: 2 }], i => (i.a === 1 ? 'a' : 'b')) => [{"a":1},{"a":2}]
|
226
|
-
* ```
|
227
|
-
*/
|
228
|
-
uniq(array, predicate) {
|
229
|
-
return Array.from(array
|
230
|
-
.reduce((map, value) => {
|
231
|
-
const key = predicate
|
232
|
-
? typeof predicate === 'string'
|
233
|
-
? value[predicate]
|
234
|
-
: predicate(value)
|
235
|
-
: value;
|
236
|
-
if (!map.has(key)) {
|
237
|
-
map.set(key, value);
|
238
|
-
}
|
239
|
-
return map;
|
240
|
-
}, new Map())
|
241
|
-
.values());
|
242
|
-
}
|
243
|
-
}
|
244
|
-
ArrayService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayService_Factory() { return new ArrayService(i0.ɵɵinject(i1.YunzaiConfigService)); }, token: ArrayService, providedIn: "root" });
|
245
|
-
ArrayService.decorators = [
|
246
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
247
|
-
];
|
248
|
-
ArrayService.ctorParameters = () => [
|
249
|
-
{ type: YunzaiConfigService }
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
8
|
+
class ArrayService {
|
9
|
+
constructor(cog) {
|
10
|
+
this.c = cog.merge('utilArray', {
|
11
|
+
deepMapName: 'deep',
|
12
|
+
parentMapName: 'parent',
|
13
|
+
idMapName: 'id',
|
14
|
+
parentIdMapName: 'parent_id',
|
15
|
+
childrenMapName: 'children',
|
16
|
+
titleMapName: 'title',
|
17
|
+
checkedMapname: 'checked',
|
18
|
+
selectedMapname: 'selected',
|
19
|
+
expandedMapname: 'expanded',
|
20
|
+
disabledMapname: 'disabled'
|
21
|
+
});
|
22
|
+
}
|
23
|
+
/**
|
24
|
+
* Convert tree structure to array structure
|
25
|
+
*
|
26
|
+
* 将树结构转换成数组结构
|
27
|
+
*/
|
28
|
+
treeToArr(tree, options) {
|
29
|
+
const opt = Object.assign({ deepMapName: this.c.deepMapName, parentMapName: this.c.parentMapName, childrenMapName: this.c.childrenMapName, clearChildren: true, cb: null }, options);
|
30
|
+
const result = [];
|
31
|
+
const inFn = (list, parent, deep = 0) => {
|
32
|
+
for (const i of list) {
|
33
|
+
i[opt.deepMapName] = deep;
|
34
|
+
i[opt.parentMapName] = parent;
|
35
|
+
if (opt.cb) {
|
36
|
+
opt.cb(i, parent, deep);
|
37
|
+
}
|
38
|
+
result.push(i);
|
39
|
+
const children = i[opt.childrenMapName];
|
40
|
+
if (children != null && Array.isArray(children) && children.length > 0) {
|
41
|
+
inFn(children, i, deep + 1);
|
42
|
+
}
|
43
|
+
if (opt.clearChildren) {
|
44
|
+
delete i[opt.childrenMapName];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
};
|
48
|
+
inFn(tree, null);
|
49
|
+
return result;
|
50
|
+
}
|
51
|
+
/**
|
52
|
+
* Convert array structure to tree structure
|
53
|
+
*
|
54
|
+
* 数组转换成树数据
|
55
|
+
*/
|
56
|
+
arrToTree(arr, options) {
|
57
|
+
if (!Array.isArray(arr) || arr.length === 0) {
|
58
|
+
return [];
|
59
|
+
}
|
60
|
+
const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, childrenMapName: this.c.childrenMapName, cb: null }, options);
|
61
|
+
const tree = [];
|
62
|
+
const childrenOf = {};
|
63
|
+
let rootPid = opt.rootParentIdValue;
|
64
|
+
const arrType = arr;
|
65
|
+
if (!rootPid) {
|
66
|
+
const pids = arrType.map(i => i[opt.parentIdMapName]);
|
67
|
+
const emptyPid = pids.findIndex(w => w == null);
|
68
|
+
rootPid = emptyPid !== -1 ? pids[emptyPid] : pids.sort()[0];
|
69
|
+
}
|
70
|
+
for (const item of arrType) {
|
71
|
+
const id = item[opt.idMapName];
|
72
|
+
const pid = item[opt.parentIdMapName];
|
73
|
+
childrenOf[id] = childrenOf[id] || [];
|
74
|
+
item[opt.childrenMapName] = childrenOf[id];
|
75
|
+
if (opt.cb) {
|
76
|
+
opt.cb(item);
|
77
|
+
}
|
78
|
+
if (pid !== rootPid) {
|
79
|
+
childrenOf[pid] = childrenOf[pid] || [];
|
80
|
+
childrenOf[pid].push(item);
|
81
|
+
}
|
82
|
+
else {
|
83
|
+
tree.push(item);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
return tree;
|
87
|
+
}
|
88
|
+
/**
|
89
|
+
* 数组转换成 `nz-tree` 数据源,通过 `options` 转化项名,也可以使用 `options.cb` 更高级决定数据项
|
90
|
+
*/
|
91
|
+
arrToTreeNode(arr, options) {
|
92
|
+
const opt = Object.assign({ idMapName: this.c.idMapName, parentIdMapName: this.c.parentIdMapName, titleMapName: this.c.titleMapName, isLeafMapName: 'isLeaf', checkedMapname: this.c.checkedMapname, selectedMapname: this.c.selectedMapname, expandedMapname: this.c.expandedMapname, disabledMapname: this.c.disabledMapname, cb: null }, options);
|
93
|
+
const tree = this.arrToTree(arr, {
|
94
|
+
idMapName: opt.idMapName,
|
95
|
+
parentIdMapName: opt.parentIdMapName,
|
96
|
+
childrenMapName: 'children'
|
97
|
+
});
|
98
|
+
this.visitTree(tree, (item, parent, deep) => {
|
99
|
+
item.key = item[opt.idMapName];
|
100
|
+
item.title = item[opt.titleMapName];
|
101
|
+
item.checked = item[opt.checkedMapname];
|
102
|
+
item.selected = item[opt.selectedMapname];
|
103
|
+
item.expanded = item[opt.expandedMapname];
|
104
|
+
item.disabled = item[opt.disabledMapname];
|
105
|
+
if (item[opt.isLeafMapName] == null) {
|
106
|
+
item.isLeaf = item.children.length === 0;
|
107
|
+
}
|
108
|
+
else {
|
109
|
+
item.isLeaf = item[opt.isLeafMapName];
|
110
|
+
}
|
111
|
+
if (opt.cb) {
|
112
|
+
opt.cb(item, parent, deep);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
return tree.map(node => new NzTreeNode(node));
|
116
|
+
}
|
117
|
+
/**
|
118
|
+
* 递归访问整个树
|
119
|
+
*/
|
120
|
+
visitTree(tree, cb, options) {
|
121
|
+
options = Object.assign({ childrenMapName: this.c.childrenMapName }, options);
|
122
|
+
const inFn = (data, parent, deep) => {
|
123
|
+
for (const item of data) {
|
124
|
+
cb(item, parent, deep);
|
125
|
+
const childrenVal = item[options.childrenMapName];
|
126
|
+
if (Array.isArray(childrenVal) && childrenVal.length > 0) {
|
127
|
+
inFn(childrenVal, item, deep + 1);
|
128
|
+
}
|
129
|
+
}
|
130
|
+
};
|
131
|
+
inFn(tree, null, 1);
|
132
|
+
}
|
133
|
+
/**
|
134
|
+
* Return the value of the first tree value in the tree where predicate is true, and `undefined` otherwise
|
135
|
+
*
|
136
|
+
* 根据条件返回树的第一个值,否则返回 `undefined`
|
137
|
+
*/
|
138
|
+
findTree(tree, predicate, options) {
|
139
|
+
let res;
|
140
|
+
this.visitTree(tree, item => {
|
141
|
+
if (res === undefined && predicate(item)) {
|
142
|
+
res = item;
|
143
|
+
}
|
144
|
+
}, options);
|
145
|
+
return res;
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* 获取所有已经选中的 `key` 值
|
149
|
+
*/
|
150
|
+
getKeysByTreeNode(tree, options) {
|
151
|
+
const opt = Object.assign({ includeHalfChecked: true }, options);
|
152
|
+
const keys = [];
|
153
|
+
this.visitTree(tree, (item, parent, deep) => {
|
154
|
+
if (item.isChecked || (opt.includeHalfChecked && item.isHalfChecked)) {
|
155
|
+
keys.push(opt.cb ? opt.cb(item, parent, deep) : opt.keyMapName ? item.origin[opt.keyMapName] : item.key);
|
156
|
+
}
|
157
|
+
});
|
158
|
+
return keys;
|
159
|
+
}
|
160
|
+
baseFlat(array, depth, result = []) {
|
161
|
+
let index = -1;
|
162
|
+
while (++index < array.length) {
|
163
|
+
const value = array[index];
|
164
|
+
if (depth > 0 && Array.isArray(value)) {
|
165
|
+
if (depth > 1) {
|
166
|
+
this.baseFlat(value, depth - 1, result);
|
167
|
+
}
|
168
|
+
else {
|
169
|
+
let pushIndex = -1;
|
170
|
+
const offset = result.length;
|
171
|
+
while (++pushIndex < value.length) {
|
172
|
+
result[offset + pushIndex] = value[pushIndex];
|
173
|
+
}
|
174
|
+
}
|
175
|
+
}
|
176
|
+
else {
|
177
|
+
result[result.length] = value;
|
178
|
+
}
|
179
|
+
}
|
180
|
+
return result;
|
181
|
+
}
|
182
|
+
/**
|
183
|
+
* Recursively flattens array
|
184
|
+
*
|
185
|
+
* 递归扁平数组
|
186
|
+
* ```ts
|
187
|
+
* srv.flat([1, [2, 3, [4, 5, [6]]]]) => [1,2,3,4,5,6]
|
188
|
+
* srv.flat([1, [2, 3, [4, 5, [6]]]], 1) => [1,2,3,[4, 5, [6]]]
|
189
|
+
* ```
|
190
|
+
*/
|
191
|
+
flat(array, depth = 1 / 0) {
|
192
|
+
return Array.isArray(array) ? this.baseFlat(array, depth) : array;
|
193
|
+
}
|
194
|
+
/**
|
195
|
+
* Group the array
|
196
|
+
*
|
197
|
+
* 对数组进行分组
|
198
|
+
* ```ts
|
199
|
+
* srv.groupBy([6.1, 4.2, 6.3], Math.floor) => {"4":[4.2],"6":[6.1,6.3]}
|
200
|
+
* srv.groupBy(['one', 'two', 'three'], v => v.length) => {"3":["one","two"],"5":["three"]}
|
201
|
+
* ```
|
202
|
+
*/
|
203
|
+
groupBy(array, iteratee) {
|
204
|
+
if (!Array.isArray(array)) {
|
205
|
+
return {};
|
206
|
+
}
|
207
|
+
return array.reduce((result, value) => {
|
208
|
+
const key = iteratee(value);
|
209
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
210
|
+
result[key].push(value);
|
211
|
+
}
|
212
|
+
else {
|
213
|
+
result[key] = [value];
|
214
|
+
}
|
215
|
+
return result;
|
216
|
+
}, {});
|
217
|
+
}
|
218
|
+
/**
|
219
|
+
* Creates a duplicate-free version of an array
|
220
|
+
*
|
221
|
+
* 创建去重后的数组
|
222
|
+
* ```ts
|
223
|
+
* uniq([1, 2, 2, 3, 1]) => [1,2,3]
|
224
|
+
* uniq([{ a: 1 }, { a: 1 }, { a: 2 }], 'a') => [{"a":1},{"a":2}]
|
225
|
+
* uniq([{ a: 1 }, { a: 1 }, { a: 2 }], i => (i.a === 1 ? 'a' : 'b')) => [{"a":1},{"a":2}]
|
226
|
+
* ```
|
227
|
+
*/
|
228
|
+
uniq(array, predicate) {
|
229
|
+
return Array.from(array
|
230
|
+
.reduce((map, value) => {
|
231
|
+
const key = predicate
|
232
|
+
? typeof predicate === 'string'
|
233
|
+
? value[predicate]
|
234
|
+
: predicate(value)
|
235
|
+
: value;
|
236
|
+
if (!map.has(key)) {
|
237
|
+
map.set(key, value);
|
238
|
+
}
|
239
|
+
return map;
|
240
|
+
}, new Map())
|
241
|
+
.values());
|
242
|
+
}
|
243
|
+
}
|
244
|
+
ArrayService.ɵprov = i0.ɵɵdefineInjectable({ factory: function ArrayService_Factory() { return new ArrayService(i0.ɵɵinject(i1.YunzaiConfigService)); }, token: ArrayService, providedIn: "root" });
|
245
|
+
ArrayService.decorators = [
|
246
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
247
|
+
];
|
248
|
+
ArrayService.ctorParameters = () => [
|
249
|
+
{ type: YunzaiConfigService }
|
250
250
|
];
|
251
251
|
|
252
|
-
/**
|
253
|
-
* Generated bundle index. Do not edit.
|
252
|
+
/**
|
253
|
+
* Generated bundle index. Do not edit.
|
254
254
|
*/
|
255
255
|
|
256
256
|
export { ArrayService };
|
@@ -2,48 +2,48 @@ import * as i0 from '@angular/core';
|
|
2
2
|
import { InjectionToken, Injectable, Optional, Inject } from '@angular/core';
|
3
3
|
import { deepMergeKey } from '@yelon/util/other';
|
4
4
|
|
5
|
-
class YunzaiSVConfig {
|
5
|
+
class YunzaiSVConfig {
|
6
6
|
}
|
7
7
|
|
8
|
-
const YUNZAI_CONFIG = new InjectionToken('yunzai-config', {
|
9
|
-
providedIn: 'root',
|
10
|
-
factory: YUNZAI_CONFIG_FACTORY
|
11
|
-
});
|
12
|
-
function YUNZAI_CONFIG_FACTORY() {
|
13
|
-
return {};
|
8
|
+
const YUNZAI_CONFIG = new InjectionToken('yunzai-config', {
|
9
|
+
providedIn: 'root',
|
10
|
+
factory: YUNZAI_CONFIG_FACTORY
|
11
|
+
});
|
12
|
+
function YUNZAI_CONFIG_FACTORY() {
|
13
|
+
return {};
|
14
14
|
}
|
15
15
|
|
16
|
-
class YunzaiConfigService {
|
17
|
-
constructor(defaultConfig) {
|
18
|
-
this.config = Object.assign({}, defaultConfig);
|
19
|
-
}
|
20
|
-
get(componentName, key) {
|
21
|
-
const res = (this.config[componentName] || {});
|
22
|
-
return key ? { [key]: res[key] } : res;
|
23
|
-
}
|
24
|
-
merge(componentName, ...defaultValues) {
|
25
|
-
return deepMergeKey({}, true, ...defaultValues, this.get(componentName));
|
26
|
-
}
|
27
|
-
attach(componentThis, componentName, defaultValues) {
|
28
|
-
Object.assign(componentThis, this.merge(componentName, defaultValues));
|
29
|
-
}
|
30
|
-
attachKey(componentThis, componentName, key) {
|
31
|
-
Object.assign(componentThis, this.get(componentName, key));
|
32
|
-
}
|
33
|
-
set(componentName, value) {
|
34
|
-
this.config[componentName] = Object.assign(Object.assign({}, this.config[componentName]), value);
|
35
|
-
}
|
36
|
-
}
|
37
|
-
YunzaiConfigService.ɵprov = i0.ɵɵdefineInjectable({ factory: function YunzaiConfigService_Factory() { return new YunzaiConfigService(i0.ɵɵinject(YUNZAI_CONFIG, 8)); }, token: YunzaiConfigService, providedIn: "root" });
|
38
|
-
YunzaiConfigService.decorators = [
|
39
|
-
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
40
|
-
];
|
41
|
-
YunzaiConfigService.ctorParameters = () => [
|
42
|
-
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [YUNZAI_CONFIG,] }] }
|
16
|
+
class YunzaiConfigService {
|
17
|
+
constructor(defaultConfig) {
|
18
|
+
this.config = Object.assign({}, defaultConfig);
|
19
|
+
}
|
20
|
+
get(componentName, key) {
|
21
|
+
const res = (this.config[componentName] || {});
|
22
|
+
return key ? { [key]: res[key] } : res;
|
23
|
+
}
|
24
|
+
merge(componentName, ...defaultValues) {
|
25
|
+
return deepMergeKey({}, true, ...defaultValues, this.get(componentName));
|
26
|
+
}
|
27
|
+
attach(componentThis, componentName, defaultValues) {
|
28
|
+
Object.assign(componentThis, this.merge(componentName, defaultValues));
|
29
|
+
}
|
30
|
+
attachKey(componentThis, componentName, key) {
|
31
|
+
Object.assign(componentThis, this.get(componentName, key));
|
32
|
+
}
|
33
|
+
set(componentName, value) {
|
34
|
+
this.config[componentName] = Object.assign(Object.assign({}, this.config[componentName]), value);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
YunzaiConfigService.ɵprov = i0.ɵɵdefineInjectable({ factory: function YunzaiConfigService_Factory() { return new YunzaiConfigService(i0.ɵɵinject(YUNZAI_CONFIG, 8)); }, token: YunzaiConfigService, providedIn: "root" });
|
38
|
+
YunzaiConfigService.decorators = [
|
39
|
+
{ type: Injectable, args: [{ providedIn: 'root' },] }
|
40
|
+
];
|
41
|
+
YunzaiConfigService.ctorParameters = () => [
|
42
|
+
{ type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [YUNZAI_CONFIG,] }] }
|
43
43
|
];
|
44
44
|
|
45
|
-
/**
|
46
|
-
* Generated bundle index. Do not edit.
|
45
|
+
/**
|
46
|
+
* Generated bundle index. Do not edit.
|
47
47
|
*/
|
48
48
|
|
49
49
|
export { YUNZAI_CONFIG, YUNZAI_CONFIG_FACTORY, YunzaiConfigService, YunzaiSVConfig };
|