64 lines
1.4 KiB
JavaScript
64 lines
1.4 KiB
JavaScript
import moment from 'moment';
|
|
|
|
/**
|
|
* 用于动态表结构的 tableProps 生成
|
|
* @param {*} nameData
|
|
* @returns
|
|
*/
|
|
export function handleNameData(nameData) {
|
|
const props = step1(nameData.filter((item) => item.tree == 1));
|
|
step2(
|
|
props,
|
|
nameData.filter((item) => item.tree == 2)
|
|
);
|
|
// console.log('level 1', JSON.stringify(props, null, 2));
|
|
return props;
|
|
}
|
|
|
|
function step1(tree1) {
|
|
return Array.from(new Set(tree1.map((item) => item.name)))
|
|
.sort()
|
|
.map((time) => ({
|
|
prop: time,
|
|
label: moment(time).format('YYYY-MM-DD HH:mm:ss'),
|
|
children: [],
|
|
}));
|
|
}
|
|
|
|
function step2(firstTierProps, tree2) {
|
|
tree2.map((nd) => {
|
|
const parent = firstTierProps.find(
|
|
({ prop }) => nd.parentId.indexOf(prop) > -1
|
|
);
|
|
if (notRepeat(parent.children, nd.name)) {
|
|
parent.children.push({
|
|
label: nd.name,
|
|
prop: `${parent.prop}-${nd.name}`,
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
function notRepeat(propArray, name) {
|
|
return propArray.every((item) => item.label !== name);
|
|
}
|
|
|
|
/**
|
|
* 用于调整服务器返回的动态数据
|
|
* @param {*} dynamicData
|
|
* @returns
|
|
*/
|
|
export function handleDynamicData(dynamicData) {
|
|
return dynamicData.map((dd) => {
|
|
const initData = {
|
|
inspectionContent: dd.inspectionDetContent,
|
|
};
|
|
dd.data.forEach((column) => {
|
|
column.children.forEach((ch) => {
|
|
initData[`${column.dynamicName}-${ch.dynamicName}`] = ch.dynamicValue;
|
|
});
|
|
});
|
|
return initData;
|
|
});
|
|
}
|