|
|
@@ -1,5 +1,12 @@
|
|
|
-import { FENCE_ENBALED_STATUS, updateCameraAlgoApi } from '@/api/camera/camera-preview';
|
|
|
+import {
|
|
|
+ createCameraFence,
|
|
|
+ FENCE_ENBALED_STATUS,
|
|
|
+ updateBatchCameraFenceApi,
|
|
|
+ updateCameraAlgoApi,
|
|
|
+} from '@/api/camera/camera-preview';
|
|
|
import { ElMessage } from 'element-plus';
|
|
|
+import { ServerLineInfo, ServerLineInfos } from '../components/FenceEditor/constants';
|
|
|
+import { FencePolygonPoints } from '../components/FenceEditorV2/types';
|
|
|
import useCameraAlgoStore from '../store/useCameraAlgoStore';
|
|
|
import useCameraDetailStore from '../store/useCameraDetailStore';
|
|
|
import useFenceStore from '../store/useFenceStore';
|
|
|
@@ -37,7 +44,75 @@ export const useParamsSettingFn = () => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
- return { toggleFenceStatus };
|
|
|
+ /** 新建电子围栏 */
|
|
|
+ // const createFence = (param: SaveFenceParams) => {
|
|
|
+ // // 还需要把名字加上。
|
|
|
+ // // return saveFenceApi({ fenceName: '电子围栏', ...param }).then((res) => {
|
|
|
+ // // console.log('save success', res);
|
|
|
+ // // currentFenceId.value = res;
|
|
|
+ // // getFence(param);
|
|
|
+ // // });
|
|
|
+
|
|
|
+ // const lastItemId = allFences.value[allFences.value.length - 1]?.id || 1;
|
|
|
+
|
|
|
+ // allFences.value = [...allFences.value, { name: '电子围栏', ...param, id: lastItemId + 1 }];
|
|
|
+ // createCameraFence({ ...param, electronicFencePolygon: JSON.stringify(allFences.value) });
|
|
|
+ // };
|
|
|
+
|
|
|
+ const updateBatchCameraFence = () => {
|
|
|
+ const cameraId = cameraDetailStore.cameraId;
|
|
|
+ const algoId = cameraAlgoStore.selectedAlgoId;
|
|
|
+ const presetToken = presetStore.currentPresetToken;
|
|
|
+ if (!cameraId) {
|
|
|
+ ElMessage.error('未选中相机');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!algoId) {
|
|
|
+ ElMessage.error('未选中算法');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!presetToken) {
|
|
|
+ ElMessage.error('未选中预置位');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ updateBatchCameraFenceApi({
|
|
|
+ id: fenceStore.currentFenceGroupId!,
|
|
|
+ cameraId,
|
|
|
+ algoId,
|
|
|
+ presetToken,
|
|
|
+ electronicFencePolygon: JSON.stringify(fenceStore.allFences),
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 在前端本地创建单个电子围栏
|
|
|
+ const createFence = (fencePolygon: FencePolygonPoints) => {
|
|
|
+ const allFences = fenceStore.allFences;
|
|
|
+ const lastItemId = allFences[allFences.length - 1]?.id || 1;
|
|
|
+ fenceStore.allFences = [...allFences, { polygon: fencePolygon, name: '电子围栏', id: lastItemId + 1 }];
|
|
|
+ // updateBatchCameraFence();
|
|
|
+ };
|
|
|
+
|
|
|
+ /** 在前端本地修改电子围栏信息 */
|
|
|
+ const editFence = (fencePolygon: ServerLineInfo) => {
|
|
|
+ const allFences = fenceStore.allFences;
|
|
|
+
|
|
|
+ fenceStore.allFences = allFences.map((x) => {
|
|
|
+ if (x.id === fencePolygon.id) {
|
|
|
+ return { ...x, ...fencePolygon };
|
|
|
+ }
|
|
|
+ return x;
|
|
|
+ });
|
|
|
+ updateBatchCameraFence();
|
|
|
+ };
|
|
|
+
|
|
|
+ const deleteFence = (fenceId: number) => {
|
|
|
+ const allFences = fenceStore.allFences;
|
|
|
+ fenceStore.allFences = allFences.filter((x) => x.id !== fenceId);
|
|
|
+ updateBatchCameraFence();
|
|
|
+ };
|
|
|
+
|
|
|
+ return { toggleFenceStatus, editFence, createFence, deleteFence };
|
|
|
};
|
|
|
|
|
|
export default useParamsSettingFn;
|