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