修复实时地图页面离开页面后轮询还在执行问题
This commit is contained in:
parent
c8b456adb3
commit
b8b174ce50
@ -743,22 +743,16 @@ const linkWebSocket = (url) => {
|
||||
// 现在车辆的逻辑是这样 websoket map_push类型推送消息 每次推送新车 我就添加到车辆列表中 testCarList 不删除车辆
|
||||
// 每几秒轮询调用查看当前楼层区域的在线车辆 如果不存在 则再把testCarList 中的车辆删除
|
||||
const robotByFloorAndAreaList = ref([]) // 机器人列表
|
||||
const robotListTimer = ref(5) //轮询时间
|
||||
const robotListTimerRef = ref(null) //轮询定时器
|
||||
const getRobotByFloorAndAreaList = () => {
|
||||
if (robotListTimerRef.value) {
|
||||
clearInterval(robotListTimerRef.value)
|
||||
robotListTimerRef.value = null
|
||||
}
|
||||
robotListTimerRef.value = setInterval(() => {
|
||||
MapApi.getRobotByFloorAndArea({ floor: imgBgObj.floor, area: imgBgObj.area }).then((res) => {
|
||||
robotByFloorAndAreaList.value = res
|
||||
if (testCarList.value.length) {
|
||||
testCarList.value = filterArrayByRobotNo(testCarList.value, robotByFloorAndAreaList.value)
|
||||
}
|
||||
})
|
||||
}, robotListTimer.value * 1000)
|
||||
MapApi.getRobotByFloorAndArea({ floor: imgBgObj.floor, area: imgBgObj.area }).then((res) => {
|
||||
robotByFloorAndAreaList.value = res
|
||||
if (testCarList.value.length) {
|
||||
testCarList.value = filterArrayByRobotNo(testCarList.value, robotByFloorAndAreaList.value)
|
||||
}
|
||||
})
|
||||
}
|
||||
robotListTimerRef.value = setInterval(getRobotByFloorAndAreaList, 5000)
|
||||
|
||||
// 删掉不在线的车辆
|
||||
const filterArrayByRobotNo = (arr1, arr2) => {
|
||||
@ -1056,10 +1050,8 @@ const carDbClick = (item, index) => {
|
||||
defineExpose({ getMapData }) // 提供 open 方法,用于打开弹窗
|
||||
onMounted(() => {})
|
||||
onBeforeUnmount(() => {
|
||||
if (robotListTimerRef.value) {
|
||||
clearInterval(robotListTimerRef.value)
|
||||
robotListTimerRef.value = null
|
||||
}
|
||||
clearInterval(robotListTimerRef.value)
|
||||
robotListTimerRef.value = null
|
||||
})
|
||||
</script>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user