|
|
@@ -47,7 +47,12 @@
|
|
|
import { storeToRefs } from 'pinia';
|
|
|
import { VideoCamera, WarningFilled, Search } from '@element-plus/icons-vue';
|
|
|
import { useCameraGroupList } from '@/store/modules/useCameraGroupList';
|
|
|
- import { queryDeviceListApi, updateSensorInGroupApi } from '@/api/sensor-group';
|
|
|
+ import {
|
|
|
+ batchSaveSensor2GroupApi,
|
|
|
+ deleteSensorFromGroupApi,
|
|
|
+ queryDeviceListApi,
|
|
|
+ saveSensor2GroupApi,
|
|
|
+ } from '@/api/sensor-group';
|
|
|
import type { DeviceListItem, SensorGroupView, SensorDeviceViewItem } from '@/api/sensor-group/type';
|
|
|
import Thumbnail from '@/components/thumbnail/Thumbnail.vue';
|
|
|
|
|
|
@@ -110,9 +115,29 @@
|
|
|
saving.value = true;
|
|
|
try {
|
|
|
const checkedNodes = (treeRef.value?.getCheckedNodes() as any[]) || [];
|
|
|
- const deviceNoList = checkedNodes.map((n) => n.code as string);
|
|
|
+ const checkedDeviceNoList = checkedNodes.map((n) => n.code as string);
|
|
|
+ const initialDeviceNoList = initialCheckedKeys.value;
|
|
|
+ const addedDeviceNoList = checkedDeviceNoList.filter((deviceNo) => !initialDeviceNoList.includes(deviceNo));
|
|
|
+ const removedDeviceNoList = initialDeviceNoList.filter((deviceNo) => !checkedDeviceNoList.includes(deviceNo));
|
|
|
|
|
|
- await updateSensorInGroupApi({ groupId: props.cameraGroup.id, deviceNoList });
|
|
|
+ if (removedDeviceNoList.length > 0) {
|
|
|
+ await Promise.all(
|
|
|
+ removedDeviceNoList.map((deviceNo) => deleteSensorFromGroupApi({ groupId: props.cameraGroup.id, deviceNo })),
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ if (addedDeviceNoList.length === 1) {
|
|
|
+ await saveSensor2GroupApi({
|
|
|
+ groupId: props.cameraGroup.id,
|
|
|
+ deviceNo: addedDeviceNoList[0],
|
|
|
+ orderNum: props.cameraGroup.details.length + 1,
|
|
|
+ });
|
|
|
+ } else if (addedDeviceNoList.length > 1) {
|
|
|
+ await batchSaveSensor2GroupApi({
|
|
|
+ groupId: props.cameraGroup.id,
|
|
|
+ deviceNoList: addedDeviceNoList,
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
// 更新本地状态
|
|
|
const newSensors: SensorDeviceViewItem[] = checkedNodes.map((n) => ({
|