|
@@ -15,10 +15,10 @@
|
|
|
</view>
|
|
|
<view class="main">
|
|
|
<view class="main_one" v-if="isSlecte">
|
|
|
- <automatic :robotInfoVo = "robotInfoVo" :robotcode = 'robotcode' ></automatic>
|
|
|
+ <automatic :robotInfoVo="robotInfoVo" :robotcode='robotcode'></automatic>
|
|
|
</view>
|
|
|
<view class="main_two" v-if="!isSlecte">
|
|
|
- <manual :storeInfoLists = "storeInfoLists"></manual>
|
|
|
+ <manual :storeInfoLists="storeInfoLists"></manual>
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
@@ -34,26 +34,46 @@
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- isSlecte: true,//切换页面
|
|
|
- getStationCode: null,//这个暂时没有
|
|
|
- ws: null,//websuokit 链接器
|
|
|
- timer: null,//记录链接的方法 方便清除
|
|
|
- storeInfoLists:[],//储充设备数据
|
|
|
- robotInfoVo:{},//机器人数据
|
|
|
- robotcode:0,//机器人模式
|
|
|
+ isSlecte: true, //切换页面
|
|
|
+ getStationCode: null, //这个暂时没有
|
|
|
+ ws: null, //websuokit 链接器
|
|
|
+ timer: null, //记录链接的方法 方便清除
|
|
|
+ storeInfoLists: [], //储充设备数据
|
|
|
+ robotInfoVo: {}, //机器人数据
|
|
|
+ robotcode: 0, //机器人模式
|
|
|
+ heartbeatTimer: null,
|
|
|
+ onMessageTime: null,
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
-
|
|
|
+ this.onMessageTime = new Date();
|
|
|
this.InitWs()
|
|
|
+ this.heartbeatTimer = setInterval(() => {
|
|
|
+ let newDate = new Date();
|
|
|
+ if (newDate - this.onMessageTime > 3000) {
|
|
|
+ if (this.ws != null) {
|
|
|
+ this.ws.close()
|
|
|
+ this.ws = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }, 3000)
|
|
|
|
|
|
},
|
|
|
|
|
|
onUnload() {
|
|
|
console.log('onUnload')
|
|
|
- clearInterval(this.timer)
|
|
|
- this.timer = null
|
|
|
- this.ws.close()
|
|
|
+ if(this.timer!=null){
|
|
|
+ clearInterval(this.timer)
|
|
|
+ this.timer = null
|
|
|
+ }
|
|
|
+ if(this.ws!=null){
|
|
|
+ this.ws.close()
|
|
|
+ this.ws=null
|
|
|
+ }
|
|
|
+ if(this.heartbeatTimer!=null){
|
|
|
+ this.heartbeatTimer.close()
|
|
|
+ this.heartbeatTimer=null
|
|
|
+ }
|
|
|
},
|
|
|
computed: {
|
|
|
pageState() {
|
|
@@ -78,7 +98,7 @@
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
-
|
|
|
+
|
|
|
//判断websocket是否链接上
|
|
|
InitWs() {
|
|
|
let token = this.$storage.getJson("token");
|
|
@@ -107,14 +127,17 @@
|
|
|
// uni.showLoading({
|
|
|
// title: '数据加载中...'
|
|
|
// });
|
|
|
- let wsMessage={
|
|
|
- type: 'page',
|
|
|
- payload: 'equipment-monitoring'
|
|
|
- }
|
|
|
- let data = JSON.stringify(wsMessage)
|
|
|
- this.ws.send({data})
|
|
|
+ let wsMessage = {
|
|
|
+ type: 'page',
|
|
|
+ payload: 'equipment-monitoring'
|
|
|
+ }
|
|
|
+ let data = JSON.stringify(wsMessage)
|
|
|
+ this.ws.send({
|
|
|
+ data
|
|
|
+ })
|
|
|
})
|
|
|
this.ws.onMessage((res) => {
|
|
|
+ this.onMessageTime = new Date();
|
|
|
let data = JSON.parse(res.data)
|
|
|
// console.log(data,'resws')
|
|
|
if (res) {
|
|
@@ -139,12 +162,16 @@
|
|
|
this.ws.onError(() => {
|
|
|
console.log("WebSocket连接错误")
|
|
|
})
|
|
|
- if (this.timer == null) {
|
|
|
+ if(this.timer == null){
|
|
|
+ //检查断开重连
|
|
|
this.timer = setInterval(() => {
|
|
|
- if (this.ws.readyState != 1) {
|
|
|
- clearInterval(this.timer)
|
|
|
- this.timer = null
|
|
|
+ if(this.ws==null){
|
|
|
+ console.log('ws为null,检查断开重连')
|
|
|
+ this.InitWs()
|
|
|
+ }else if(this.ws.readyState != 1){
|
|
|
this.ws.close()
|
|
|
+ this.ws = null
|
|
|
+ console.log('未连接成功,检查断开重连')
|
|
|
this.InitWs()
|
|
|
}
|
|
|
}, 2000)
|