Commit 009f2adb authored by Administrator's avatar Administrator

地图定时刷新

parent effb6f6f
...@@ -184,6 +184,7 @@ export default { ...@@ -184,6 +184,7 @@ export default {
data(){ data(){
const _this = this; const _this = this;
return { return {
intervalId: null,
map: {}, map: {},
amapManager: new AMapManager(), amapManager: new AMapManager(),
zoom: 6, zoom: 6,
...@@ -247,10 +248,17 @@ export default { ...@@ -247,10 +248,17 @@ export default {
.then(res => { .then(res => {
this.markersDevice = res.data; this.markersDevice = res.data;
}); });
this.dataRefresh();
},
destroyed(){
// 在页面销毁后,清除计时器
this.clearIntv();
}, },
methods: { methods: {
checkPermission, checkPermission,
allDevices() { allDevices() {
this.clearIntv();
this.dataRefresh();
devices() devices()
.then(res => { .then(res => {
this.leftDeviceName = '全部设备'; this.leftDeviceName = '全部设备';
...@@ -290,10 +298,13 @@ export default { ...@@ -290,10 +298,13 @@ export default {
}, },
// 获取单个用户下的设备 // 获取单个用户下的设备
getUserDeviceList(uid) { getUserDeviceList(uid) {
// 停止定时器
this.clearIntv();
devices({ uid: uid }) devices({ uid: uid })
.then(res => { .then(res => {
this.markersDevice = res.data; this.markersDevice = res.data;
}); });
this.dataRefresh(uid);
}, },
// 获取设备详细信息 // 获取设备详细信息
getUserDeviceInfo(id) { getUserDeviceInfo(id) {
...@@ -367,6 +378,41 @@ export default { ...@@ -367,6 +378,41 @@ export default {
openDeviceBox(row, column, event) { openDeviceBox(row, column, event) {
this.getUserDeviceInfo(row.id); this.getUserDeviceInfo(row.id);
}, },
// 定时刷新数据
dataRefresh(uid = null) {
// 计时器正在进行中,退出函数
if (this.intervalId != null) {
return;
}
// 计时器为空,操作
this.intervalId = setInterval(() => {
console.log('刷新' + uid + '--' + new Date());
if (uid > 0) {
users({ uid: uid })
.then(res => {
this.markers = res.data;
});
devices({ uid: uid })
.then(res => {
this.markersDevice = res.data;
});
} else {
users()
.then(res => {
this.markers = res.data;
});
devices({})
.then(res => {
this.markersDevice = res.data;
});
}
}, 3000);
},
// 停止定时器
clearIntv() {
clearInterval(this.intervalId); // 清除计时器
this.intervalId = null; // 设置为null
},
}, },
}; };
</script> </script>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment