From 0f3d70b7f8c17f47b65710f2a97b80b11b7dfc8f Mon Sep 17 00:00:00 2001 From: lhzzforever Date: Thu, 9 May 2024 15:32:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=85=A8=E5=B9=B3?= =?UTF-8?q?=E5=8F=B0ip=E9=80=89=E6=8B=A9=E5=99=A8=E4=B8=8D=E5=90=8C?= =?UTF-8?q?=E6=8B=93=E6=89=91=E4=B8=8B=E7=9B=B8=E5=90=8C=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E7=9A=84=E5=AD=90=E9=9B=86=E6=95=B0=E6=8D=AE=E4=BC=9A=E8=A2=AB?= =?UTF-8?q?=E5=8E=BB=E9=87=8D=E9=81=97=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/components/choose-ip/grade.vue | 34 ++++++++++++------ .../src/components/choose-ip/grade/index.vue | 35 +++++++++++++------ frontend/src/components/choose-ip/index.vue | 8 ++--- 3 files changed, 51 insertions(+), 26 deletions(-) diff --git a/frontend/src/components/choose-ip/grade.vue b/frontend/src/components/choose-ip/grade.vue index 3a5801482..472f77167 100644 --- a/frontend/src/components/choose-ip/grade.vue +++ b/frontend/src/components/choose-ip/grade.vue @@ -348,9 +348,15 @@ const hasNode = {}; const treeData = [...this.treeData]; const list = treeData.reduce((curr, next) => { - // eslint-disable-next-line no-unused-expressions - hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); - // hasNode[next.name] ? '' : hasNode[next.name] = true && curr.push(next); + if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { + const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.id}&${next.name}&${chainContent}`] ? '' + : hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next); + } else { + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); + } return curr; }, []); return list; @@ -422,7 +428,8 @@ handleOnExpanded (index, expanded) { window.changeAlert = true; - if (!expanded && this.treeData[index + 2].type === 'search-empty') { + const searchEmptyData = this.treeData[index + 2]; + if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') { this.treeData.splice(index + 2, 1); } }, @@ -1167,12 +1174,19 @@ removeAsyncNode () { // 需要过滤掉name为空以及反复切换选中造成的重复数据的节点 - const obj = {}; - const treeList = _.cloneDeep(this.treeData.filter(item => item.name)); - this.treeData = treeList.reduce((pre, item) => { - // eslint-disable-next-line no-unused-expressions - obj[`${item.id}${item.name}`] ? '' : obj[`${item.id}${item.name}`] = true && pre.push(item); - return pre; + const hasNode = {}; + const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== '')); + this.treeData = treeList.reduce((curr, next) => { + if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { + const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.id}&${next.name}&${chainContent}`] ? '' + : hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next); + } else { + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); + } + return curr; }, []); const index = this.treeData.findIndex(item => item.type === 'async'); if (index > -1) this.treeData.splice(index, 1); diff --git a/frontend/src/components/choose-ip/grade/index.vue b/frontend/src/components/choose-ip/grade/index.vue index 6afb5e8a6..e07df8d59 100644 --- a/frontend/src/components/choose-ip/grade/index.vue +++ b/frontend/src/components/choose-ip/grade/index.vue @@ -386,8 +386,15 @@ const hasNode = {}; const treeData = [...this.treeData]; const list = treeData.reduce((curr, next) => { - // eslint-disable-next-line no-unused-expressions - hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); + if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { + const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.id}&${next.name}&${chainContent}`] ? '' + : hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next); + } else { + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); + } return curr; }, []); return list; @@ -603,7 +610,8 @@ handleOnExpanded (index, expanded) { window.changeAlert = true; - if (!expanded && this.treeData[index + 2].type === 'search-empty') { + const searchEmptyData = this.treeData[index + 2]; + if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') { this.treeData.splice(index + 2, 1); } }, @@ -1681,14 +1689,21 @@ removeAsyncNode () { // 需要过滤掉name为空以及反复切换选中造成的重复数据的节点 - const obj = {}; - const treeList = _.cloneDeep(this.treeData.filter(item => item.name)); - this.treeData = treeList.reduce((pre, item) => { - // eslint-disable-next-line no-unused-expressions - obj[`${item.id}${item.name}`] ? '' : obj[`${item.id}${item.name}`] = true && pre.push(item); - return pre; + const hasNode = {}; + const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== '')); + this.treeData = treeList.reduce((curr, next) => { + if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { + const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.id}&${next.name}&${chainContent}`] ? '' + : hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next); + } else { + // eslint-disable-next-line no-unused-expressions + hasNode[`${next.name}&${next.id}`] ? '' : hasNode[`${next.name}&${next.id}`] = true && curr.push(next); + } + return curr; }, []); - const index = this.treeData.findIndex((item) => item.type === 'async'); + const index = this.treeData.findIndex(item => item.type === 'async'); if (index > -1) this.treeData.splice(index, 1); }, diff --git a/frontend/src/components/choose-ip/index.vue b/frontend/src/components/choose-ip/index.vue index 66e15abe3..49db68e88 100644 --- a/frontend/src/components/choose-ip/index.vue +++ b/frontend/src/components/choose-ip/index.vue @@ -369,7 +369,6 @@ renderTopologyData () { const hasNode = {}; const treeData = [...this.treeData]; - console.log(treeData, '去重前的数据'); const list = treeData.reduce((curr, next) => { if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); @@ -382,7 +381,6 @@ } return curr; }, []); - console.log(list, '去重后的数据'); return list; }, getSystemParams () { @@ -462,7 +460,8 @@ handleOnExpanded (index, expanded) { window.changeAlert = true; - if (!expanded && this.treeData[index + 2] && this.treeData[index + 2].type === 'search-empty') { + const searchEmptyData = this.treeData[index + 2]; + if (!expanded && searchEmptyData && searchEmptyData.type === 'search-empty') { this.treeData.splice(index + 2, 1); } }, @@ -1299,11 +1298,9 @@ // 需要过滤掉name为空以及反复切换选中造成的重复数据的节点 const hasNode = {}; const treeList = _.cloneDeep(this.treeData.filter(item => item.name !== '')); - console.log(treeList, 'remove前'); this.treeData = treeList.reduce((curr, next) => { if (next.level > 0 && next.parentChain && next.parentChain.length > 0) { const chainContent = next.parentChain.map((v) => `${v.id}&${v.name}&${v.type}`).join(); - console.log(chainContent, '父级数据'); // eslint-disable-next-line no-unused-expressions hasNode[`${next.id}&${next.name}&${chainContent}`] ? '' : hasNode[`${next.id}&${next.name}&${chainContent}`] = true && curr.push(next); @@ -1313,7 +1310,6 @@ } return curr; }, []); - console.log(this.treeData, 'remove前后'); const index = this.treeData.findIndex(item => item.type === 'async'); if (index > -1) this.treeData.splice(index, 1); },