yi-bi-ez-table 1.0.0
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.
- package/.idea/ez-table.iml +12 -0
- package/.idea/modules.xml +8 -0
- package/angular/formatNumber.js +39 -0
- package/angular/formatPercent.js +4 -0
- package/calc-measure/calc-measure-hander.js +239 -0
- package/calc-measure/utils.js +384 -0
- package/constants.js +62 -0
- package/ez-agg-cunc-hander.js +186 -0
- package/ez-custom-agg-func/ez-custom-agg-func-hander.js +71 -0
- package/ez-custom-agg-func/utils.js +61 -0
- package/ezNumber.js +82 -0
- package/func.js +70 -0
- package/index.js +3 -0
- package/interface.js +2 -0
- package/package.json +16 -0
- package/prisma/seed.js +70 -0
- package/setBindDim.js +178 -0
- package/setDisplayData.js +207 -0
- package/setMergeData.js +198 -0
- package/table-core.js +620 -0
- package/table-header.js +1680 -0
- package/table-headerKeys.js +785 -0
- package/utils.js +910 -0
package/table-core.js
ADDED
|
@@ -0,0 +1,620 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { calcCurrentGroup, cloneDeepTree, convertToTree, getAlertConditionFn, getCalcValue, getCatchFunction, getDifferentTypeHeaderKeys, getImageDisplayName, pruneEmptyChildren, setSortDataList, } from "./utils";
|
|
3
|
+
import { parseISO, startOfDay } from "date-fns";
|
|
4
|
+
import { EZTableHeader } from "./table-header";
|
|
5
|
+
import { EZTableHeaderKeys } from "./table-headerKeys";
|
|
6
|
+
import { getCalcRowValue } from "./calc-measure/calc-measure-hander";
|
|
7
|
+
import { calcSum, recursionForLastButTwo, recursionForParent, } from "./calc-measure/utils";
|
|
8
|
+
import { calcAgg } from "./ez-agg-cunc-hander";
|
|
9
|
+
import { setDisplayData } from "./setDisplayData";
|
|
10
|
+
import { setMergeChildren } from "./setMergeData";
|
|
11
|
+
import { setBindDimChildren, setSortOfBindDim } from "./setBindDim";
|
|
12
|
+
import { ONCE_CALC_LIST } from "./constants";
|
|
13
|
+
export class EZTable {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.headers = [];
|
|
16
|
+
this.headersOfMerge = [];
|
|
17
|
+
this.headersOfBindDimVertical = [];
|
|
18
|
+
this.headerKeys = [];
|
|
19
|
+
this.headerKeysDic = {};
|
|
20
|
+
this.headerKeysOfMerge = [];
|
|
21
|
+
this.headerKeysOfBindDimVertical = [];
|
|
22
|
+
this.dimKeyList = [];
|
|
23
|
+
this.measureKeyList = [];
|
|
24
|
+
this.groupKeyList = [];
|
|
25
|
+
this.normalMeasureKeyList = [];
|
|
26
|
+
// 计算度量(排除累加等一次性算好全部底层数据的)
|
|
27
|
+
this.calcHeaderKeys = [];
|
|
28
|
+
// 累计等一次性算好全部底层数据的计算度量
|
|
29
|
+
this.accHeaderKeys = [];
|
|
30
|
+
// 依赖累加等一次性算好全部底层数据的计算度量
|
|
31
|
+
this.afterAccHeaderKeys = [];
|
|
32
|
+
this.firstDim = {};
|
|
33
|
+
this.allData = {
|
|
34
|
+
dataList: [],
|
|
35
|
+
tree: [],
|
|
36
|
+
};
|
|
37
|
+
this.currentData = {
|
|
38
|
+
dataList: [],
|
|
39
|
+
tree: [],
|
|
40
|
+
};
|
|
41
|
+
this.data = {
|
|
42
|
+
dataList: [],
|
|
43
|
+
tree: [],
|
|
44
|
+
};
|
|
45
|
+
// 预警标识
|
|
46
|
+
this.alertTask = undefined;
|
|
47
|
+
}
|
|
48
|
+
getData(config, itemWidth = 100) {
|
|
49
|
+
this.config = config;
|
|
50
|
+
const ezTableHeader = new EZTableHeader();
|
|
51
|
+
const { headers, headersOfMerge, headersOfBindDimVertical } = ezTableHeader.getAllHeaders(config);
|
|
52
|
+
this.headers = headers;
|
|
53
|
+
// 1.获取 headerKeys
|
|
54
|
+
const { headerKeys, headerKeysDic } = new EZTableHeaderKeys().getHeaderKeys(headers, itemWidth);
|
|
55
|
+
const { headerKeys: headerKeysOfMerge } = new EZTableHeaderKeys().getHeaderKeys(headersOfMerge, itemWidth);
|
|
56
|
+
const { headerKeys: headerKeysOfBindDimVertical } = new EZTableHeaderKeys().getHeaderKeys(headersOfBindDimVertical, itemWidth);
|
|
57
|
+
const { dimKeyList, measureKeyList, groupKeyList, normalMeasureKeyList } = getDifferentTypeHeaderKeys(headerKeys);
|
|
58
|
+
this.headerKeys = headerKeys;
|
|
59
|
+
this.headersOfMerge = headersOfMerge;
|
|
60
|
+
this.headersOfBindDimVertical = headersOfBindDimVertical;
|
|
61
|
+
this.headerKeysDic = headerKeysDic;
|
|
62
|
+
this.headerKeysOfMerge = headerKeysOfMerge;
|
|
63
|
+
this.headerKeysOfBindDimVertical = headerKeysOfBindDimVertical;
|
|
64
|
+
this.dimKeyList = dimKeyList;
|
|
65
|
+
this.measureKeyList = measureKeyList;
|
|
66
|
+
this.groupKeyList = groupKeyList;
|
|
67
|
+
this.normalMeasureKeyList = normalMeasureKeyList;
|
|
68
|
+
this.firstDim = dimKeyList[0];
|
|
69
|
+
const calcHeaderKeys = _.orderBy(headerKeys.filter((header) => (header.calcLevel === 0 || header.calcLevel > 0) && typeof header.accLevel !== 'number'), "calcLevel");
|
|
70
|
+
const calcDimKeys = [];
|
|
71
|
+
const calcMeasureKeys = [];
|
|
72
|
+
calcHeaderKeys.forEach(item => {
|
|
73
|
+
if (item.dimType) {
|
|
74
|
+
calcDimKeys.push(item);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
calcMeasureKeys.push(item);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
this.calcHeaderKeys = calcMeasureKeys;
|
|
81
|
+
const accHeaderKeys = _.orderBy(headerKeys.filter((header) => header.accLevel === 0), 'calcLevel');
|
|
82
|
+
const afterAccHeaderKeys = _.orderBy(headerKeys.filter((header) => header.accLevel > 0), "accLevel");
|
|
83
|
+
this.accHeaderKeys = accHeaderKeys;
|
|
84
|
+
this.afterAccHeaderKeys = afterAccHeaderKeys;
|
|
85
|
+
// 2.转换为树结构(dataList 和 tree 里的 对象是同一个)
|
|
86
|
+
let dataList = config.dataList.map((item) => ({ data: item }));
|
|
87
|
+
// 2.1 计算条件维度
|
|
88
|
+
calcDimKeys.forEach((header) => {
|
|
89
|
+
this.calcTree(dataList, header);
|
|
90
|
+
});
|
|
91
|
+
let tree = convertToTree(dataList, this.groupKeyList, this.firstDim.key);
|
|
92
|
+
// 3.行计算(计算所有,包括累加,累加增加个排序方式,选择维度,选择升序降序,和排序一样的 ui)
|
|
93
|
+
this.calcRowOfAll(tree, dataList);
|
|
94
|
+
const displayHeaders = this.getDisplayHeader();
|
|
95
|
+
// 4.设置表头过滤(条件度量(字符类型)需要行计算后才能有值)
|
|
96
|
+
this.setCustomFilter(displayHeaders, dataList);
|
|
97
|
+
// 5.表头过滤(表头过滤后值不变,不再计算)
|
|
98
|
+
this.allData = {
|
|
99
|
+
tree: [...tree],
|
|
100
|
+
dataList: [...dataList],
|
|
101
|
+
};
|
|
102
|
+
tree = this.searchAll(this.allData.tree);
|
|
103
|
+
dataList = this.convertToList(tree);
|
|
104
|
+
this.currentData = {
|
|
105
|
+
tree,
|
|
106
|
+
dataList,
|
|
107
|
+
};
|
|
108
|
+
// 6.列计算
|
|
109
|
+
this.calcColOfAll(tree);
|
|
110
|
+
// 7.排序(如果有分组,则合计项排序)
|
|
111
|
+
this.setSort(config.sortList, tree, true);
|
|
112
|
+
// 8.headersOfMerge 或 headersOfBindDimVertical 处理
|
|
113
|
+
this.setMergeData();
|
|
114
|
+
// 9.维度绑定处理
|
|
115
|
+
this.setSortOfBindDim();
|
|
116
|
+
try {
|
|
117
|
+
// 10.预警计算
|
|
118
|
+
this.setAlertTask(config.alertTaskList);
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
console.error(error);
|
|
122
|
+
}
|
|
123
|
+
// 11.计算显示样式
|
|
124
|
+
this.setDisplayData(tree);
|
|
125
|
+
return {
|
|
126
|
+
headers: this.getDisplayHeader(),
|
|
127
|
+
headerKeys: this.getDisplayHeaderKeys(),
|
|
128
|
+
dataTree: this.currentData.tree,
|
|
129
|
+
headerKeysDic: this.headerKeysDic,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
getSearchData(headerSortList, rowLimit) {
|
|
133
|
+
let tree = cloneDeepTree(this.allData.tree);
|
|
134
|
+
tree = this.searchAll(tree);
|
|
135
|
+
// const dataList = this.convertToList(tree);
|
|
136
|
+
this.calcColOfAll(tree);
|
|
137
|
+
this.setSort(headerSortList || this.config?.sortList, tree, true);
|
|
138
|
+
if (rowLimit > 0) {
|
|
139
|
+
tree[0].children = tree[0].children.slice(0, rowLimit);
|
|
140
|
+
// const newDataList = this.convertToList(tree);
|
|
141
|
+
this.calcColOfAll(tree);
|
|
142
|
+
}
|
|
143
|
+
this.setMergeData(tree);
|
|
144
|
+
this.setDisplayData(tree, true);
|
|
145
|
+
return tree;
|
|
146
|
+
}
|
|
147
|
+
getDisplayHeader() {
|
|
148
|
+
let headers = this.headers;
|
|
149
|
+
if (this.headersOfMerge.length) {
|
|
150
|
+
headers = this.headersOfMerge;
|
|
151
|
+
}
|
|
152
|
+
if (this.headersOfBindDimVertical?.length) {
|
|
153
|
+
headers = this.headersOfBindDimVertical;
|
|
154
|
+
}
|
|
155
|
+
return headers;
|
|
156
|
+
}
|
|
157
|
+
getDisplayHeaderKeys() {
|
|
158
|
+
let headerKeys = this.headerKeys;
|
|
159
|
+
if (this.headerKeysOfMerge.length) {
|
|
160
|
+
headerKeys = this.headerKeysOfMerge;
|
|
161
|
+
}
|
|
162
|
+
if (this.headerKeysOfBindDimVertical?.length) {
|
|
163
|
+
headerKeys = this.headerKeysOfBindDimVertical;
|
|
164
|
+
}
|
|
165
|
+
//按headers重新排序headerKeys
|
|
166
|
+
// const sortHeaderKeys = [];
|
|
167
|
+
// const headerKeysDic = {};
|
|
168
|
+
// headerKeys.forEach(h=>{
|
|
169
|
+
// headerKeysDic[h.key] = h;
|
|
170
|
+
// });
|
|
171
|
+
// this.headers.forEach(list=>{
|
|
172
|
+
// list.forEach(item=>{
|
|
173
|
+
// if(!item.colspan||item.colspan<=1){
|
|
174
|
+
// sortHeaderKeys.push(headerKeysDic[item.key]);
|
|
175
|
+
// }
|
|
176
|
+
// });
|
|
177
|
+
// });
|
|
178
|
+
//
|
|
179
|
+
// console.log(this.headers,headerKeys,headerKeysDic,sortHeaderKeys);
|
|
180
|
+
return headerKeys;
|
|
181
|
+
}
|
|
182
|
+
// convertToTree(dataList): ITreeData[] {
|
|
183
|
+
// const groupKeyList = this.groupKeyList;
|
|
184
|
+
// const root = {
|
|
185
|
+
// children: [],
|
|
186
|
+
// value: "合计",
|
|
187
|
+
// data: { [this.firstDim.key]: "合计" },
|
|
188
|
+
// totalType: 'TOTAL_SUMMARY',
|
|
189
|
+
// };
|
|
190
|
+
// const nodeMap = { root }; // 哈希表存储节点
|
|
191
|
+
// for (const data of dataList) {
|
|
192
|
+
// let currentNode = root;
|
|
193
|
+
// let nodeId = "root";
|
|
194
|
+
// for (let i = 0; i < groupKeyList.length; i++) {
|
|
195
|
+
// const group = groupKeyList[i];
|
|
196
|
+
// const value = data.data[group.key];
|
|
197
|
+
// nodeId = `${nodeId}_${value}`;
|
|
198
|
+
// let matchingNode = nodeMap[nodeId];
|
|
199
|
+
// if (!matchingNode) {
|
|
200
|
+
// matchingNode = {
|
|
201
|
+
// nodeId,
|
|
202
|
+
// value,
|
|
203
|
+
// children: [],
|
|
204
|
+
// data: { [group.key]: value },
|
|
205
|
+
// totalType: group.key,
|
|
206
|
+
// };
|
|
207
|
+
// currentNode.children.push(matchingNode);
|
|
208
|
+
// nodeMap[nodeId] = matchingNode;
|
|
209
|
+
// }
|
|
210
|
+
// currentNode = matchingNode;
|
|
211
|
+
// }
|
|
212
|
+
// currentNode.children.push({ data: data.data });
|
|
213
|
+
// }
|
|
214
|
+
// const makeTreeFn = (list: any[], parent = null) => {
|
|
215
|
+
// for (const item of list) {
|
|
216
|
+
// delete item.nodeId;
|
|
217
|
+
// item.parent = parent;
|
|
218
|
+
// if (item.children?.length) {
|
|
219
|
+
// makeTreeFn(item.children, item);
|
|
220
|
+
// }
|
|
221
|
+
// }
|
|
222
|
+
// };
|
|
223
|
+
// const tree: ITreeData[] = [root];
|
|
224
|
+
// makeTreeFn(tree);
|
|
225
|
+
// return tree;
|
|
226
|
+
// }
|
|
227
|
+
convertToList(tree) {
|
|
228
|
+
const list = [];
|
|
229
|
+
const loopTree = (treeData) => {
|
|
230
|
+
for (const data of treeData) {
|
|
231
|
+
if (data.children) {
|
|
232
|
+
loopTree(data.children);
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
list.push(data);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
loopTree(tree);
|
|
240
|
+
return list;
|
|
241
|
+
}
|
|
242
|
+
calcRowOfCItem(child, header) {
|
|
243
|
+
let value = getCalcRowValue({
|
|
244
|
+
header,
|
|
245
|
+
data: child,
|
|
246
|
+
headerKeysDic: this.headerKeysDic,
|
|
247
|
+
});
|
|
248
|
+
if (['IMAGE', 'LINK'].includes(header.dataType)) {
|
|
249
|
+
if (typeof value !== 'object') {
|
|
250
|
+
value = {
|
|
251
|
+
title: value,
|
|
252
|
+
href: value,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
child.data[header.key] = value?.title;
|
|
256
|
+
if (!child.link) {
|
|
257
|
+
child.link = {};
|
|
258
|
+
}
|
|
259
|
+
child.link[header.key] = value;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
child.data[header.key] = value;
|
|
263
|
+
}
|
|
264
|
+
calcTree(list, header) {
|
|
265
|
+
for (const data of list) {
|
|
266
|
+
if (data.children) {
|
|
267
|
+
this.calcTree(data.children, header);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.calcRowOfCItem(data, header);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
calcAccOfRow(dataList, tree) {
|
|
275
|
+
for (const accHeader of this.accHeaderKeys) {
|
|
276
|
+
getCalcRowValue({
|
|
277
|
+
header: accHeader,
|
|
278
|
+
dataList,
|
|
279
|
+
firstDim: this.firstDim,
|
|
280
|
+
// data: child,
|
|
281
|
+
headerKeysDic: this.headerKeysDic,
|
|
282
|
+
tree,
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
calcRowOfAll(tree, dataList) {
|
|
287
|
+
// 普通度量求和
|
|
288
|
+
calcSum(tree, this.normalMeasureKeyList);
|
|
289
|
+
// 1.先计算普通计算度量(不包括累加等一次性算好全部的)
|
|
290
|
+
this.calcHeaderKeys.forEach((header) => {
|
|
291
|
+
this.calcTree(tree, header);
|
|
292
|
+
});
|
|
293
|
+
// 2.计算累加等一次性算好全部的计算度量
|
|
294
|
+
this.calcAccOfRow(dataList, tree);
|
|
295
|
+
// 3.最后计算依赖累加等一次性算好全部的计算度量
|
|
296
|
+
this.afterAccHeaderKeys.forEach((header) => {
|
|
297
|
+
if (ONCE_CALC_LIST.includes(header.measureType)) {
|
|
298
|
+
getCalcRowValue({
|
|
299
|
+
header,
|
|
300
|
+
dataList,
|
|
301
|
+
firstDim: this.firstDim,
|
|
302
|
+
// data: child,
|
|
303
|
+
headerKeysDic: this.headerKeysDic,
|
|
304
|
+
tree,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
this.calcTree(tree, header);
|
|
309
|
+
}
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
getAggFunc(header, data) {
|
|
313
|
+
const { groupAggFunc } = header;
|
|
314
|
+
let func = header.totalCalculate;
|
|
315
|
+
let aggRange = null;
|
|
316
|
+
if (data.parent && groupAggFunc?.aggFunc) {
|
|
317
|
+
func = groupAggFunc.aggFunc;
|
|
318
|
+
}
|
|
319
|
+
if (!data.parent) {
|
|
320
|
+
aggRange = header.aggRange;
|
|
321
|
+
}
|
|
322
|
+
const c = groupAggFunc?.conditionList.find(item => item.dimList.includes(data.totalType));
|
|
323
|
+
if (c) {
|
|
324
|
+
func = c.aggFunc;
|
|
325
|
+
if (c.dimList?.length === 1 && c.aggRange !== 'GLOBAL') {
|
|
326
|
+
aggRange = c.aggRange;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
return {
|
|
330
|
+
func,
|
|
331
|
+
aggRange,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
recursiveCalc(header, tree) {
|
|
335
|
+
recursionForParent(tree, (item) => {
|
|
336
|
+
const { func, aggRange } = this.getAggFunc(header, item);
|
|
337
|
+
item.data[header.key] = calcAgg({
|
|
338
|
+
// aggKey: header.totalCalculate as TAggFunc,
|
|
339
|
+
aggKey: func,
|
|
340
|
+
aggRange,
|
|
341
|
+
calcKey: header.key,
|
|
342
|
+
header,
|
|
343
|
+
headerKeysDic: this.headerKeysDic,
|
|
344
|
+
dataList: item.children,
|
|
345
|
+
data: item,
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
calcAccOfCol(tree, customList, calcList) {
|
|
350
|
+
if (calcList.length) {
|
|
351
|
+
calcList.forEach((header) => {
|
|
352
|
+
this.recursiveCalc(header, tree);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
for (const header of customList) {
|
|
356
|
+
calcAgg({
|
|
357
|
+
aggKey: header.totalCalculate,
|
|
358
|
+
calcKey: header.key,
|
|
359
|
+
header,
|
|
360
|
+
headerKeysDic: this.headerKeysDic,
|
|
361
|
+
tree,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
getAccTypeListOfCol() {
|
|
366
|
+
const customList = [];
|
|
367
|
+
const calcList = [];
|
|
368
|
+
this.accHeaderKeys.forEach((header) => {
|
|
369
|
+
if (header.totalCalculate === 'CUSTOM') {
|
|
370
|
+
customList.push(header);
|
|
371
|
+
}
|
|
372
|
+
else {
|
|
373
|
+
calcList.push(header);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
return {
|
|
377
|
+
customList,
|
|
378
|
+
calcList,
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
calcColOfAll(tree) {
|
|
382
|
+
calcCurrentGroup(tree, this.measureKeyList);
|
|
383
|
+
// 1.先计算普通度量和普通计算度量(不包括累加等一次性算好全部的)
|
|
384
|
+
[...this.normalMeasureKeyList, ...this.calcHeaderKeys].forEach((header) => {
|
|
385
|
+
this.recursiveCalc(header, tree);
|
|
386
|
+
});
|
|
387
|
+
// 2.计算累加等一次性算好全部的计算度量
|
|
388
|
+
const { customList, calcList } = this.getAccTypeListOfCol();
|
|
389
|
+
this.calcAccOfCol(tree, customList, calcList);
|
|
390
|
+
// 3.最后计算依赖累加等一次性算好全部的计算度量
|
|
391
|
+
this.afterAccHeaderKeys.forEach((header) => {
|
|
392
|
+
if (ONCE_CALC_LIST.includes(header.measureType)) {
|
|
393
|
+
const itemCustomList = [];
|
|
394
|
+
const itemCalcList = [];
|
|
395
|
+
if (header.totalCalculate === 'CUSTOM') {
|
|
396
|
+
itemCustomList.push(header);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
itemCalcList.push(header);
|
|
400
|
+
}
|
|
401
|
+
this.calcAccOfCol(tree, itemCustomList, itemCalcList);
|
|
402
|
+
}
|
|
403
|
+
else {
|
|
404
|
+
this.recursiveCalc(header, tree);
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
searchAll(tree) {
|
|
409
|
+
tree = _.cloneDeep(tree);
|
|
410
|
+
// tree = cloneDeepTree(tree);
|
|
411
|
+
tree = this.stringSearch(tree);
|
|
412
|
+
tree = this.dateRangeSearch(tree);
|
|
413
|
+
tree = this.numberSearch(tree);
|
|
414
|
+
return tree;
|
|
415
|
+
}
|
|
416
|
+
stringSearch(tree) {
|
|
417
|
+
const hasFilterSelectedListHeaders = [];
|
|
418
|
+
const displayHeaders = this.getDisplayHeader();
|
|
419
|
+
displayHeaders.forEach((header) => {
|
|
420
|
+
header.forEach((hItem) => {
|
|
421
|
+
if (hItem.filterSelectedList && hItem.filterSelectedList.length) {
|
|
422
|
+
hasFilterSelectedListHeaders.push(hItem);
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
recursionForLastButTwo(tree, (data) => {
|
|
427
|
+
data.children = this.getStringSearchList(data.children, hasFilterSelectedListHeaders);
|
|
428
|
+
});
|
|
429
|
+
tree = pruneEmptyChildren(tree);
|
|
430
|
+
return tree;
|
|
431
|
+
}
|
|
432
|
+
getStringSearchList(list, hasFilterSelectedListHeaders) {
|
|
433
|
+
return list?.filter((data) => {
|
|
434
|
+
return hasFilterSelectedListHeaders.every((header) => {
|
|
435
|
+
if (header.isNotIncludes) {
|
|
436
|
+
return !header.filterSelectedList.includes(header.isProductImage
|
|
437
|
+
? getImageDisplayName(data.data[header.key])
|
|
438
|
+
: data.data[header.key]);
|
|
439
|
+
}
|
|
440
|
+
return header.filterSelectedList.includes(header.isProductImage
|
|
441
|
+
? getImageDisplayName(data.data[header.key])
|
|
442
|
+
: data.data[header.key]);
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
dateRangeSearch(tree) {
|
|
447
|
+
const hasFilterSelectedListHeaders = [];
|
|
448
|
+
const displayHeaders = this.getDisplayHeader();
|
|
449
|
+
displayHeaders.forEach((header) => {
|
|
450
|
+
header.forEach((hItem) => {
|
|
451
|
+
if (hItem.dateRange && (hItem.dateRange[0] || hItem.dateRange[1])) {
|
|
452
|
+
hasFilterSelectedListHeaders.push(hItem);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
});
|
|
456
|
+
recursionForLastButTwo(tree, (data) => {
|
|
457
|
+
data.children = this.getDateSearchList(data.children, hasFilterSelectedListHeaders);
|
|
458
|
+
});
|
|
459
|
+
tree = pruneEmptyChildren(tree);
|
|
460
|
+
return tree;
|
|
461
|
+
}
|
|
462
|
+
getDateSearchList(list, hasFilterSelectedListHeaders) {
|
|
463
|
+
return list.filter((data) => {
|
|
464
|
+
return hasFilterSelectedListHeaders.every((header) => {
|
|
465
|
+
const [hStartDate, hEndDate] = header.dateRange;
|
|
466
|
+
let hStartTime = null;
|
|
467
|
+
let hEndTime = null;
|
|
468
|
+
if (hStartDate) {
|
|
469
|
+
hStartTime = startOfDay(parseISO(hStartDate)).getTime();
|
|
470
|
+
}
|
|
471
|
+
if (hEndDate) {
|
|
472
|
+
hEndTime = startOfDay(parseISO(hEndDate)).getTime();
|
|
473
|
+
}
|
|
474
|
+
const dataTime = startOfDay(parseISO(data.data[header.key])).getTime();
|
|
475
|
+
if (hStartTime && hEndTime) {
|
|
476
|
+
return dataTime >= hStartTime && dataTime <= hEndTime;
|
|
477
|
+
}
|
|
478
|
+
if (hStartTime && !hEndTime) {
|
|
479
|
+
return dataTime >= hStartTime;
|
|
480
|
+
}
|
|
481
|
+
if (!hStartTime && hEndTime) {
|
|
482
|
+
return dataTime <= hEndTime;
|
|
483
|
+
}
|
|
484
|
+
return false;
|
|
485
|
+
});
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
numberSearch(tree) {
|
|
489
|
+
const hasFilterSelectedListHeaders = [];
|
|
490
|
+
const displayHeaders = this.getDisplayHeader();
|
|
491
|
+
displayHeaders.forEach((header) => {
|
|
492
|
+
header.forEach((hItem) => {
|
|
493
|
+
if (hItem.minNum ||
|
|
494
|
+
hItem.minNum === 0 ||
|
|
495
|
+
hItem.maxNum ||
|
|
496
|
+
hItem.maxNum === 0) {
|
|
497
|
+
hasFilterSelectedListHeaders.push(hItem);
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
});
|
|
501
|
+
recursionForLastButTwo(tree, (data) => {
|
|
502
|
+
data.children = this.getNumberSearchList(data.children, hasFilterSelectedListHeaders);
|
|
503
|
+
});
|
|
504
|
+
tree = pruneEmptyChildren(tree);
|
|
505
|
+
return tree;
|
|
506
|
+
}
|
|
507
|
+
getNumberSearchList(list, hasFilterSelectedListHeaders) {
|
|
508
|
+
return list.filter((data) => {
|
|
509
|
+
return hasFilterSelectedListHeaders.every((header) => {
|
|
510
|
+
const minNum = header.dataType === "PERCENT" ? header.minNum / 100 : header.minNum;
|
|
511
|
+
const maxNum = header.dataType === "PERCENT" ? header.maxNum / 100 : header.maxNum;
|
|
512
|
+
let d = data.data[header.key] || 0;
|
|
513
|
+
if (d === Infinity) {
|
|
514
|
+
d = 0;
|
|
515
|
+
}
|
|
516
|
+
if ((header.minNum || header.minNum === 0) &&
|
|
517
|
+
(header.maxNum || header.maxNum === 0)) {
|
|
518
|
+
return d >= minNum && d <= maxNum;
|
|
519
|
+
}
|
|
520
|
+
if ((header.minNum || header.minNum === 0) &&
|
|
521
|
+
!(header.maxNum || header.maxNum === 0)) {
|
|
522
|
+
return d !== Infinity && d >= minNum;
|
|
523
|
+
}
|
|
524
|
+
if (!(header.minNum || header.minNum === 0) &&
|
|
525
|
+
(header.maxNum || header.maxNum === 0)) {
|
|
526
|
+
return d <= maxNum;
|
|
527
|
+
}
|
|
528
|
+
return false;
|
|
529
|
+
});
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
setSort(sortList, tree, isChangeList = false) {
|
|
533
|
+
if (sortList.length) {
|
|
534
|
+
recursionForParent(tree, (data) => {
|
|
535
|
+
setSortDataList(data.children, sortList, this.headerKeysDic, isChangeList);
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
setAlertTask(alertTaskList) {
|
|
540
|
+
if (alertTaskList?.length) {
|
|
541
|
+
const task = alertTaskList?.[0];
|
|
542
|
+
const dataList = this.allData.dataList;
|
|
543
|
+
let alert = false;
|
|
544
|
+
const fn = getAlertConditionFn(task.conditionList, this.headerKeys);
|
|
545
|
+
for (let i = 0, leng = dataList.length; i < leng; i++) {
|
|
546
|
+
const data = dataList[i];
|
|
547
|
+
const boolean = getCalcValue(getCatchFunction(fn), { data });
|
|
548
|
+
if (boolean) {
|
|
549
|
+
alert = true;
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
this.alertTask = alert;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
// 合并分日期/尺码
|
|
557
|
+
setMergeData(tree = this.currentData.tree) {
|
|
558
|
+
if (this.headersOfMerge?.length) {
|
|
559
|
+
setMergeChildren(tree, this.headerKeysOfMerge, this.headerKeysDic, this.dimKeyList);
|
|
560
|
+
recursionForParent(tree, (data) => {
|
|
561
|
+
setMergeChildren(data.children, this.headerKeysOfMerge, this.headerKeysDic, this.dimKeyList);
|
|
562
|
+
});
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
// 绑定维度,竖排数据处理
|
|
566
|
+
setSortOfBindDim() {
|
|
567
|
+
if (this.headersOfBindDimVertical?.length) {
|
|
568
|
+
// setBindDimChildren(this.currentData.tree, this.headerKeysOfBindDimVertical, this.headerKeysDic, this.dimKeyList)
|
|
569
|
+
setBindDimChildren(this.currentData.tree, this.headerKeysOfBindDimVertical);
|
|
570
|
+
recursionForParent(this.currentData.tree, (data) => {
|
|
571
|
+
setBindDimChildren(data.children, this.headerKeysOfBindDimVertical);
|
|
572
|
+
});
|
|
573
|
+
}
|
|
574
|
+
const hasBind = this.headerKeys.find(header => header.bindDimOfParent && header.bindDimOfParent.bindDimOrder && header.bindDimOfParent.bindDimOrderMeasureName?.length);
|
|
575
|
+
if (hasBind) {
|
|
576
|
+
setSortOfBindDim(this.headerKeys, this.headers, this.currentData.tree[0].data);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
setDisplayData(tree, onlyTotal = false) {
|
|
580
|
+
const headerKeys = this.getDisplayHeaderKeys();
|
|
581
|
+
const dimList = this.dimKeyList;
|
|
582
|
+
// const { tree } = this.currentData;
|
|
583
|
+
setDisplayData(headerKeys, dimList, tree, onlyTotal);
|
|
584
|
+
}
|
|
585
|
+
setCustomFilter(headers, dataList) {
|
|
586
|
+
headers.forEach(header => {
|
|
587
|
+
header.forEach(h => {
|
|
588
|
+
if (h.customFilter) {
|
|
589
|
+
h.filterVisible = false;
|
|
590
|
+
h.filterSelectedList = h.filterSelectedList || [];
|
|
591
|
+
const listOfFilter = [];
|
|
592
|
+
const listOfMap = {};
|
|
593
|
+
const allListOfFilter = [];
|
|
594
|
+
const allListOfMap = {};
|
|
595
|
+
dataList.forEach(item => {
|
|
596
|
+
const value = h.isProductImage ? getImageDisplayName(item.data[h.key]) : item.data[h.key];
|
|
597
|
+
if (listOfFilter.length <= 100) {
|
|
598
|
+
if (!listOfMap[value]) {
|
|
599
|
+
listOfFilter.push({
|
|
600
|
+
text: value,
|
|
601
|
+
value,
|
|
602
|
+
});
|
|
603
|
+
listOfMap[value] = true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (!allListOfMap[value]) {
|
|
607
|
+
allListOfFilter.push({
|
|
608
|
+
text: value,
|
|
609
|
+
value,
|
|
610
|
+
});
|
|
611
|
+
allListOfMap[value] = true;
|
|
612
|
+
}
|
|
613
|
+
});
|
|
614
|
+
h.listOfFilter = listOfFilter;
|
|
615
|
+
h.allListOfFilter = [...allListOfFilter];
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
}
|