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
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { CALCULATED_REGEX, SUM_REGEX, GROUP_SUM_REGEX, GET_SIZE_REGEX, ONCE_CALC_LIST } from "./constants";
|
|
3
|
+
import { expr2FnBody, getCatchFunction, getStyleConditionFn, setStyleComputeFn } from "./utils";
|
|
4
|
+
export class EZTableHeaderKeys {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.getHeaderLevel = (header, headerKeysDic) => {
|
|
7
|
+
if (header.itemCalculate?.startsWith('DATE_RANGE_SUM(') || header.itemCalculate?.startsWith('COR(')) {
|
|
8
|
+
return {
|
|
9
|
+
level: 0,
|
|
10
|
+
accLevel: undefined,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const levelObj = {
|
|
14
|
+
level: 0,
|
|
15
|
+
accLevel: undefined
|
|
16
|
+
};
|
|
17
|
+
if (ONCE_CALC_LIST.includes(header.measureType)) {
|
|
18
|
+
// return {
|
|
19
|
+
// level: undefined,
|
|
20
|
+
// accLevel: 0,
|
|
21
|
+
// };
|
|
22
|
+
levelObj.accLevel = 0;
|
|
23
|
+
}
|
|
24
|
+
this.setHeaderLevel(header, header, headerKeysDic, levelObj);
|
|
25
|
+
return levelObj;
|
|
26
|
+
};
|
|
27
|
+
// getDiffLevel = (diff: IDiffDataCalculate, diffList: IDiffDataCalculate[]) => {
|
|
28
|
+
// let level = 0;
|
|
29
|
+
// const setDiffItemLevel = (d: IDiffDataCalculate) => {
|
|
30
|
+
// for (let fI = 0, fLeng = d.measureFields.length; fI < fLeng; fI++) {
|
|
31
|
+
// const f = d.measureFields[fI];
|
|
32
|
+
// const calcDiff = diffList.find(item => item.measure && item.measure === f);
|
|
33
|
+
// if (d === calcDiff) {
|
|
34
|
+
// // headerOfHasSelf.h = { key: calcDiff.measure } as IHeaderKey;
|
|
35
|
+
// // break;
|
|
36
|
+
// throw new Error(`${calcDiff.measure}计算公式中引用了自己`);
|
|
37
|
+
// }
|
|
38
|
+
// if (calcDiff) {
|
|
39
|
+
// level++;
|
|
40
|
+
// setDiffItemLevel(calcDiff);
|
|
41
|
+
// }
|
|
42
|
+
// }
|
|
43
|
+
// };
|
|
44
|
+
// setDiffItemLevel(diff);
|
|
45
|
+
// return level;
|
|
46
|
+
// };
|
|
47
|
+
// setCalcDiffLevel = (list: IDiffDataCalculate[]) => {
|
|
48
|
+
// list.forEach(diff => {
|
|
49
|
+
// diff.diffLevel = this.getDiffLevel(diff, list);
|
|
50
|
+
// });
|
|
51
|
+
// }
|
|
52
|
+
this.getMergeLevel = (merge, mergeDic) => {
|
|
53
|
+
let level = 0;
|
|
54
|
+
const setMergeItemLevel = (d) => {
|
|
55
|
+
for (let fI = 0, fLeng = d.measureFields.length; fI < fLeng; fI++) {
|
|
56
|
+
const f = d.measureFields[fI];
|
|
57
|
+
// const calcMerge = mergeList.find(item => item.measureKey && item.measureKey === f);
|
|
58
|
+
const calcMerge = mergeDic[f];
|
|
59
|
+
if (d === calcMerge) {
|
|
60
|
+
// headerOfHasSelf.h = { key: calcMerge.measureKey } as IHeaderKey;
|
|
61
|
+
// break;
|
|
62
|
+
throw new Error(`${calcMerge.measureKey}计算公式中引用了自己`);
|
|
63
|
+
}
|
|
64
|
+
if (calcMerge) {
|
|
65
|
+
level++;
|
|
66
|
+
setMergeItemLevel(calcMerge);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
setMergeItemLevel(merge);
|
|
71
|
+
return level;
|
|
72
|
+
};
|
|
73
|
+
this.setCalcLevel = (list, headerKeysDic) => {
|
|
74
|
+
for (let i = 0, leng = list.length; i < leng; i++) {
|
|
75
|
+
const h = list[i];
|
|
76
|
+
if (h.itemCalculate || h.exprObject?.list?.length) {
|
|
77
|
+
const { level, accLevel } = this.getHeaderLevel(h, headerKeysDic);
|
|
78
|
+
h.calcLevel = level;
|
|
79
|
+
h.accLevel = accLevel;
|
|
80
|
+
}
|
|
81
|
+
if (h.diffCalcList?.length && !h.calcLevel) {
|
|
82
|
+
h.calcLevel = 0;
|
|
83
|
+
}
|
|
84
|
+
// 经营指标用,目前不需要
|
|
85
|
+
// if (h.diffCalcList?.length) {
|
|
86
|
+
// this.setCalcDiffLevel(h.diffCalcList)
|
|
87
|
+
// }
|
|
88
|
+
if (h.mergeCalcList?.length) {
|
|
89
|
+
this.setMergeDiffLevel(h.mergeCalcList);
|
|
90
|
+
}
|
|
91
|
+
// if (headerOfHasSelf.h) {
|
|
92
|
+
// break;
|
|
93
|
+
// }
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
this.setHeaderComputeFn = (h, calcStr, headerKeysDic) => {
|
|
97
|
+
const expr = calcStr;
|
|
98
|
+
const fields = calcStr.match(CALCULATED_REGEX);
|
|
99
|
+
let formula = expr;
|
|
100
|
+
if (fields && fields.length) {
|
|
101
|
+
const calcKeyList = [];
|
|
102
|
+
for (let fI = 0, fLeng = fields.length; fI < fLeng; fI++) {
|
|
103
|
+
const f = fields[fI];
|
|
104
|
+
calcKeyList.push(f.replace('{', '').replace('}', ''));
|
|
105
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === f);
|
|
106
|
+
const headerItem = headerKeysDic[f.substring(1, f.length - 1)];
|
|
107
|
+
if (headerItem) {
|
|
108
|
+
let str = `data.data[${'"' + headerItem.key + '"'}]`;
|
|
109
|
+
if (headerItem.dataType === 'NUMBER') {
|
|
110
|
+
str = `(data.data[${'"' + headerItem.key + '"'}] || 0)`;
|
|
111
|
+
}
|
|
112
|
+
formula = formula.replace(f, str);
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
const newF = f.substring(1, f.length - 1);
|
|
116
|
+
formula = formula.replace(f, '(data.data["' + newF + '"] || 0)');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
h.calcKeyList = calcKeyList;
|
|
120
|
+
}
|
|
121
|
+
const sumFields = formula.match(SUM_REGEX);
|
|
122
|
+
const groupSumFields = formula.match(GROUP_SUM_REGEX);
|
|
123
|
+
const getSizeFields = formula.match(GET_SIZE_REGEX);
|
|
124
|
+
if (sumFields && sumFields.length && (!groupSumFields || !groupSumFields.length)) {
|
|
125
|
+
formula = formula.replaceAll('sum((data.data[', '((data.extra.sum[');
|
|
126
|
+
const sumKeyList = [];
|
|
127
|
+
const newSumFields = calcStr.match(SUM_REGEX);
|
|
128
|
+
newSumFields.forEach(sum => {
|
|
129
|
+
sumKeyList.push(sum.replace('sum({', '').replace('})', ''));
|
|
130
|
+
});
|
|
131
|
+
h.sumKeyList = sumKeyList;
|
|
132
|
+
}
|
|
133
|
+
if (groupSumFields && groupSumFields.length) {
|
|
134
|
+
formula = formula.replaceAll('group_sum((data.data[', '((data.extra.sum[');
|
|
135
|
+
const groupSumKeyList = [];
|
|
136
|
+
const newGroupSumFields = calcStr.match(GROUP_SUM_REGEX);
|
|
137
|
+
newGroupSumFields.forEach(sum => {
|
|
138
|
+
groupSumKeyList.push(sum.replace('group_sum({', '').replace('})', ''));
|
|
139
|
+
});
|
|
140
|
+
h.groupSumKeyList = groupSumKeyList;
|
|
141
|
+
}
|
|
142
|
+
if (getSizeFields && getSizeFields.length) {
|
|
143
|
+
getSizeFields.forEach(field => {
|
|
144
|
+
const f = field.replaceAll('getSize((data.data[', 'getSize(').replaceAll('] || 0)', '');
|
|
145
|
+
formula = formula.replace(field, f);
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
h.expr = expr2FnBody(formula);
|
|
149
|
+
h.computeFn = getCatchFunction(expr2FnBody(formula));
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
getHeaderKeys(headers, itemWidth = 0, key = null) {
|
|
153
|
+
// 计算度量中自己引用自己的度量
|
|
154
|
+
// const headerOfHasSelf: { h: IHeaderKey } = { h: null };
|
|
155
|
+
const headerKeys = this.getKeys(headers);
|
|
156
|
+
const headerKeysDic = this.getHeaderkeysDic(headerKeys);
|
|
157
|
+
// const getHeaderLevel = (header: IHeaderKey) => {
|
|
158
|
+
// let level = 0;
|
|
159
|
+
// let accLevel = undefined;
|
|
160
|
+
// if (header.itemCalculate?.startsWith('DATE_RANGE_SUM(') || header.itemCalculate?.startsWith('COR(')) {
|
|
161
|
+
// return {
|
|
162
|
+
// level: 0,
|
|
163
|
+
// accLevel,
|
|
164
|
+
// };
|
|
165
|
+
// }
|
|
166
|
+
// if (['GLOBAL_ACC', 'GROUP_ACC'].includes(header.measureType)) {
|
|
167
|
+
// return {
|
|
168
|
+
// level: undefined,
|
|
169
|
+
// accLevel: 0,
|
|
170
|
+
// };
|
|
171
|
+
// }
|
|
172
|
+
// const setHeaderLevel = (h: IHeaderKey) => {
|
|
173
|
+
// if (h.itemCalculate) {
|
|
174
|
+
// const expr = h.itemCalculate;
|
|
175
|
+
// let fields: any = expr.match(CALCULATED_REGEX);
|
|
176
|
+
// fields = _.uniq(fields);
|
|
177
|
+
// if (fields && fields.length) {
|
|
178
|
+
// for (let fI = 0, fLeng = fields.length; fI < fLeng; fI++) {
|
|
179
|
+
// const f = fields[fI];
|
|
180
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === f);
|
|
181
|
+
// if (header.key === headerItem.key) {
|
|
182
|
+
// headerOfHasSelf.h = header;
|
|
183
|
+
// throw new Error('计算公式中引用了自己');
|
|
184
|
+
// }
|
|
185
|
+
// if (['GLOBAL_ACC', 'GROUP_ACC'].includes(headerItem?.measureType)) {
|
|
186
|
+
// accLevel = level + 1;
|
|
187
|
+
// level = undefined;
|
|
188
|
+
// break;
|
|
189
|
+
// }
|
|
190
|
+
// if (headerItem?.itemCalculate || headerItem?.exprObject?.list?.length) {
|
|
191
|
+
// level++;
|
|
192
|
+
// setHeaderLevel(headerItem);
|
|
193
|
+
// }
|
|
194
|
+
// }
|
|
195
|
+
// }
|
|
196
|
+
// }
|
|
197
|
+
// if (h.exprObject?.list?.length) {
|
|
198
|
+
// const levelList = [];
|
|
199
|
+
// h.exprObject.list.forEach(exprObj => {
|
|
200
|
+
// exprObj.itemCalculate = exprObj.expr;
|
|
201
|
+
// const exprObjLevel = getHeaderLevel(exprObj).level;
|
|
202
|
+
// levelList.push(exprObjLevel);
|
|
203
|
+
// });
|
|
204
|
+
// if (levelList?.length) {
|
|
205
|
+
// const exprObjLevel = Math.max(...levelList);
|
|
206
|
+
// level = exprObjLevel > level ? exprObjLevel : level;
|
|
207
|
+
// }
|
|
208
|
+
// }
|
|
209
|
+
// };
|
|
210
|
+
// setHeaderLevel(header);
|
|
211
|
+
// return {
|
|
212
|
+
// level,
|
|
213
|
+
// accLevel,
|
|
214
|
+
// };
|
|
215
|
+
// };
|
|
216
|
+
// const getHeaderLevelAfterSort = (header: IHeaderKey) => {
|
|
217
|
+
// let level = 0;
|
|
218
|
+
// if (header.itemCalculate?.startsWith('DATE_RANGE_SUM(') || header.itemCalculate?.startsWith('COR(')) {
|
|
219
|
+
// return 0;
|
|
220
|
+
// }
|
|
221
|
+
// const setIncludesACC = (h: IHeaderKey) => {
|
|
222
|
+
// if (h?.itemCalculate) {
|
|
223
|
+
// const newFields = h.itemCalculate.match(CALCULATED_REGEX);
|
|
224
|
+
// newFields?.forEach(nF => {
|
|
225
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === nF);
|
|
226
|
+
// if (['GLOBAL_ACC', 'GROUP_ACC'].includes(headerItem?.measureType)) {
|
|
227
|
+
// level++;
|
|
228
|
+
// }
|
|
229
|
+
// if (headerItem?.itemCalculate) {
|
|
230
|
+
// setIncludesACC(headerItem);
|
|
231
|
+
// }
|
|
232
|
+
// });
|
|
233
|
+
// }
|
|
234
|
+
// };
|
|
235
|
+
// const setHeaderLevel = (h: IHeaderKey) => {
|
|
236
|
+
// if (h.itemCalculate) {
|
|
237
|
+
// const expr = h.itemCalculate;
|
|
238
|
+
// let fields: any = expr.match(CALCULATED_REGEX);
|
|
239
|
+
// fields = _.uniq(fields);
|
|
240
|
+
// if (fields && fields.length) {
|
|
241
|
+
// for (let fI = 0, fLeng = fields.length; fI < fLeng; fI++) {
|
|
242
|
+
// const f = fields[fI];
|
|
243
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === f);
|
|
244
|
+
// if (header === headerItem) {
|
|
245
|
+
// headerOfHasSelf.h = header;
|
|
246
|
+
// break;
|
|
247
|
+
// }
|
|
248
|
+
// if (headerItem?.itemCalculate || headerItem?.exprObject?.list?.length) {
|
|
249
|
+
// level++;
|
|
250
|
+
// setHeaderLevel(headerItem);
|
|
251
|
+
// } else if (!['GLOBAL_ACC', 'GROUP_ACC'].includes(h.measureType)) {
|
|
252
|
+
// }
|
|
253
|
+
// if (headerItem?.itemCalculate) {
|
|
254
|
+
// setIncludesACC(headerItem);
|
|
255
|
+
// }
|
|
256
|
+
// }
|
|
257
|
+
// }
|
|
258
|
+
// }
|
|
259
|
+
// };
|
|
260
|
+
// setHeaderLevel(header);
|
|
261
|
+
// return level;
|
|
262
|
+
// };
|
|
263
|
+
// const getDiffLevel = (diff: IDiffDataCalculate, diffList: IDiffDataCalculate[]) => {
|
|
264
|
+
// let level = 0;
|
|
265
|
+
// const setDiffItemLevel = (d: IDiffDataCalculate) => {
|
|
266
|
+
// for (let fI = 0, fLeng = d.measureFields.length; fI < fLeng; fI++) {
|
|
267
|
+
// const f = d.measureFields[fI];
|
|
268
|
+
// const calcDiff = diffList.find(item => item.measure && item.measure === f);
|
|
269
|
+
// if (d === calcDiff) {
|
|
270
|
+
// headerOfHasSelf.h = { key: calcDiff.measure } as IHeaderKey;
|
|
271
|
+
// break;
|
|
272
|
+
// }
|
|
273
|
+
// if (calcDiff) {
|
|
274
|
+
// level++;
|
|
275
|
+
// setDiffItemLevel(calcDiff);
|
|
276
|
+
// }
|
|
277
|
+
// }
|
|
278
|
+
// };
|
|
279
|
+
// setDiffItemLevel(diff);
|
|
280
|
+
// return level;
|
|
281
|
+
// };
|
|
282
|
+
// const setCalcDiffLevel = (list: IDiffDataCalculate[]) => {
|
|
283
|
+
// list.forEach(diff => {
|
|
284
|
+
// diff.diffLevel = getDiffLevel(diff, list);
|
|
285
|
+
// });
|
|
286
|
+
// };
|
|
287
|
+
// const getMergeLevel = (merge: IMergeDataCalculate, mergeList: IMergeDataCalculate[]) => {
|
|
288
|
+
// let level = 0;
|
|
289
|
+
// const setMergeItemLevel = (d: IMergeDataCalculate) => {
|
|
290
|
+
// for (let fI = 0, fLeng = d.measureFields.length; fI < fLeng; fI++) {
|
|
291
|
+
// const f = d.measureFields[fI];
|
|
292
|
+
// const calcMerge = mergeList.find(item => item.measureKey && item.measureKey === f);
|
|
293
|
+
// if (d === calcMerge) {
|
|
294
|
+
// headerOfHasSelf.h = { key: calcMerge.measureKey } as IHeaderKey;
|
|
295
|
+
// break;
|
|
296
|
+
// }
|
|
297
|
+
// if (calcMerge) {
|
|
298
|
+
// level++;
|
|
299
|
+
// setMergeItemLevel(calcMerge);
|
|
300
|
+
// }
|
|
301
|
+
// }
|
|
302
|
+
// };
|
|
303
|
+
// setMergeItemLevel(merge);
|
|
304
|
+
// return level;
|
|
305
|
+
// };
|
|
306
|
+
// const setMergeDiffLevel = (list: IMergeDataCalculate[]) => {
|
|
307
|
+
// list.forEach(merge => {
|
|
308
|
+
// merge.mergeLevel = getMergeLevel(merge, list);
|
|
309
|
+
// });
|
|
310
|
+
// }
|
|
311
|
+
// const setCalcLevel = (list: IHeaderKey[]) => {
|
|
312
|
+
// for (let i = 0, leng = list.length; i < leng; i++) {
|
|
313
|
+
// const h = list[i];
|
|
314
|
+
// if (h.itemCalculate || h.exprObject?.list?.length) {
|
|
315
|
+
// const { level, accLevel } = getHeaderLevel(h);
|
|
316
|
+
// h.calcLevel = level;
|
|
317
|
+
// h.accLevel = accLevel;
|
|
318
|
+
// }
|
|
319
|
+
// if (h.diffCalcList?.length && !h.calcLevel) {
|
|
320
|
+
// h.calcLevel = 0;
|
|
321
|
+
// }
|
|
322
|
+
// if (h.diffCalcList?.length) {
|
|
323
|
+
// setCalcDiffLevel(h.diffCalcList)
|
|
324
|
+
// }
|
|
325
|
+
// if (h.mergeCalcList?.length) {
|
|
326
|
+
// setMergeDiffLevel(h.mergeCalcList);
|
|
327
|
+
// }
|
|
328
|
+
// if (headerOfHasSelf.h) {
|
|
329
|
+
// break;
|
|
330
|
+
// }
|
|
331
|
+
// }
|
|
332
|
+
// };
|
|
333
|
+
// setCalcLevel(headerKeys);
|
|
334
|
+
this.setCalcLevel(headerKeys, headerKeysDic);
|
|
335
|
+
// const setCalcLevelAfterSort = (list: IHeaderKey[]) => {
|
|
336
|
+
// for (let i = 0, leng = list.length; i < leng; i++) {
|
|
337
|
+
// const h = list[i];
|
|
338
|
+
// if (h.itemCalculate || h.exprObject?.list?.length) {
|
|
339
|
+
// h.calcLevelAfterSort = getHeaderLevelAfterSort(h);
|
|
340
|
+
// }
|
|
341
|
+
// if (headerOfHasSelf.h) {
|
|
342
|
+
// break;
|
|
343
|
+
// }
|
|
344
|
+
// }
|
|
345
|
+
// }
|
|
346
|
+
// setCalcLevelAfterSort(headerKeys);
|
|
347
|
+
// if (headerOfHasSelf.h) {
|
|
348
|
+
// console.error(`${headerOfHasSelf.h.key}的计算公式中引用了自己`)
|
|
349
|
+
// return [];
|
|
350
|
+
// }
|
|
351
|
+
// const setHeaderComputeFn = (h: IHeaderKey, calcStr: string) => {
|
|
352
|
+
// const expr = calcStr;
|
|
353
|
+
// const fields = calcStr.match(CALCULATED_REGEX);
|
|
354
|
+
// let formula = expr;
|
|
355
|
+
// if (fields && fields.length) {
|
|
356
|
+
// const calcKeyList = [];
|
|
357
|
+
// for (let fI = 0, fLeng = fields.length; fI < fLeng; fI++) {
|
|
358
|
+
// const f = fields[fI];
|
|
359
|
+
// calcKeyList.push(f.replace('{', '').replace('}', ''));
|
|
360
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === f);
|
|
361
|
+
// if (headerItem) {
|
|
362
|
+
// let str = `data.data[${'"' + headerItem.key + '"'}]`;
|
|
363
|
+
// if (headerItem.dataType === 'NUMBER') {
|
|
364
|
+
// str = `(data.data[${'"' + headerItem.key + '"'}] || 0)`;
|
|
365
|
+
// }
|
|
366
|
+
// formula = formula.replace(f, str);
|
|
367
|
+
// } else {
|
|
368
|
+
// const newF = f.substring(1, f.length - 1);
|
|
369
|
+
// formula = formula.replace(f, '(data.data["' + newF + '"] || 0)');
|
|
370
|
+
// }
|
|
371
|
+
// }
|
|
372
|
+
// h.calcKeyList = calcKeyList;
|
|
373
|
+
// }
|
|
374
|
+
// const sumFields = formula.match(SUM_REGEX);
|
|
375
|
+
// const groupSumFields = formula.match(GROUP_SUM_REGEX);
|
|
376
|
+
// const getSizeFields = formula.match(GET_SIZE_REGEX);
|
|
377
|
+
// if (sumFields && sumFields.length && (!groupSumFields || !groupSumFields.length)) {
|
|
378
|
+
// formula = formula.replaceAll('sum((data.data[', '((data.extra.sum[');
|
|
379
|
+
// const sumKeyList = [];
|
|
380
|
+
// const newSumFields = calcStr.match(SUM_REGEX);
|
|
381
|
+
// newSumFields.forEach(sum => {
|
|
382
|
+
// sumKeyList.push(sum.replace('sum({', '').replace('})', ''));
|
|
383
|
+
// });
|
|
384
|
+
// h.sumKeyList = sumKeyList;
|
|
385
|
+
// }
|
|
386
|
+
// if (groupSumFields && groupSumFields.length) {
|
|
387
|
+
// formula = formula.replaceAll('group_sum((data.data[', '((data.extra.sum[');
|
|
388
|
+
// const groupSumKeyList = [];
|
|
389
|
+
// const newGroupSumFields = calcStr.match(GROUP_SUM_REGEX);
|
|
390
|
+
// newGroupSumFields.forEach(sum => {
|
|
391
|
+
// groupSumKeyList.push(sum.replace('group_sum({', '').replace('})', ''));
|
|
392
|
+
// });
|
|
393
|
+
// h.groupSumKeyList = groupSumKeyList;
|
|
394
|
+
// }
|
|
395
|
+
// if (getSizeFields && getSizeFields.length) {
|
|
396
|
+
// getSizeFields.forEach(field => {
|
|
397
|
+
// const f = field.replaceAll('getSize((data.data[', 'getSize(').replaceAll('] || 0)', '');
|
|
398
|
+
// formula = formula.replace(field, f);
|
|
399
|
+
// });
|
|
400
|
+
// }
|
|
401
|
+
// h.expr = expr2FnBody(formula);
|
|
402
|
+
// h.computeFn = getCatchFunction(expr2FnBody(formula));
|
|
403
|
+
// }
|
|
404
|
+
headerKeys.forEach(h => {
|
|
405
|
+
const { itemCalculate, totalCalculate } = h;
|
|
406
|
+
if (itemCalculate && !itemCalculate.startsWith('DATE_RANGE_SUM(') && !itemCalculate.startsWith('COR(')) {
|
|
407
|
+
this.setHeaderComputeFn(h, itemCalculate, headerKeysDic);
|
|
408
|
+
}
|
|
409
|
+
if (totalCalculate && totalCalculate.match(CALCULATED_REGEX)?.length && !h.computeFn) {
|
|
410
|
+
this.setHeaderComputeFn(h, totalCalculate, headerKeysDic);
|
|
411
|
+
}
|
|
412
|
+
if (h.styleConditionList?.length) {
|
|
413
|
+
setStyleComputeFn(h);
|
|
414
|
+
}
|
|
415
|
+
});
|
|
416
|
+
// console.log('headerKeys --> ', JSON.parse(JSON.stringify(headerKeys)))
|
|
417
|
+
return {
|
|
418
|
+
headerKeys,
|
|
419
|
+
headerKeysDic,
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
// 获取有几个 '['
|
|
423
|
+
getCount(k) {
|
|
424
|
+
let count = 0;
|
|
425
|
+
const indexArr = [];
|
|
426
|
+
while (k.indexOf('[', count) !== -1) {
|
|
427
|
+
const m = k.indexOf('[', count);
|
|
428
|
+
count = m + 1;
|
|
429
|
+
indexArr.push(m);
|
|
430
|
+
}
|
|
431
|
+
return indexArr.length;
|
|
432
|
+
}
|
|
433
|
+
;
|
|
434
|
+
getHeaderkeysDic(headerKeys) {
|
|
435
|
+
const headerKeysDic = {};
|
|
436
|
+
for (const h of headerKeys) {
|
|
437
|
+
headerKeysDic[h.key] = h;
|
|
438
|
+
}
|
|
439
|
+
return headerKeysDic;
|
|
440
|
+
}
|
|
441
|
+
getKeys(headers) {
|
|
442
|
+
const headerKeys = [];
|
|
443
|
+
const setKeys = (leng, index = 0, label = null, startI = 0, isHide = false, merge = null, parentWidthList = []) => {
|
|
444
|
+
for (let itemI = startI; itemI < leng; itemI++) {
|
|
445
|
+
const item = headers[index][itemI];
|
|
446
|
+
// 补足 ']'
|
|
447
|
+
let str = '';
|
|
448
|
+
if (item && item.key) {
|
|
449
|
+
const count = this.getCount(item.key);
|
|
450
|
+
if (count > 0) {
|
|
451
|
+
for (let i = 0; i < count; i++) {
|
|
452
|
+
str += ']';
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (item && (!label ?
|
|
457
|
+
item.key && index === 0 :
|
|
458
|
+
((item.key && item.key === `${label}[${item.label + str}`) ||
|
|
459
|
+
(item.parentKey && item.parentKey.startsWith(`${label}[`))))) {
|
|
460
|
+
// const newKey = item.key + (key || '');
|
|
461
|
+
const newKey = item.key;
|
|
462
|
+
if (!headerKeys.some(h => h.key === newKey)) {
|
|
463
|
+
const parentWidth = [...parentWidthList].reverse().find(w => w || w === 0);
|
|
464
|
+
if (item.format?.type === 'percent' && item.dataType === 'NUMBER') {
|
|
465
|
+
item.dataType = 'PERCENT';
|
|
466
|
+
}
|
|
467
|
+
const hKey = {
|
|
468
|
+
label: item.label,
|
|
469
|
+
key: newKey,
|
|
470
|
+
realKey: item.key,
|
|
471
|
+
dataType: item.dataType,
|
|
472
|
+
styleType: item.styleType,
|
|
473
|
+
digitsInfo: item.digitsInfo,
|
|
474
|
+
color: item.color,
|
|
475
|
+
tagMap: item.tagMap,
|
|
476
|
+
clickFn: item.clickFn,
|
|
477
|
+
width: item.width || parentWidth,
|
|
478
|
+
isDataRowspan: item.isDataRowspan || item.groupBy,
|
|
479
|
+
isDrill: item.isDrill,
|
|
480
|
+
nzLeft: item.nzLeft,
|
|
481
|
+
left: item.left,
|
|
482
|
+
calculated: item.calculated,
|
|
483
|
+
isSkcImage: item.isSkcImage,
|
|
484
|
+
customDrill: item.customDrill,
|
|
485
|
+
isProductImage: item.isProductImage,
|
|
486
|
+
customFilter: item.customFilter,
|
|
487
|
+
customNumberFilter: item.customNumberFilter,
|
|
488
|
+
showSort: item.showSort,
|
|
489
|
+
sortFn: item.sortFn,
|
|
490
|
+
sortOrder: item.sortOrder,
|
|
491
|
+
totalCalculate: item.totalCalculate,
|
|
492
|
+
itemCalculate: item.itemCalculate,
|
|
493
|
+
customDateFilter: item.customDateFilter,
|
|
494
|
+
isHide: item.isHide || isHide,
|
|
495
|
+
format: item.format,
|
|
496
|
+
showEditIcon: item.showEditIcon,
|
|
497
|
+
groupBy: item.groupBy,
|
|
498
|
+
rank: item.rank,
|
|
499
|
+
measureType: item.measureType,
|
|
500
|
+
isCalculateKey: item.isCalculateKey,
|
|
501
|
+
backgroundColor: item.backgroundColor,
|
|
502
|
+
exprObject: item.exprObject,
|
|
503
|
+
styleConditionList: item.styleConditionList,
|
|
504
|
+
subLabel: item.subLabel,
|
|
505
|
+
type: item.type,
|
|
506
|
+
fixed: item.fixed,
|
|
507
|
+
dateRangeSumList: item.dateRangeSumList,
|
|
508
|
+
mark: item.mark,
|
|
509
|
+
trigger: item.trigger,
|
|
510
|
+
action: item.action,
|
|
511
|
+
showSize: item.showSize,
|
|
512
|
+
isDateRange: item.isDateRange,
|
|
513
|
+
isTimeRange: item.isTimeRange,
|
|
514
|
+
groupKey: item.groupKey,
|
|
515
|
+
isMerge: merge ? merge.isMerge : false,
|
|
516
|
+
mergeChildren: merge ? merge.mergeChildren : null,
|
|
517
|
+
originalChildren: merge ? merge.originalChildren : item.originalChildren,
|
|
518
|
+
groupList: item.groupList,
|
|
519
|
+
computeFn: item.computeFn,
|
|
520
|
+
diffCalcList: item.diffCalcList,
|
|
521
|
+
diffStyleList: item.diffStyleList,
|
|
522
|
+
sumKeyList: item.sumKeyList,
|
|
523
|
+
groupSumKeyList: item.groupSumKeyList,
|
|
524
|
+
calcKeyList: item.calcKeyList,
|
|
525
|
+
mergeCalcList: item.mergeCalcList,
|
|
526
|
+
groupAggFunc: item.groupAggFunc,
|
|
527
|
+
style: item.style,
|
|
528
|
+
code: item.code,
|
|
529
|
+
bindDim: item.bindDim,
|
|
530
|
+
bindDimOrder: item.bindDimOrder,
|
|
531
|
+
bindDimOrderMeasureName: item.bindDimOrderMeasureName,
|
|
532
|
+
bindDimMeasureAlign: item.bindDimMeasureAlign,
|
|
533
|
+
bindDimOfParent: item.bindDimOfParent,
|
|
534
|
+
computeParam: item.computeParam,
|
|
535
|
+
showItemGroupSummary: item.showItemGroupSummary,
|
|
536
|
+
aggRange: item.aggRange,
|
|
537
|
+
dimType: item.dimType,
|
|
538
|
+
dimExpanded: item.dimExpanded,
|
|
539
|
+
};
|
|
540
|
+
// 分组合并分日期/合并尺码,计算方法
|
|
541
|
+
if (hKey.isMerge && hKey.label !== '度量') {
|
|
542
|
+
const firstLabel = hKey.key.substring(0, hKey.key.indexOf('['));
|
|
543
|
+
const isSize = hKey.originalChildren?.some(item => item.showSize);
|
|
544
|
+
hKey.originalChildren?.forEach(c => {
|
|
545
|
+
if (c.expr) {
|
|
546
|
+
let formula = c.expr;
|
|
547
|
+
const fields = c.expr.match(CALCULATED_REGEX);
|
|
548
|
+
fields?.forEach(f => {
|
|
549
|
+
if (f.startsWith(`{${firstLabel}[`)) {
|
|
550
|
+
const j = f.indexOf(']');
|
|
551
|
+
const newF = !isSize ?
|
|
552
|
+
f.substring(1, j) + '[' + (hKey.key.substring(hKey.key.indexOf('[') + 1, hKey.key.length - 1)) + ']' + f.substring(j, f.length - 1) :
|
|
553
|
+
hKey.key.substring(0, hKey.key.indexOf(']')) + (f.substring(f.indexOf('['), f.indexOf(']') + 1)) + hKey.key.substring(hKey.key.indexOf(']'));
|
|
554
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
555
|
+
}
|
|
556
|
+
else {
|
|
557
|
+
const newF = f.substring(1, f.length - 1);
|
|
558
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
const computeExpr = formula.replaceAll('{', '(data.data["').replaceAll('}', '"] || 0)');
|
|
562
|
+
if (!hKey.mergeCalcList) {
|
|
563
|
+
hKey.mergeCalcList = [];
|
|
564
|
+
}
|
|
565
|
+
hKey.mergeCalcList.push({
|
|
566
|
+
expr: formula,
|
|
567
|
+
measure: c.displayName,
|
|
568
|
+
measureKey: c.exprKey,
|
|
569
|
+
firstMeasureKey: `${firstLabel}[度量]`,
|
|
570
|
+
measureFields: fields.map(f => f.replace('{', '').replace('}', '')),
|
|
571
|
+
computeFn: getCatchFunction(expr2FnBody(computeExpr)),
|
|
572
|
+
mergeLevel: undefined,
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
if (c.style) {
|
|
576
|
+
if (!hKey.mergeStyleList) {
|
|
577
|
+
hKey.mergeStyleList = [];
|
|
578
|
+
}
|
|
579
|
+
const mergeStyle = {
|
|
580
|
+
color: c.style.color,
|
|
581
|
+
backgroundColor: c.style.backgroundColor,
|
|
582
|
+
measure: c.displayName,
|
|
583
|
+
measureKey: c.exprKey,
|
|
584
|
+
firstMeasureKey: `${firstLabel}[度量]`,
|
|
585
|
+
measureFields: [],
|
|
586
|
+
expr: '',
|
|
587
|
+
styleComputeFn: null,
|
|
588
|
+
};
|
|
589
|
+
const measureFields = [];
|
|
590
|
+
if (c.style.conditionList?.length) {
|
|
591
|
+
const conditionList = _.cloneDeep(c.style.conditionList);
|
|
592
|
+
conditionList.forEach(condition => {
|
|
593
|
+
if (condition.value) {
|
|
594
|
+
let formula = condition.value;
|
|
595
|
+
const fields = condition.value?.match(CALCULATED_REGEX);
|
|
596
|
+
if (fields && fields.length) {
|
|
597
|
+
fields?.forEach(f => {
|
|
598
|
+
if (f.startsWith(`{${firstLabel}[`)) {
|
|
599
|
+
const j = f.indexOf(']');
|
|
600
|
+
const newF = !isSize ?
|
|
601
|
+
f.substring(1, j) + '[' + (hKey.key.substring(hKey.key.indexOf('[') + 1, hKey.key.length - 1)) + ']' + f.substring(j, f.length - 1) :
|
|
602
|
+
hKey.key.substring(0, hKey.key.indexOf(']')) + (f.substring(f.indexOf('['), f.indexOf(']') + 1)) + hKey.key.substring(hKey.key.indexOf(']'));
|
|
603
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
const newF = f.substring(1, f.length - 1);
|
|
607
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
measureFields.push(...fields.map(f => f.replace('{', '').replace('}', '')));
|
|
611
|
+
}
|
|
612
|
+
condition.value = formula;
|
|
613
|
+
}
|
|
614
|
+
});
|
|
615
|
+
const styleComputeFn = getStyleConditionFn(c.style, conditionList, hKey.key, hKey.dataType);
|
|
616
|
+
mergeStyle.measureFields = measureFields;
|
|
617
|
+
mergeStyle.expr = styleComputeFn;
|
|
618
|
+
mergeStyle.styleComputeFn = getCatchFunction(styleComputeFn);
|
|
619
|
+
}
|
|
620
|
+
hKey.mergeStyleList.push(mergeStyle);
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
// 绑定维度竖排
|
|
625
|
+
if (hKey.bindDimOfParent?.bindDimMeasureAlign === 'vertical' || hKey.bindDimMeasureAlign === 'vertical') {
|
|
626
|
+
const firstLabel = hKey.key.substring(0, hKey.key.indexOf('['));
|
|
627
|
+
(hKey.bindDimOfParent?.originalChildren || hKey.originalChildren)?.forEach(c => {
|
|
628
|
+
if (c.expr) {
|
|
629
|
+
let formula = c.expr;
|
|
630
|
+
const fields = c.expr.match(CALCULATED_REGEX);
|
|
631
|
+
fields?.forEach(f => {
|
|
632
|
+
if (f.startsWith(`{${firstLabel}[`)) {
|
|
633
|
+
const j = f.includes(']') ? f.indexOf(']') : f.length;
|
|
634
|
+
;
|
|
635
|
+
const newF = f.substring(1, j) + '[' + (hKey.key.substring(hKey.key.indexOf('[') + 1, hKey.key.length - 1)) + ']' + f.substring(j, f.length - 1);
|
|
636
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
637
|
+
}
|
|
638
|
+
else {
|
|
639
|
+
const newF = f.substring(1, f.length - 1);
|
|
640
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
641
|
+
}
|
|
642
|
+
});
|
|
643
|
+
const computeExpr = formula.replaceAll('{', '(data.data["').replaceAll('}', '"] || 0)');
|
|
644
|
+
if (!hKey.mergeCalcList) {
|
|
645
|
+
hKey.mergeCalcList = [];
|
|
646
|
+
}
|
|
647
|
+
hKey.mergeCalcList.push({
|
|
648
|
+
expr: formula,
|
|
649
|
+
measure: c.displayName,
|
|
650
|
+
measureKey: c.exprKey,
|
|
651
|
+
firstMeasureKey: `度量`,
|
|
652
|
+
measureFields: fields.map(f => f.replace('{', '').replace('}', '')),
|
|
653
|
+
computeFn: getCatchFunction(expr2FnBody(computeExpr)),
|
|
654
|
+
mergeLevel: undefined,
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
if (c.style) {
|
|
658
|
+
if (!hKey.mergeStyleList) {
|
|
659
|
+
hKey.mergeStyleList = [];
|
|
660
|
+
}
|
|
661
|
+
const mergeStyle = {
|
|
662
|
+
color: c.style.color,
|
|
663
|
+
backgroundColor: c.style.backgroundColor,
|
|
664
|
+
measure: c.displayName,
|
|
665
|
+
measureKey: c.exprKey,
|
|
666
|
+
firstMeasureKey: `度量`,
|
|
667
|
+
measureFields: [],
|
|
668
|
+
expr: '',
|
|
669
|
+
styleComputeFn: null,
|
|
670
|
+
};
|
|
671
|
+
const measureFields = [];
|
|
672
|
+
if (c.style.conditionList?.length) {
|
|
673
|
+
const conditionList = _.cloneDeep(c.style.conditionList);
|
|
674
|
+
conditionList.forEach(condition => {
|
|
675
|
+
if (condition.value) {
|
|
676
|
+
let formula = condition.value;
|
|
677
|
+
const fields = condition.value?.match(CALCULATED_REGEX);
|
|
678
|
+
if (fields && fields.length) {
|
|
679
|
+
fields?.forEach(f => {
|
|
680
|
+
if (f.startsWith(`{${firstLabel}[`)) {
|
|
681
|
+
let j = f.includes(']') ? f.indexOf(']') : f.length;
|
|
682
|
+
const newF = f.substring(1, j) + '[' + (hKey.key.substring(hKey.key.indexOf('[') + 1, hKey.key.length - 1)) + ']' + f.substring(j, f.length - 1);
|
|
683
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
684
|
+
}
|
|
685
|
+
else {
|
|
686
|
+
const newF = f.substring(1, f.length - 1);
|
|
687
|
+
formula = formula.replace(f, `{${newF}}`);
|
|
688
|
+
}
|
|
689
|
+
});
|
|
690
|
+
measureFields.push(...fields.map(f => f.replace('{', '').replace('}', '')));
|
|
691
|
+
}
|
|
692
|
+
condition.value = formula;
|
|
693
|
+
}
|
|
694
|
+
});
|
|
695
|
+
const styleComputeFn = getStyleConditionFn(c.style, conditionList, hKey.key, hKey.dataType);
|
|
696
|
+
mergeStyle.measureFields = measureFields;
|
|
697
|
+
mergeStyle.expr = styleComputeFn;
|
|
698
|
+
mergeStyle.styleComputeFn = getCatchFunction(styleComputeFn);
|
|
699
|
+
}
|
|
700
|
+
hKey.mergeStyleList.push(mergeStyle);
|
|
701
|
+
}
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
headerKeys.push(hKey);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (item && !item.key) {
|
|
708
|
+
let nextStartI = 0;
|
|
709
|
+
let nextleng = 0;
|
|
710
|
+
for (let j = 0; j < itemI; j++) {
|
|
711
|
+
const beforeItem = headers[index][j];
|
|
712
|
+
if (!item.hasOwnProperty('realColspan') && beforeItem.colspan) {
|
|
713
|
+
nextStartI += beforeItem.colspan;
|
|
714
|
+
}
|
|
715
|
+
if (item.hasOwnProperty('realColspan') && beforeItem.realColspan) {
|
|
716
|
+
nextStartI += beforeItem.realColspan;
|
|
717
|
+
}
|
|
718
|
+
}
|
|
719
|
+
nextleng = nextStartI + (item.hasOwnProperty('realColspan') ? item.realColspan : item.colspan);
|
|
720
|
+
parentWidthList.push(item.width);
|
|
721
|
+
setKeys(nextleng, index + 1, !label ? item.label : `${label}[${item.label}`, nextStartI, item.isHide || false, item, parentWidthList);
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
if (headers?.length) {
|
|
726
|
+
setKeys(headers[0].length);
|
|
727
|
+
}
|
|
728
|
+
return headerKeys;
|
|
729
|
+
}
|
|
730
|
+
;
|
|
731
|
+
setHeaderLevel(h, headerSelf, headerKeysDic, levelObj) {
|
|
732
|
+
if (h.itemCalculate) {
|
|
733
|
+
const expr = h.itemCalculate;
|
|
734
|
+
let fields = expr.match(CALCULATED_REGEX);
|
|
735
|
+
fields = _.uniq(fields);
|
|
736
|
+
if (fields && fields.length) {
|
|
737
|
+
for (let fI = 0, fLeng = fields.length; fI < fLeng; fI++) {
|
|
738
|
+
const f = fields[fI];
|
|
739
|
+
// const headerItem = headerKeys.find(item => item.key && `{${item.key}}` === f);
|
|
740
|
+
const headerItem = headerKeysDic[f.substring(1, f.length - 1)];
|
|
741
|
+
if (headerSelf?.key === headerItem?.key) {
|
|
742
|
+
// headerOfHasSelf.h = header;
|
|
743
|
+
throw new Error(`${headerSelf.label}计算公式中引用了自己`);
|
|
744
|
+
}
|
|
745
|
+
if (ONCE_CALC_LIST.includes(headerItem?.measureType)) {
|
|
746
|
+
if (!ONCE_CALC_LIST.includes(h.measureType)) {
|
|
747
|
+
levelObj.accLevel = levelObj.level + 1;
|
|
748
|
+
}
|
|
749
|
+
levelObj.level = levelObj.level + 1;
|
|
750
|
+
break;
|
|
751
|
+
}
|
|
752
|
+
if (headerItem?.itemCalculate || headerItem?.exprObject?.list?.length) {
|
|
753
|
+
levelObj.level++;
|
|
754
|
+
this.setHeaderLevel(headerItem, headerSelf, headerKeysDic, levelObj);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
}
|
|
759
|
+
if (h.exprObject?.list?.length) {
|
|
760
|
+
const levelList = [];
|
|
761
|
+
h.exprObject.list.forEach(exprObj => {
|
|
762
|
+
exprObj.itemCalculate = exprObj.expr;
|
|
763
|
+
const exprObjLevel = this.getHeaderLevel(exprObj, headerKeysDic).level;
|
|
764
|
+
levelList.push(exprObjLevel);
|
|
765
|
+
});
|
|
766
|
+
if (levelList?.length) {
|
|
767
|
+
const exprObjLevel = Math.max(...levelList);
|
|
768
|
+
levelObj.level = exprObjLevel > levelObj.level ? exprObjLevel : levelObj.level;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
setMergeDiffLevel(list) {
|
|
773
|
+
const mergeDic = {};
|
|
774
|
+
for (const item of list) {
|
|
775
|
+
if (item.measureKey) {
|
|
776
|
+
mergeDic[item.measureKey] = item;
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
list.forEach(merge => {
|
|
780
|
+
merge.mergeLevel = this.getMergeLevel(merge, mergeDic);
|
|
781
|
+
});
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
// const ezTableHeaderKeys = new EZTableHeaderKeys();
|
|
785
|
+
// export default ezTableHeaderKeys;
|