feat: 设备关联与解除关联
- 支持配置交换机端口的下游关联设备 - 支持配置安防箱电路的下游关联设备 - 支持解除关联 - 删除设备时校验是否存在上/下游设备
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { deleteDeviceApi, exportDeviceApi, importDeviceApi, type ImportMsg, type NdmDevicePageQuery, type PageParams, type Station } from '@/apis';
|
||||
import { deleteDeviceApi, exportDeviceApi, importDeviceApi, type ImportMsg, type NdmDeviceLinkDescription, type NdmDevicePageQuery, type PageParams, type Station } from '@/apis';
|
||||
import { useStationDevicesMutation } from '@/composables';
|
||||
import { DEVICE_TYPE_NAMES, type DeviceType } from '@/enums';
|
||||
import { useDeviceStore, useStationStore } from '@/stores';
|
||||
@@ -6,6 +6,7 @@ import { downloadByData, parseErrorFeedback } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import { isCancel } from 'axios';
|
||||
import dayjs from 'dayjs';
|
||||
import destr from 'destr';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { h, onBeforeUnmount } from 'vue';
|
||||
|
||||
@@ -152,6 +153,32 @@ export const useDeviceManagement = () => {
|
||||
|
||||
window.$loadingBar.start();
|
||||
|
||||
// 检查要删除的设备是否存在关联设备
|
||||
const stationDevices = lineDevices.value[stationCode];
|
||||
if (!!stationDevices) {
|
||||
const classified = stationDevices[deviceType];
|
||||
if (!!classified) {
|
||||
const device = classified.find((device) => device.id === id);
|
||||
if (!!device) {
|
||||
const maybeLinkDescription = destr<any>(device.linkDescription);
|
||||
if (!!maybeLinkDescription && typeof maybeLinkDescription === 'object') {
|
||||
const linkDescription = maybeLinkDescription as NdmDeviceLinkDescription;
|
||||
// 只要有上游或下游设备,就不能删除
|
||||
const { upstream } = linkDescription;
|
||||
if (!!upstream && upstream.length > 0) {
|
||||
throw new Error('该设备存在关联的上游设备,无法删除');
|
||||
}
|
||||
if ('downstream' in linkDescription) {
|
||||
const { downstream } = linkDescription;
|
||||
if (!!downstream && Object.keys(downstream).length > 0) {
|
||||
throw new Error('该设备存在关联的下游设备,无法删除');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return await deleteDeviceApi(deviceType, id, { stationCode, signal });
|
||||
},
|
||||
onSuccess: (_, { stationCode, signal }) => {
|
||||
|
||||
Reference in New Issue
Block a user