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函数