diff --git a/src/utils/dynamicData.js b/src/utils/dynamicData.js new file mode 100644 index 00000000..3d57ce4c --- /dev/null +++ b/src/utils/dynamicData.js @@ -0,0 +1,4 @@ +/** + * 用于调整服务器返回的动态数据 + */ +export default function handleDynamicData() {} diff --git a/src/utils/dynamicProps.js b/src/utils/dynamicProps.js new file mode 100644 index 00000000..c1a5f275 --- /dev/null +++ b/src/utils/dynamicProps.js @@ -0,0 +1,44 @@ +/** + * 用于动态表结构的 tableProps 生成 + * @param {*} nameData + * @returns + */ +export default 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((item) => ({ + prop: item, + label: item, + align: 'center', + 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}`, + align: 'center', + }); + } + }); +} + +function notRepeat(propArray, name) { + return propArray.every((item) => item.label !== name); +} diff --git a/src/views/quality/monitoring/qualityRecentHours/index.vue b/src/views/quality/monitoring/qualityRecentHours/index.vue index d0df5e4d..435ade7a 100644 --- a/src/views/quality/monitoring/qualityRecentHours/index.vue +++ b/src/views/quality/monitoring/qualityRecentHours/index.vue @@ -10,7 +10,7 @@ -
+