Commit 648e0332 authored by caicaicai's avatar caicaicai

修改

parent 176ac645
......@@ -135,6 +135,7 @@ import * as echarts from 'echarts';
export default {
data() {
return {
heartbeatTimer:null,
websocket: null,
whetherShow:false,
selectCarFleet:'', //搜索对应车队
......@@ -149,10 +150,7 @@ export default {
dispatchBtnTitle1:'人工调度',
}
},
created(){
//页面刚进入时开启长连接
this.initWebSocket();
},
created(){ },
mounted() { },
methods: {
//获取总数据
......@@ -204,6 +202,13 @@ export default {
//车辆区域分布Echarts
this.carsAreaDistributionEcharts();
})
//页面刚进入时开启长连接
this.initWebSocket();
this.heartbeatTimer = setInterval(() => {
this.reconnect();
}, 10000)
}else{
this.whetherShow = false;
}
......@@ -399,12 +404,13 @@ export default {
//初始化weosocket
initWebSocket(){
//const wsuri = "ws://114.116.108.246:81/websocket/socketServer?userId="+userId;//连接地址,可加参数
const wsuri = process.env.VUE_APP_WS_API + "/" + 7;
const wsuri = process.env.VUE_APP_WS_API + "/" + 'pcBigScreen';
this.websocket = new WebSocket(wsuri);
this.websocket.onopen = this.websocketonopen;
this.websocket.onerror = this.websocketonerror;
this.websocket.onmessage = this.websocketonmessage;
this.websocket.onclose = this.websocketclose;
this.websocketonmessage();
},
//WebSocket连接成功
websocketonopen() {
......@@ -429,11 +435,29 @@ export default {
websocketclose(e){
console.log("connection closed (" + e.code + ")");
},
//WebSocket重连
reconnect(){
var This=this;
if (this.websocket.readyState === 1) { // that.websock.readyState = 1 表示连接成功,可以立即发送信息
This.websocketonmessage();
} else if (this.websocket.readyState === 0) { // 表示正在连接,设置300ms后发送信息
setTimeout(function () {
This.websocketonmessage();
}, 300);
} else { // 连接未创建或者创建失败,则重新创建连接,并设置500ms后发送信息
This.initWebSocket();
setTimeout(function () {
This.websocketonmessage();
}, 500);
}
},
},
destroyed: function() {
//页面销毁时关闭长连接
this.websocketclose();
//关闭心跳
this.heartbeatTimer = null;
},
}
</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