From 1747b773fcc37e68a1366c8fb2b5e42212f48541 Mon Sep 17 00:00:00 2001 From: yyy <2605810609@qq.com> Date: Thu, 12 Jun 2025 16:13:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E8=8E=B7=E5=8F=96=E8=BD=A6?= =?UTF-8?q?=E8=BE=86=E7=9A=84=E5=AE=9A=E6=97=B6=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../realTimeMap/components/indexPage.vue | 17 +++- src/views/mapPage/realTimeMap/editMap.vue | 85 ++++++++++++------- 2 files changed, 68 insertions(+), 34 deletions(-) diff --git a/src/views/mapPage/realTimeMap/components/indexPage.vue b/src/views/mapPage/realTimeMap/components/indexPage.vue index 7fc7a71e..aa859d61 100644 --- a/src/views/mapPage/realTimeMap/components/indexPage.vue +++ b/src/views/mapPage/realTimeMap/components/indexPage.vue @@ -878,7 +878,7 @@ onMounted(() => { robotListTimerRef.value = setInterval(() => { if (document.hidden) return // 页面不可见时暂停轮询 getRobotByFloorAndAreaList() - }, 5000) + }, 10000) // 监听页面可见性变化 document.addEventListener('visibilitychange', () => { @@ -892,6 +892,21 @@ onUnmounted(() => { document.removeEventListener('webkitfullscreenchange', handleFullscreenChange) document.removeEventListener('mozfullscreenchange', handleFullscreenChange) document.removeEventListener('MSFullscreenChange', handleFullscreenChange) + + // 清理定时器 + if (robotListTimerRef.value) { + clearInterval(robotListTimerRef.value) + robotListTimerRef.value = null + } + + if (wsConnection.value) { + wsConnection.value.disconnect() + wsConnection.value = null + } + + // 清理其他引用 + testCarList.value = [] + robotByFloorAndAreaList.value = [] }) onBeforeUnmount(() => { if (robotListTimerRef.value) { diff --git a/src/views/mapPage/realTimeMap/editMap.vue b/src/views/mapPage/realTimeMap/editMap.vue index 837f2026..32ef5893 100644 --- a/src/views/mapPage/realTimeMap/editMap.vue +++ b/src/views/mapPage/realTimeMap/editMap.vue @@ -2714,14 +2714,24 @@ const submitBatchCopyingFormSuccess = async (form) => { const validNodes = newPoints.filter((node) => isValidNodeType(node.type)) const validRoutes = newRoutes.filter((route) => isValidRoute(route)) + // 计算新坐标的辅助函数 + const calculateNewCoordinates = (x, y) => { + const newX = (Number(x) + Number(form.x)).toString() + const newY = (Number(y) + Number(form.y)).toString() + const actualPoint = disposeEventPoint(newX, newY) + return { newX, newY, actualPoint } + } + const newPointList = await Promise.all( validNodes.map(async (node) => { const newId = await MapApi.getNodeId() nodeIdMap.set(node.id, newId) - const locationX = Number(node.locationX) + Number(form.x) - const locationY = Number(node.locationY) + Number(form.y) - const actualPoint = disposeEventPoint(locationX, locationY) + const { + newX: locationX, + newY: locationY, + actualPoint + } = calculateNewCoordinates(node.locationX, node.locationY) const { sortNum, createTime, ...restNode } = node @@ -2733,14 +2743,14 @@ const submitBatchCopyingFormSuccess = async (form) => { dataList = [] dataJson = '' } else if (restNode.type === 2) { - dataList = restNode.dataList.map((item) => { - return { - locationDeep: item.locationDeep, - locationStorey: item.locationStorey, - locationWide: item.locationWide, - positionMapId: item.positionMapId - } - }) + dataList = restNode.dataList.map( + ({ locationDeep, locationStorey, locationWide, positionMapId }) => ({ + locationDeep, + locationStorey, + locationWide, + positionMapId + }) + ) dataJson = JSON.stringify(dataList) } else if (restNode.type === 4) { dataObj = { @@ -2771,21 +2781,27 @@ const submitBatchCopyingFormSuccess = async (form) => { // 更新起点 if (nodeIdMap.has(route.startingPointId)) { + const { newX, newY, actualPoint } = calculateNewCoordinates( + route.startPointX, + route.startPointY + ) newRoute.startingPointId = nodeIdMap.get(route.startingPointId) - newRoute.startPointX = (Number(route.startPointX) + Number(form.x)).toString() - newRoute.startPointY = (Number(route.startPointY) + Number(form.y)).toString() - - const actualStartPoint = disposeEventPoint(newRoute.startPointX, newRoute.startPointY) - newRoute.actualStartPointX = actualStartPoint.actualLocationX - newRoute.actualStartPointY = actualStartPoint.actualLocationY + newRoute.startPointX = newX + newRoute.startPointY = newY + newRoute.actualStartPointX = actualPoint.actualLocationX + newRoute.actualStartPointY = actualPoint.actualLocationY // 更新控制点 if (route.method == 1) { - newRoute.beginControlX = (Number(route.beginControlX) + Number(form.x)).toString() - newRoute.beginControlY = (Number(route.beginControlY) + Number(form.y)).toString() - const actualBeginControl = disposeEventPoint(newRoute.beginControlX, newRoute.beginControlY) - newRoute.actualBeginControlX = actualBeginControl.actualLocationX - newRoute.actualBeginControlY = actualBeginControl.actualLocationY + const { + newX: controlX, + newY: controlY, + actualPoint: controlPoint + } = calculateNewCoordinates(route.beginControlX, route.beginControlY) + newRoute.beginControlX = controlX + newRoute.beginControlY = controlY + newRoute.actualBeginControlX = controlPoint.actualLocationX + newRoute.actualBeginControlY = controlPoint.actualLocationY } else { newRoute.beginControlX = 0 newRoute.beginControlY = 0 @@ -2796,21 +2812,24 @@ const submitBatchCopyingFormSuccess = async (form) => { // 更新终点 if (nodeIdMap.has(route.endPointId)) { + const { newX, newY, actualPoint } = calculateNewCoordinates(route.endPointX, route.endPointY) newRoute.endPointId = nodeIdMap.get(route.endPointId) - newRoute.endPointX = (Number(route.endPointX) + Number(form.x)).toString() - newRoute.endPointY = (Number(route.endPointY) + Number(form.y)).toString() - - const actualEndPoint = disposeEventPoint(newRoute.endPointX, newRoute.endPointY) - newRoute.actualEndPointX = actualEndPoint.actualLocationX - newRoute.actualEndPointY = actualEndPoint.actualLocationY + newRoute.endPointX = newX + newRoute.endPointY = newY + newRoute.actualEndPointX = actualPoint.actualLocationX + newRoute.actualEndPointY = actualPoint.actualLocationY // 更新控制点 if (route.method == 1) { - newRoute.endControlX = (Number(route.endControlX) + Number(form.x)).toString() - newRoute.endControlY = (Number(route.endControlY) + Number(form.y)).toString() - const actualEndControl = disposeEventPoint(newRoute.endControlX, newRoute.endControlY) - newRoute.actualEndControlX = actualEndControl.actualLocationX - newRoute.actualEndControlY = actualEndControl.actualLocationY + const { + newX: controlX, + newY: controlY, + actualPoint: controlPoint + } = calculateNewCoordinates(route.endControlX, route.endControlY) + newRoute.endControlX = controlX + newRoute.endControlY = controlY + newRoute.actualEndControlX = controlPoint.actualLocationX + newRoute.actualEndControlY = controlPoint.actualLocationY } else { newRoute.endControlX = 0 newRoute.endControlY = 0