定时器改WebSocket
This commit is contained in:
@@ -25,8 +25,8 @@ function websocketSend (agentData) {
|
||||
}
|
||||
if (websock.readyState === websock.CLOSED) { // websock.CLOSED = 3
|
||||
console.log('websock.readyState=3')
|
||||
Message.error('ws连接异常,请稍候重试')
|
||||
errorCallback()
|
||||
// Message.error('ws连接异常,请稍候重试')
|
||||
// errorCallback()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
@@ -36,7 +36,7 @@ function websocketclose (e) {
|
||||
// e.code === 1000 表示正常关闭。 无论为何目的而创建, 该链接都已成功完成任务。
|
||||
// e.code !== 1000 表示非正常关闭。
|
||||
if (e && e.code !== 1000) {
|
||||
Message.error('ws连接异常,请稍候重试')
|
||||
Message.error('server error')
|
||||
errorCallback()
|
||||
// // 如果需要设置异常重连则可替换为下面的代码,自行进行测试
|
||||
// if (tryTime < 10) {
|
||||
@@ -75,8 +75,8 @@ function initWebSocket () {
|
||||
websocketOpen()
|
||||
}
|
||||
websock.onerror = function () {
|
||||
Message.error('ws连接异常,请稍候重试')
|
||||
errorCallback()
|
||||
// Message.error('ws连接异常,请稍候重试')
|
||||
// errorCallback()
|
||||
}
|
||||
websock.onclose = function (e) {
|
||||
websocketclose(e)
|
||||
|
||||
@@ -69,8 +69,8 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
interTime: this.$store.getters.setTime,
|
||||
timer: null,
|
||||
dataInfo: {}
|
||||
timer: null
|
||||
// dataInfo: {}
|
||||
// dataInfo: {
|
||||
// device_info: 'NobleLiftPS10LMT_HuaHai',
|
||||
// task_name: '无',
|
||||
@@ -99,9 +99,15 @@ export default {
|
||||
// }
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
dataInfo () {
|
||||
let res = JSON.stringify(this.$store.getters.materObj) !== '{}' ? this.$store.getters.materObj : {}
|
||||
return res
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.initData()
|
||||
this.refresh()
|
||||
// this.initData()
|
||||
// this.refresh()
|
||||
},
|
||||
beforeDestroy () {
|
||||
clearInterval(this.timer)
|
||||
|
||||
@@ -86,6 +86,7 @@ export default {
|
||||
}
|
||||
},
|
||||
created () {
|
||||
this.$store.dispatch('materObj', {})
|
||||
if (this.$i18n.locale === 'zh-cn') {
|
||||
this.selectType = 'zh-cn'
|
||||
} else if (this.$i18n.locale === 'en-us') {
|
||||
|
||||
@@ -263,7 +263,7 @@ export default {
|
||||
}
|
||||
},
|
||||
beforeDestroy () {
|
||||
// clearInterval(this.timer)
|
||||
clearInterval(this.timer)
|
||||
closeWebsocket(true)
|
||||
},
|
||||
destroyed () {
|
||||
@@ -368,17 +368,24 @@ export default {
|
||||
let getTimestamp = new Date().getTime()
|
||||
let url = this.$store.getters.baseUrl
|
||||
url = url.substring(7)
|
||||
console.log(url)
|
||||
sendWebsocket('ws://' + url + '/webSocket/SendHomeInfo/' + getTimestamp, {}, this.wsMessage, null)
|
||||
// sendWebsocket('ws://' + '192.168.10.130:8018' + '/webSocket/SendHomeInfo/' + getTimestamp, {}, this.wsMessage, null)
|
||||
sendWebsocket('ws://' + url + '/webSocket/SendHomeInfo/' + getTimestamp, {}, this.wsMessage, this.wsErr)
|
||||
},
|
||||
wsMessage (res) {
|
||||
if (res.code === '1') {
|
||||
this.topInfo = res.result
|
||||
// console.log(res)
|
||||
clearInterval(this.timer)
|
||||
let data = res.head
|
||||
this.$store.dispatch('materObj', res.home.result)
|
||||
if (data.code === '1') {
|
||||
this.topInfo = data.result
|
||||
} else {
|
||||
this.toast(res.desc)
|
||||
this.toast(data.desc)
|
||||
}
|
||||
},
|
||||
wsErr () {
|
||||
this.timer = setTimeout(() => {
|
||||
this._queryHead()
|
||||
}, 10000)
|
||||
},
|
||||
toEixt () {
|
||||
this.$store.dispatch('setSignOut')
|
||||
this._authLogout()
|
||||
|
||||
Reference in New Issue
Block a user