From 73c2354a06686b95cec6e7ca775cfae2ca0cfe68 Mon Sep 17 00:00:00 2001 From: yangsy Date: Fri, 26 Dec 2025 14:43:00 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BD=93=E4=B8=8B=E6=B8=B8=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E8=A7=A3=E9=99=A4=E5=85=B3=E8=81=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 获取下游设备时,如果发现下游设备不存在,将静默解除关联 --- .../security-box-circuit-card.vue | 21 +++++++++++++--- .../current-diag/switch-port-card.vue | 24 +++++++++++++++---- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/components/device/device-card/components/current-diag/security-box-circuit-card.vue b/src/components/device/device-card/components/current-diag/security-box-circuit-card.vue index 480b396..9be2169 100644 --- a/src/components/device/device-card/components/current-diag/security-box-circuit-card.vue +++ b/src/components/device/device-card/components/current-diag/security-box-circuit-card.vue @@ -144,9 +144,24 @@ const getLowerDeviceByCircuitIndex = (circuitIndex: number) => { const stationDevices = lineDevices.value[stationCode]; if (!stationDevices) return null; const devices = stationDevices[deviceType]; - const device = devices.find((device) => device.id === deviceDbId); - if (!device) return null; - return device; + const lowerDevice = devices.find((device) => device.id === deviceDbId); + if (!lowerDevice) { + // 下游设备不存在时解除关联 + const modifiedUpperDevice = cloneDeep(ndmDevice.value); + const modifiedUpperLinkDescription = cloneDeep(upperDeviceLinkDescription.value); + delete modifiedUpperLinkDescription.downstream?.[circuitIndex]; + modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription); + // 不需要等待异步 + const stationCode = station.value.code; + updateDeviceApi(modifiedUpperDevice, { stationCode }).then(() => { + detailDeviceApi(modifiedUpperDevice, { stationCode }).then((upperDevice) => { + if (!upperDevice) return; + deviceStore.patchDevice(stationCode, { ...upperDevice }); + }); + }); + return null; + } + return lowerDevice; }; // 获取从父组件注入的selectDevice函数 diff --git a/src/components/device/device-card/components/current-diag/switch-port-card.vue b/src/components/device/device-card/components/current-diag/switch-port-card.vue index 7b8c0d2..8fcc105 100644 --- a/src/components/device/device-card/components/current-diag/switch-port-card.vue +++ b/src/components/device/device-card/components/current-diag/switch-port-card.vue @@ -84,19 +84,33 @@ const upperDeviceLinkDescription = computed(() => { }); const getLowerDeviceByPort = (port: NdmSwitchPortInfo) => { - const portName = port.portName; if (!upperDeviceLinkDescription.value) return null; const downstream = upperDeviceLinkDescription.value.downstream; if (!downstream) return null; - const deviceStoreIndex = downstream[portName]; + const deviceStoreIndex = downstream[port.portName]; if (!deviceStoreIndex) return null; const { stationCode, deviceType, deviceDbId } = deviceStoreIndex; const stationDevices = lineDevices.value[stationCode]; if (!stationDevices) return null; const devices = stationDevices[deviceType]; - const device = devices.find((device) => device.id === deviceDbId); - if (!device) return null; - return device; + const lowerDevice = devices.find((device) => device.id === deviceDbId); + if (!lowerDevice) { + // 下游设备不存在时解除关联 + const modifiedUpperDevice = cloneDeep(ndmDevice.value); + const modifiedUpperLinkDescription = cloneDeep(upperDeviceLinkDescription.value); + delete modifiedUpperLinkDescription.downstream?.[port.portName]; + modifiedUpperDevice.linkDescription = JSON.stringify(modifiedUpperLinkDescription); + // 不需要等待异步 + const stationCode = station.value.code; + updateDeviceApi(modifiedUpperDevice, { stationCode }).then(() => { + detailDeviceApi(modifiedUpperDevice, { stationCode }).then((upperDevice) => { + if (!upperDevice) return; + deviceStore.patchDevice(stationCode, { ...upperDevice }); + }); + }); + return null; + } + return lowerDevice; }; // 获取从父组件注入的selectDevice函数