From 4a4123b2e7e71d6faee7cd70ead66ebb785fc09f Mon Sep 17 00:00:00 2001 From: leiqiaochu Date: Wed, 15 Mar 2023 14:36:14 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20=E5=AD=90=E8=AE=BE=E5=A4=87=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=92=8C=E6=96=B0=E5=A2=9E=E7=BB=91=E5=AE=9A=E8=87=AA?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ChildDevice/BindChildDevice/index.vue | 8 +- .../Detail/ChildDevice/EdgeMap/MSelect.vue | 8 +- .../ChildDevice/EdgeMap/PatchMapping.vue | 35 ++--- .../Detail/ChildDevice/EdgeMap/index.vue | 123 +++++++---------- .../Detail/ChildDevice/SaveChild/index.vue | 126 ++++++++++-------- .../Instance/Detail/ChildDevice/index.vue | 8 +- 6 files changed, 152 insertions(+), 156 deletions(-) diff --git a/src/views/device/Instance/Detail/ChildDevice/BindChildDevice/index.vue b/src/views/device/Instance/Detail/ChildDevice/BindChildDevice/index.vue index 72f82b22..59aca823 100644 --- a/src/views/device/Instance/Detail/ChildDevice/BindChildDevice/index.vue +++ b/src/views/device/Instance/Detail/ChildDevice/BindChildDevice/index.vue @@ -1,6 +1,6 @@ \ No newline at end of file diff --git a/src/views/device/Instance/Detail/ChildDevice/SaveChild/index.vue b/src/views/device/Instance/Detail/ChildDevice/SaveChild/index.vue index 8bebc5f3..6138d3f9 100644 --- a/src/views/device/Instance/Detail/ChildDevice/SaveChild/index.vue +++ b/src/views/device/Instance/Detail/ChildDevice/SaveChild/index.vue @@ -2,7 +2,7 @@
@@ -39,7 +39,10 @@ @@ -64,67 +67,80 @@ const formRef = ref(); const emit = defineEmits(['closeChildSave']); const productList = ref(); const visible = ref(false); +/** + * 获取产品列表 + */ const getProductList = async () => { const res = await getProductListNoPage({ terms: [{ column: 'accessProvider', value: 'edge-child-device' }], }); if (res.status === 200) { productList.value = res.result; - if (props.childData?.id) { - current.value.parentId = props.childData.id; - form.name = props.childData?.name; - form.productId = props.childData?.productId; - selectChange(form.productId); - if (current.value.metadata) { - const metadata = current.value.metadata; - if (metadata && metadata.length !== 0) { - getEdgeMap(current.value.id, { - deviceId: props.childData.id, - query: {}, - }).then((res) => { - if (res.status === 200) { - // console.log(res.result) - //合并物模型 - const array = res.result[0]?.reduce( - (x: any, y: any) => { - const metadataId = metadata.find( - (item: any) => - item.metadataId === y.metadataId, - ); - if (metadataId) { - Object.assign(metadataId, y); - } else { - x.push(y); - } - return x; - }, - metadata, - ); - //删除物模型 - const items = array.filter( - (item: any) => item.metadataName, - ); - current.value.metadata = items; - const delList = array - .filter((a: any) => !a.metadataName) - .map((b: any) => b.id); - //删除后解绑 - if (delList && delList.length !== 0) { - removeEdgeMap(current.value.id, { - deviceId: props.childData.id, - idList: [...delList], - }); - } - } - }); - } - } - visible.value = true; - } else { - current.value.parentId = ''; - } + getEdgeMapData(); } }; +/** + * 获取映射数据 + */ +const getEdgeMapData = () => { + if (props.childData?.id) { + current.value.parentId = props.childData.id; + form.name = props.childData?.name; + form.productId = props.childData?.productId; + selectChange(form.productId); + if (current.value.metadata) { + const metadata = current.value.metadata; + if (metadata && metadata.length !== 0) { + getEdgeMap(current.value.id, { + deviceId: props.childData.id, + query: {}, + }).then((res) => { + if (res.status === 200) { + // console.log(res.result) + //合并物模型 + const array = res.result[0]?.reduce( + (x: any, y: any) => { + const metadataId = metadata.find( + (item: any) => + item.metadataId === y.metadataId, + ); + if (metadataId) { + Object.assign(metadataId, y); + } else { + x.push(y); + } + return x; + }, + metadata, + ); + //删除物模型 + const items = array.filter( + (item: any) => item.metadataName, + ); + current.value.metadata = items; + const delList = array + .filter((a: any) => !a.metadataName) + .map((b: any) => b.id); + //删除后解绑 + if (delList && delList.length !== 0) { + removeEdgeMap(current.value.id, { + deviceId: props.childData.id, + idList: [...delList], + }); + } + } + }); + } + } + visible.value = true; + } else { + current.value.parentId = ''; + } +}; +/** + * 根据产品id获取对应映射列表 + * @param e 产品id + */ const selectChange = (e: any) => { if (e) { visible.value = true; diff --git a/src/views/device/Instance/Detail/ChildDevice/index.vue b/src/views/device/Instance/Detail/ChildDevice/index.vue index e3e298f2..d723385f 100644 --- a/src/views/device/Instance/Detail/ChildDevice/index.vue +++ b/src/views/device/Instance/Detail/ChildDevice/index.vue @@ -1,12 +1,12 @@