From 54ce9639ab5ed9bc356471f9cff0074cbfeaadb2 Mon Sep 17 00:00:00 2001 From: lb Date: Fri, 18 Aug 2023 14:06:44 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=8A=A8=E6=80=81=E8=A1=A8=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E5=A4=84=E7=90=86=E7=9B=B8=E5=85=B3=E5=B7=A5=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/dynamicData.js | 4 + src/utils/dynamicProps.js | 44 +++++ .../monitoring/qualityRecentHours/index.vue | 150 ++++-------------- .../monitoring/qualityRecentHours/props.json | 80 ++++++++++ 4 files changed, 162 insertions(+), 116 deletions(-) create mode 100644 src/utils/dynamicData.js create mode 100644 src/utils/dynamicProps.js create mode 100644 src/views/quality/monitoring/qualityRecentHours/props.json 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 @@ -
+