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/setBindDim.js
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import _ from "lodash";
|
|
2
|
+
import { cloneDeepTree, getMeasureDataType } from "./utils";
|
|
3
|
+
const getEndNameKey = (currentKey, displayName) => {
|
|
4
|
+
const lastIndex = currentKey.includes(']') ? currentKey.indexOf(']') : currentKey.length;
|
|
5
|
+
let key = currentKey.substring(0, lastIndex) + `[${displayName}]` + currentKey.substring(lastIndex);
|
|
6
|
+
return key;
|
|
7
|
+
};
|
|
8
|
+
const isBindDimVertical = (item) => {
|
|
9
|
+
return item.bindDimOfParent?.bindDimMeasureAlign === 'vertical' || item.bindDimMeasureAlign === 'vertical';
|
|
10
|
+
};
|
|
11
|
+
export const setBindDimChildren = (children, headerKeysOfBindDimVertical) => {
|
|
12
|
+
if (headerKeysOfBindDimVertical?.length && children.length) {
|
|
13
|
+
const firstBindDimVerticalIndex = headerKeysOfBindDimVertical.findIndex(header => isBindDimVertical(header));
|
|
14
|
+
;
|
|
15
|
+
const firstBindDimVerticalH = headerKeysOfBindDimVertical[firstBindDimVerticalIndex];
|
|
16
|
+
// const measureList = _.cloneDeep(firstBindDimVerticalH.originalChildren).filter(item => !item.isHide);
|
|
17
|
+
const measureList = [...firstBindDimVerticalH.originalChildren].filter(item => !item.isHide);
|
|
18
|
+
const measureListLeng = measureList.length;
|
|
19
|
+
const verticalKeys = headerKeysOfBindDimVertical.filter(item => isBindDimVertical(item));
|
|
20
|
+
for (let i = 0, leng = children.length * measureListLeng; i < leng; i++) {
|
|
21
|
+
const item = children[i];
|
|
22
|
+
item.same = {
|
|
23
|
+
index: i,
|
|
24
|
+
};
|
|
25
|
+
if (!item.hideTd) {
|
|
26
|
+
item.hideTd = {};
|
|
27
|
+
}
|
|
28
|
+
// dimKeyList.forEach(dim => {
|
|
29
|
+
// item.hideTd[dim.key] = true;
|
|
30
|
+
// })
|
|
31
|
+
headerKeysOfBindDimVertical.forEach(dim => {
|
|
32
|
+
if (!dim.originalChildren?.length) {
|
|
33
|
+
item.hideTd[dim.key] = true;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
const newData = { ...item };
|
|
37
|
+
if (i % measureListLeng === 0) {
|
|
38
|
+
measureList.forEach((child, j) => {
|
|
39
|
+
if (j === 0) {
|
|
40
|
+
item.data['度量'] = child.displayName;
|
|
41
|
+
verticalKeys.forEach(vk => {
|
|
42
|
+
const verticalHeader = headerKeysOfBindDimVertical.find(header => header.key === vk.key);
|
|
43
|
+
// const verticalHeader = headerKeysDic[vk.key];
|
|
44
|
+
if (verticalHeader && verticalHeader.originalChildren?.length) {
|
|
45
|
+
child = verticalHeader.originalChildren.filter(item => !item.isHide)[j];
|
|
46
|
+
}
|
|
47
|
+
if (child) {
|
|
48
|
+
item.data[vk.key] = item.data[getEndNameKey(vk.key, child?.displayName)];
|
|
49
|
+
if (!item.dataType) {
|
|
50
|
+
item.dataType = {};
|
|
51
|
+
}
|
|
52
|
+
if (!item.format) {
|
|
53
|
+
item.format = {};
|
|
54
|
+
}
|
|
55
|
+
if (!item.style) {
|
|
56
|
+
item.style = {};
|
|
57
|
+
}
|
|
58
|
+
item.dataType[vk.key] = getMeasureDataType(child);
|
|
59
|
+
item.format[vk.key] = child?.format;
|
|
60
|
+
item.style[vk.key] = child?.style;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// const arr = JSON.parse(JSON.stringify(new Array(measureListLeng - 1).fill({...newData})));
|
|
66
|
+
const arr = cloneDeepTree(new Array(measureListLeng - 1).fill({ ...newData }));
|
|
67
|
+
// item.hideTd.isHideTdStart = true;
|
|
68
|
+
arr.forEach((d, dI) => {
|
|
69
|
+
const measure = measureList[dI + 1];
|
|
70
|
+
const { isHide } = measure;
|
|
71
|
+
d.same.index = i;
|
|
72
|
+
// if (dI === arr.length - 1 && !isHide) {
|
|
73
|
+
// d.hideTd.isHideTdEnd = true;
|
|
74
|
+
// d.hideTd.isHideTd = true;
|
|
75
|
+
// } else {
|
|
76
|
+
// d.hideTd.isHideTd = true;
|
|
77
|
+
// }
|
|
78
|
+
d.isHide = isHide;
|
|
79
|
+
measureList.forEach((child, j) => {
|
|
80
|
+
if (dI === j - 1) {
|
|
81
|
+
d.data['度量'] = child.displayName;
|
|
82
|
+
verticalKeys.forEach(vk => {
|
|
83
|
+
const verticalHeader = headerKeysOfBindDimVertical.find(header => header.key === vk.key);
|
|
84
|
+
// const verticalHeader = headerKeysDic[vk.key];
|
|
85
|
+
if (verticalHeader && verticalHeader.originalChildren?.length) {
|
|
86
|
+
child = verticalHeader.originalChildren.filter(item => !item.isHide)[j];
|
|
87
|
+
}
|
|
88
|
+
if (child) {
|
|
89
|
+
d.data[vk.key] = d.data[getEndNameKey(vk.key, child.displayName)];
|
|
90
|
+
if (!d.dataType) {
|
|
91
|
+
d.dataType = {};
|
|
92
|
+
}
|
|
93
|
+
if (!d.format) {
|
|
94
|
+
d.format = {};
|
|
95
|
+
}
|
|
96
|
+
if (!d.style) {
|
|
97
|
+
d.style = {};
|
|
98
|
+
}
|
|
99
|
+
d.dataType[vk.key] = getMeasureDataType(child);
|
|
100
|
+
d.format[vk.key] = child?.format;
|
|
101
|
+
d.style[vk.key] = child?.style;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
// dimKeyList.forEach(dim => {
|
|
107
|
+
// d.data[dim.key] = '';
|
|
108
|
+
// if (dI === arr.length - 1) {
|
|
109
|
+
// d.hideTd[dim.key] = false;
|
|
110
|
+
// }
|
|
111
|
+
// })
|
|
112
|
+
headerKeysOfBindDimVertical.forEach(dim => {
|
|
113
|
+
if (!dim.originalChildren?.length) {
|
|
114
|
+
d.data[dim.key] = null;
|
|
115
|
+
if (dI === arr.length - 1) {
|
|
116
|
+
d.hideTd[dim.key] = false;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
// item.hideTd.isHideTdEnd = arr.every(a => a.isHide);
|
|
122
|
+
children.splice(i + 1, 0, ...arr);
|
|
123
|
+
i += (measureListLeng - 1);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
export const setSortOfBindDim = (headerKeys, headers, totalData) => {
|
|
129
|
+
const bindDimList = [];
|
|
130
|
+
headerKeys.forEach(header => {
|
|
131
|
+
if (header.bindDimOfParent && header.bindDimOfParent.bindDimOrder && header.bindDimOfParent.bindDimOrderMeasureName?.length) {
|
|
132
|
+
let bind = bindDimList.find(l => l.code === header.bindDimOfParent.code);
|
|
133
|
+
if (!bind) {
|
|
134
|
+
bind = {
|
|
135
|
+
...header.bindDimOfParent,
|
|
136
|
+
list: [],
|
|
137
|
+
};
|
|
138
|
+
bindDimList.push(bind);
|
|
139
|
+
}
|
|
140
|
+
bind.list.push(header);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const data = totalData;
|
|
144
|
+
bindDimList.forEach(item => {
|
|
145
|
+
item.list = _.chunk(item.list, item.leng);
|
|
146
|
+
item.list.sort((a, b) => {
|
|
147
|
+
const aSortMeasure = a.find(h => h.label === item.bindDimOrderMeasureName[0]);
|
|
148
|
+
const bSortMeasure = b.find(h => h.label === item.bindDimOrderMeasureName[0]);
|
|
149
|
+
const aValue = data[aSortMeasure.key];
|
|
150
|
+
const bValue = data[bSortMeasure.key];
|
|
151
|
+
return item.bindDimOrder === 'asc' ? ((aValue || 0) - (bValue || 0)) : ((bValue || 0) - (aValue || 0));
|
|
152
|
+
});
|
|
153
|
+
const list = [];
|
|
154
|
+
item.list.forEach(l => {
|
|
155
|
+
list.push(...l);
|
|
156
|
+
});
|
|
157
|
+
headers.forEach((headerList, i) => {
|
|
158
|
+
const index = headerList.findIndex(h => h.code === item.code);
|
|
159
|
+
if (index > -1) {
|
|
160
|
+
const listOfBind = headerList.filter(h => h.code === item.code);
|
|
161
|
+
listOfBind.sort((a, b) => {
|
|
162
|
+
const aIndex = item.list.findIndex(l => l[0].key.includes(a.label));
|
|
163
|
+
const bIndex = item.list.findIndex(l => l[0].key.includes(b.label));
|
|
164
|
+
return aIndex - bIndex;
|
|
165
|
+
});
|
|
166
|
+
headerList.splice(index, item.list.length, ...listOfBind);
|
|
167
|
+
if (headers[i + 1]) {
|
|
168
|
+
headers[i + 1].sort((a, b) => {
|
|
169
|
+
const aIndex = headerList.findIndex(h => h.bindDim && a.key?.includes(h.label));
|
|
170
|
+
const bIndex = headerList.findIndex(h => h.bindDim && b.key?.includes(h.label));
|
|
171
|
+
return aIndex - bIndex;
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
headerKeys.splice(headerKeys.findIndex(h => h.bindDimOfParent && h.bindDimOfParent.code === item.code), list.length, ...list);
|
|
177
|
+
});
|
|
178
|
+
};
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { ezNumber } from "./ezNumber";
|
|
2
|
+
import { getCalcValue, getImageDisplayName } from "./utils";
|
|
3
|
+
export function setDisplayData(headerKeys, dimKeyList, tree, onlyTotal = false) {
|
|
4
|
+
const secondKey = headerKeys[1].key;
|
|
5
|
+
headerKeys.forEach((header, i) => {
|
|
6
|
+
setDisplayDataRecursive(tree, header, secondKey, dimKeyList, tree, onlyTotal);
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
function getCell(data, h) {
|
|
10
|
+
if (!data.displayData) {
|
|
11
|
+
data.displayData = {};
|
|
12
|
+
}
|
|
13
|
+
if (!data.displayData[h.key]) {
|
|
14
|
+
data.displayData[h.key] = {};
|
|
15
|
+
}
|
|
16
|
+
// 表示每一个格子
|
|
17
|
+
return data.displayData[h.key];
|
|
18
|
+
}
|
|
19
|
+
function getValue(data, h) {
|
|
20
|
+
if (h.isProductImage) {
|
|
21
|
+
return getImageDisplayName(data.data[h.key]);
|
|
22
|
+
}
|
|
23
|
+
return data.data[h.key];
|
|
24
|
+
}
|
|
25
|
+
function setDisplayDataRecursive(treeData, h, secondKey, dimKeyList, originalTree, onlyTotal = false) {
|
|
26
|
+
treeData.forEach((data) => {
|
|
27
|
+
if (onlyTotal && !data.children) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// if (!data.displayData) {
|
|
31
|
+
// data.displayData = {};
|
|
32
|
+
// }
|
|
33
|
+
// if (!data.displayData[h.key]) {
|
|
34
|
+
// data.displayData[h.key] = {};
|
|
35
|
+
// }
|
|
36
|
+
// 表示每一个格子
|
|
37
|
+
const cell = getCell(data, h);
|
|
38
|
+
let value = getValue(data, h);
|
|
39
|
+
if (value === -Infinity || value === Infinity) {
|
|
40
|
+
value = '';
|
|
41
|
+
}
|
|
42
|
+
if (treeData === originalTree && h.dimType === 'CONDITION') {
|
|
43
|
+
value = '';
|
|
44
|
+
}
|
|
45
|
+
setDisplayValue(cell, value, data, h);
|
|
46
|
+
setDisplayStyle(cell, h, data);
|
|
47
|
+
setMergeStyle(cell, h, data);
|
|
48
|
+
if (data.isTotal &&
|
|
49
|
+
(['#fff', 'rgba(255, 255, 255, 1)'].includes(cell.displayBackground) ||
|
|
50
|
+
(cell.displayBackground && parseFloat(cell.displayBackground.split(',').pop()) === 0))) {
|
|
51
|
+
cell.displayBackground = null;
|
|
52
|
+
}
|
|
53
|
+
if (shouldDisplayNumberStyle(h, data)) {
|
|
54
|
+
setDisplayNumberStyle(cell, value, data, h, secondKey, dimKeyList, originalTree);
|
|
55
|
+
}
|
|
56
|
+
if (data.children?.length) {
|
|
57
|
+
setDisplayDataRecursive(data.children, h, secondKey, dimKeyList, originalTree);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function setDisplayValue(cell, value, data, h) {
|
|
62
|
+
const displayValue = ezNumber(value, data.dataType && data.dataType[h.key] ? data.dataType[h.key] : h.dataType, data.digitsInfo && data.digitsInfo[h.key] ? data.digitsInfo[h.key] : h.digitsInfo, '', data.format && data.format[h.key] ? data.format[h.key] : h.format);
|
|
63
|
+
cell.displayValue = displayValue;
|
|
64
|
+
}
|
|
65
|
+
function setDisplayStyle(cell, h, data) {
|
|
66
|
+
cell.displayColor = h.color;
|
|
67
|
+
cell.displayBackground = h.backgroundColor;
|
|
68
|
+
cell.displayFontWeight = h.style && h.style.bold ? 'bold' : null;
|
|
69
|
+
cell.displayFontStyle = h.style && h.style.italic ? 'italic' : null;
|
|
70
|
+
cell.displayTextDecoration = h.style && h.style.underline ? 'underline' : null;
|
|
71
|
+
cell.displayFontSize = h.style && h.style.fontSize ? (h.style.fontSize + 'px') : null;
|
|
72
|
+
cell.displayTextAlign = h.style && h.style.horizontalAlign ? h.style.horizontalAlign : null;
|
|
73
|
+
cell.displayChildStyle = {
|
|
74
|
+
displayTextDecoration: h.style && h.style.strike ? 'line-through' : null,
|
|
75
|
+
};
|
|
76
|
+
if (h.styleComputeFn) {
|
|
77
|
+
const style = getCalcValue(h.styleComputeFn, { data: data.data });
|
|
78
|
+
if (style) {
|
|
79
|
+
cell.displayColor = style.color;
|
|
80
|
+
cell.displayBackground = style.backgroundColor;
|
|
81
|
+
cell.displayFontWeight = style.fontWeight;
|
|
82
|
+
cell.displayFontStyle = style.fontStyle;
|
|
83
|
+
cell.displayTextDecoration = style.textDecoration;
|
|
84
|
+
cell.displayTextAlign = style.textAlign;
|
|
85
|
+
if (style.fontSize !== 'null') {
|
|
86
|
+
cell.displayFontSize = style.fontSize;
|
|
87
|
+
}
|
|
88
|
+
cell.displayChildStyle = {
|
|
89
|
+
displayTextDecoration: style.childStyle.textDecoration,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
if (h.style?.hideGroupTotalStyle && data.children) {
|
|
94
|
+
cell.displayBackground = '#d9d9d9';
|
|
95
|
+
cell.displayColor = 'rgba(0, 0, 0, 0.85)';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
// 合并分日期/分尺码的样式
|
|
99
|
+
function setMergeStyle(cell, h, data) {
|
|
100
|
+
if (h.mergeStyleList?.length) {
|
|
101
|
+
const merge = h.mergeStyleList.find(item => data.data[item.firstMeasureKey] === item.measure);
|
|
102
|
+
if (merge) {
|
|
103
|
+
cell.displayColor = merge.color;
|
|
104
|
+
cell.displayBackground = merge.backgroundColor;
|
|
105
|
+
if (merge.styleComputeFn) {
|
|
106
|
+
const style = getCalcValue(merge.styleComputeFn, { data: data.data });
|
|
107
|
+
if (style) {
|
|
108
|
+
cell.displayColor = style.color;
|
|
109
|
+
cell.displayBackground = style.backgroundColor;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function shouldDisplayNumberStyle(h, data) {
|
|
116
|
+
return (data.format &&
|
|
117
|
+
data.format[h.key] &&
|
|
118
|
+
['percent', 'number'].includes(data.format[h.key].type) ||
|
|
119
|
+
(!data.format ||
|
|
120
|
+
(data.format &&
|
|
121
|
+
data.format[h.key] &&
|
|
122
|
+
['percent', 'number'].includes(data.format[h.key].type))) &&
|
|
123
|
+
(['PERCENT', 'NUMBER'].includes(h.dataType)) ||
|
|
124
|
+
(h.measureType === 'CONDITION' && data.format === 'NUMBER'));
|
|
125
|
+
}
|
|
126
|
+
function setDisplayNumberStyle(cell, value, data, h, secondKey, dimKeyList, tree) {
|
|
127
|
+
if (!cell.displayNumberStyle) {
|
|
128
|
+
cell.displayNumberStyle = {
|
|
129
|
+
isNumber: true,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
const displayNumberStyle = cell.displayNumberStyle;
|
|
133
|
+
const displayDataType = (h.measureType === 'CONDITION' && h.dataType === 'STRING' ?
|
|
134
|
+
'NUMBER' :
|
|
135
|
+
data.dataType && data.dataType[h.key] ?
|
|
136
|
+
data.dataType[h.key] :
|
|
137
|
+
(h.dataType || null));
|
|
138
|
+
const displayStyleType = (data.format && data.format[h.key] ? (data.styleType && data.styleType[h.key] ?
|
|
139
|
+
data.styleType[h.key] :
|
|
140
|
+
null) : (['PERCENT', 'NUMBER'].includes(h.dataType) || h.measureType === 'CONDITION') ? h.styleType :
|
|
141
|
+
null);
|
|
142
|
+
const displayFormat = (data.format && data.format[h.key] ?
|
|
143
|
+
data.format && data.format[h.key] :
|
|
144
|
+
h.format);
|
|
145
|
+
const displayDigitsInfo = h.digitsInfo;
|
|
146
|
+
const displayIsCondition = h.measureType === 'CONDITION' && h.dataType === 'STRING';
|
|
147
|
+
displayNumberStyle.dataType = displayDataType;
|
|
148
|
+
displayNumberStyle.styleType = displayStyleType;
|
|
149
|
+
displayNumberStyle.format = displayFormat;
|
|
150
|
+
displayNumberStyle.digitsInfo = displayDigitsInfo;
|
|
151
|
+
displayNumberStyle.isCondition = displayIsCondition;
|
|
152
|
+
// 设置趋势,上升或则下降
|
|
153
|
+
displayNumberStyle.trend = null;
|
|
154
|
+
if (value !== Infinity && value > 0) {
|
|
155
|
+
displayNumberStyle.trend = 'up';
|
|
156
|
+
}
|
|
157
|
+
else if (value !== -Infinity && value < 0) {
|
|
158
|
+
displayNumberStyle.trend = 'down';
|
|
159
|
+
}
|
|
160
|
+
// 设置进度条
|
|
161
|
+
if (shouldDisplayProgressBar(displayStyleType, displayIsCondition, value)) {
|
|
162
|
+
setProgressBar(h, data, value, displayNumberStyle, displayFormat, displayIsCondition, secondKey, tree, dimKeyList);
|
|
163
|
+
}
|
|
164
|
+
// 设置展示的值
|
|
165
|
+
cell.displayValue = ezNumber(value, displayDataType, displayDigitsInfo, '', displayFormat, displayIsCondition);
|
|
166
|
+
}
|
|
167
|
+
function shouldDisplayProgressBar(displayStyleType, displayIsCondition, value) {
|
|
168
|
+
return (displayStyleType === 'progress' &&
|
|
169
|
+
(!displayIsCondition ||
|
|
170
|
+
(displayIsCondition &&
|
|
171
|
+
!isNaN(value))));
|
|
172
|
+
}
|
|
173
|
+
function setProgressBar(h, data, value, displayNumberStyle, displayFormat, displayIsCondition, secondKey, tree, dimKeyList) {
|
|
174
|
+
displayNumberStyle.isProgress = true;
|
|
175
|
+
displayNumberStyle.progressWidth = ezNumber(value, 'percent', null, '', displayFormat, displayIsCondition);
|
|
176
|
+
if (displayFormat.type === 'number') {
|
|
177
|
+
if (displayFormat.max && typeof displayFormat.max === 'number') {
|
|
178
|
+
displayNumberStyle.progressWidth = ezNumber(value / displayFormat.max, 'percent', '1.0-2', '');
|
|
179
|
+
}
|
|
180
|
+
else if (displayFormat.max === '合计值') {
|
|
181
|
+
displayNumberStyle.progressWidth = ezNumber(value / tree[0].data[h.key], 'percent', '1.0-2', '');
|
|
182
|
+
}
|
|
183
|
+
else if (displayFormat.max === '分组合计值') {
|
|
184
|
+
if (data.isTotal && data[secondKey] === '合计') {
|
|
185
|
+
displayNumberStyle.progressWidth = ezNumber(value / tree[0].data[h.key], 'percent', '1.0-2', '');
|
|
186
|
+
}
|
|
187
|
+
else if (!data.isTotal) {
|
|
188
|
+
// const lastDim = dimList[dimList.length - 1];
|
|
189
|
+
const total = data.parent?.data || data.data;
|
|
190
|
+
if (total) {
|
|
191
|
+
displayNumberStyle.progressWidth = ezNumber(value / total[h.key], 'percent', '1.0-2', '');
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
else if (data.isTotal && data[secondKey] !== '合计') {
|
|
195
|
+
const dimIndex = dimKeyList.findIndex(item => data[item.key] === '合计');
|
|
196
|
+
if (dimIndex > -1) {
|
|
197
|
+
// const dim = dimList[dimIndex - 1];
|
|
198
|
+
const total = data.parent?.data || data.data;
|
|
199
|
+
if (total) {
|
|
200
|
+
displayNumberStyle.progressWidth = ezNumber(value / total[h.key], 'percent', '1.0-2', '');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
displayNumberStyle.progressBackground = displayFormat && ['percent', 'number'].includes(displayFormat.type) ? displayFormat.progressColor : 'unset';
|
|
207
|
+
}
|
package/setMergeData.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import { cloneDeepTree } from "./utils";
|
|
2
|
+
// const getKey = (m: IDisplayMeasure) => {
|
|
3
|
+
// let key = m.displayName;
|
|
4
|
+
// const deepMeasure = (list: IDisplayMeasure[]) => {
|
|
5
|
+
// if (list && list.length) {
|
|
6
|
+
// const item = list[0];
|
|
7
|
+
// if (item.displayName !== '度量') {
|
|
8
|
+
// key += `[${item.displayName}`;
|
|
9
|
+
// if (item.children?.length) {
|
|
10
|
+
// deepMeasure(item.children);
|
|
11
|
+
// }
|
|
12
|
+
// }
|
|
13
|
+
// }
|
|
14
|
+
// };
|
|
15
|
+
// deepMeasure(m.children);
|
|
16
|
+
// const leng = key.split('[').length - 1;
|
|
17
|
+
// if (leng > 0) {
|
|
18
|
+
// key = _.padEnd(key, key.length + leng, ']');
|
|
19
|
+
// }
|
|
20
|
+
// return key;
|
|
21
|
+
// };
|
|
22
|
+
const getKey = (m) => {
|
|
23
|
+
const keyParts = [m.displayName];
|
|
24
|
+
const deepMeasure = (list) => {
|
|
25
|
+
if (list && list.length) {
|
|
26
|
+
const item = list[0];
|
|
27
|
+
if (item.displayName !== '度量') {
|
|
28
|
+
keyParts.push(item.displayName);
|
|
29
|
+
if (item.children?.length) {
|
|
30
|
+
deepMeasure(item.children);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
deepMeasure(m.children);
|
|
36
|
+
const numBrackets = keyParts.length - 1;
|
|
37
|
+
const key = `${keyParts.join('[')}${']'.repeat(numBrackets)}`;
|
|
38
|
+
return key;
|
|
39
|
+
};
|
|
40
|
+
const getEndNameKey = (mDisplayName, sizeKey, displayName) => {
|
|
41
|
+
let key = `${mDisplayName}[${sizeKey.substring(0, sizeKey.indexOf(']'))}`;
|
|
42
|
+
key += `[${displayName}`;
|
|
43
|
+
const leng1 = key.split('[').length - 1;
|
|
44
|
+
if (leng1 > 0) {
|
|
45
|
+
// key = _.padEnd(key, key.length + leng1, ']');
|
|
46
|
+
key += ']'.repeat(leng1);
|
|
47
|
+
}
|
|
48
|
+
return key;
|
|
49
|
+
};
|
|
50
|
+
const getHeader = (mergeChildren, mDisplayName, child, value, headerKeysDic) => {
|
|
51
|
+
let header = null;
|
|
52
|
+
for (let i = 1, leng = mergeChildren.length; i < leng; i++) {
|
|
53
|
+
let sameKey = `${mDisplayName}[${child.displayName}[${mergeChildren[i].sizeKey}]]`;
|
|
54
|
+
if (child.expr) {
|
|
55
|
+
if (value === undefined) {
|
|
56
|
+
sameKey = `${mDisplayName}[${child.displayName}[${i}]]`;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
// header = this.headerKeys.find(h => h.key === sameKey);
|
|
60
|
+
header = headerKeysDic[sameKey];
|
|
61
|
+
if (header) {
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return header;
|
|
66
|
+
};
|
|
67
|
+
export const setMergeChildren = (children, headerKeysOfMerge, headerKeysDic, dimKeyList) => {
|
|
68
|
+
if (children?.length) {
|
|
69
|
+
const firstMergeH = headerKeysOfMerge.find(header => header.isMerge && header.label === '度量');
|
|
70
|
+
const originalChildren = firstMergeH?.originalChildren.filter(item => !item.isHide);
|
|
71
|
+
const mergeChildren = firstMergeH?.mergeChildren;
|
|
72
|
+
const showSize = originalChildren?.some(item => item.showSize);
|
|
73
|
+
// const measureList = _.cloneDeep(originalChildren);
|
|
74
|
+
const measureList = [...originalChildren];
|
|
75
|
+
const measureListLeng = measureList.length;
|
|
76
|
+
const mDisplayName = firstMergeH.key.substring(0, firstMergeH.key.indexOf('['));
|
|
77
|
+
mergeChildren.forEach((m, mI) => {
|
|
78
|
+
if (showSize ? mI > 1 : mI > 0) {
|
|
79
|
+
const sizeKey = getKey(m);
|
|
80
|
+
const key = `${mDisplayName}[${sizeKey}]`;
|
|
81
|
+
m.headerKey = key;
|
|
82
|
+
m.sizeKey = sizeKey;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
for (let i = 0, leng = children.length * measureListLeng; i < leng; i++) {
|
|
86
|
+
const item = children[i];
|
|
87
|
+
item.same = {
|
|
88
|
+
index: i,
|
|
89
|
+
};
|
|
90
|
+
// // if (!item.dataType) {
|
|
91
|
+
// // item.dataType = {};
|
|
92
|
+
// // }
|
|
93
|
+
// // if (!item.format) {
|
|
94
|
+
// // item.format = {};
|
|
95
|
+
// // }
|
|
96
|
+
// // if (!item.style) {
|
|
97
|
+
// // item.style = {};
|
|
98
|
+
// // }
|
|
99
|
+
if (!item.hideTd) {
|
|
100
|
+
item.hideTd = {};
|
|
101
|
+
}
|
|
102
|
+
dimKeyList.forEach(dim => {
|
|
103
|
+
item.hideTd[dim.key] = true;
|
|
104
|
+
});
|
|
105
|
+
const newData = { ...item };
|
|
106
|
+
if (i % measureListLeng === 0) {
|
|
107
|
+
originalChildren.forEach((child, j) => {
|
|
108
|
+
if (j === 0) {
|
|
109
|
+
item.data[`${mDisplayName}[度量]`] = child.displayName;
|
|
110
|
+
mergeChildren.forEach((m, mI) => {
|
|
111
|
+
if (showSize ? mI > 1 : mI > 0) {
|
|
112
|
+
const value = item.data[`${mDisplayName}[${child.displayName}[${m.sizeKey}]]`];
|
|
113
|
+
item.data[m.headerKey] = value;
|
|
114
|
+
if (showSize) {
|
|
115
|
+
item.data[getEndNameKey(mDisplayName, m.sizeKey, child.displayName)] = value;
|
|
116
|
+
}
|
|
117
|
+
if (!item.dataType) {
|
|
118
|
+
item.dataType = {};
|
|
119
|
+
}
|
|
120
|
+
if (!item.format) {
|
|
121
|
+
item.format = {};
|
|
122
|
+
}
|
|
123
|
+
let sameKey = `${mDisplayName}[${child.displayName}[${mergeChildren[showSize ? 2 : 1].sizeKey}]]`;
|
|
124
|
+
if (child.expr) {
|
|
125
|
+
if (value === undefined) {
|
|
126
|
+
sameKey = `${mDisplayName}[${child.displayName}[${1}]]`;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
// const header = this.headerKeys.find(h => h.key === sameKey);
|
|
130
|
+
const header = headerKeysDic[sameKey];
|
|
131
|
+
item.dataType[m.headerKey] = header?.dataType;
|
|
132
|
+
item.format[m.headerKey] = header?.format;
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
// const arr = JSON.parse(JSON.stringify(new Array(measureListLeng - 1).fill({...newData})));
|
|
138
|
+
const arr = cloneDeepTree(new Array(measureListLeng - 1).fill({ ...newData }));
|
|
139
|
+
// item.hideTd.isHideTdStart = true;
|
|
140
|
+
arr.forEach((d, dI) => {
|
|
141
|
+
const measure = measureList[dI + 1];
|
|
142
|
+
const { isHide } = measure;
|
|
143
|
+
d.same.index = i;
|
|
144
|
+
// if (dI === arr.length - 1 && !isHide) {
|
|
145
|
+
// d.hideTd.isHideTdEnd = true;
|
|
146
|
+
// d.hideTd.isHideTd = true;
|
|
147
|
+
// } else {
|
|
148
|
+
// d.hideTd.isHideTd = true;
|
|
149
|
+
// }
|
|
150
|
+
d.isHide = isHide;
|
|
151
|
+
originalChildren.forEach((child, j) => {
|
|
152
|
+
if (dI === j - 1) {
|
|
153
|
+
d.data[`${mDisplayName}[度量]`] = child.displayName;
|
|
154
|
+
mergeChildren.forEach((m, mI) => {
|
|
155
|
+
if (showSize ? mI > 1 : mI > 0) {
|
|
156
|
+
let k = `${mDisplayName}[${child.displayName}[${m.sizeKey}]]`;
|
|
157
|
+
const value = d.data[k];
|
|
158
|
+
d.data[m.headerKey] = value;
|
|
159
|
+
if (!d.dataType) {
|
|
160
|
+
d.dataType = {};
|
|
161
|
+
}
|
|
162
|
+
if (!d.format) {
|
|
163
|
+
d.format = {};
|
|
164
|
+
}
|
|
165
|
+
let sameKey = `${mDisplayName}[${child.displayName}[${mergeChildren[1].sizeKey}]]`;
|
|
166
|
+
if (child.expr) {
|
|
167
|
+
if (value === undefined) {
|
|
168
|
+
sameKey = `${mDisplayName}[${child.displayName}[${1}]]`;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const header = getHeader(mergeChildren, mDisplayName, child, value, headerKeysDic);
|
|
172
|
+
d.dataType[m.headerKey] = header?.dataType;
|
|
173
|
+
d.format[m.headerKey] = header?.format;
|
|
174
|
+
if (child.expr && value === undefined) {
|
|
175
|
+
const exprValue = d.data[`${mDisplayName}[${child.displayName}[${mI}]]`];
|
|
176
|
+
d.data[m.headerKey] = exprValue;
|
|
177
|
+
}
|
|
178
|
+
if (showSize) {
|
|
179
|
+
d.data[getEndNameKey(mDisplayName, m.sizeKey, child.displayName)] = value;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
dimKeyList.forEach(dim => {
|
|
186
|
+
d.data[dim.key] = '';
|
|
187
|
+
if (dI === arr.length - 1) {
|
|
188
|
+
d.hideTd[dim.key] = false;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
});
|
|
192
|
+
// item.hideTd.isHideTdEnd = arr.every(a => a.isHide);
|
|
193
|
+
children.splice(i + 1, 0, ...arr);
|
|
194
|
+
i += (measureListLeng - 1);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|