Browse Source

绑定标签 websocket

master
z_yu 3 years ago
parent
commit
e0aa23bc03
  1. 174
      src/views/components/WarehouseWarning.vue
  2. 4
      src/views/storeManage/tagManage/bindTagList/index.vue
  3. 91
      src/views/storeManage/warehouse3D/index.vue

174
src/views/components/WarehouseWarning.vue

@ -32,13 +32,32 @@ export default {
data() {
return {
tableData: [],
timeout: 1000
socket: null,
lockReconnect: false, //
heartCheck: {
timeout: 3000,
timeoutobj: null,
serverTimeoutObj: null,
start: function() {
const that = this
clearTimeout(this.timeoutObj)
clearTimeout(this.serverTimeoutObj)
this.timeObj = setTimeout(function() {
// ping-pong
this.socket.send('ping')
that.serverTimeoutObj = setTimeout(function() {
this.socket.close()
}, that.timeout)
}, this.timeout)
}
}
}
},
created() {
this.initWebSocket()
},
// created() {
// this.openSocket()
// },
mounted() {
this.openSocket()
this.getData()
console.log(11333)
this.$nextTick(() => {
@ -59,9 +78,6 @@ export default {
// })
// })
},
destroyed() {
clearInterval(this.timer)
},
methods: {
getData() {
this.tableData = data1.rows
@ -109,120 +125,40 @@ export default {
}
}, 1000 * 3 * this.scollNum)
},
initWebSocket() {
const wsUri = process.env.VUE_APP_WS_API + '/webSocket'
this.websock = new WebSocket(wsUri)
this.websock.onerror = this.webSocketOnError
this.websock.onmessage = this.webSocketOnMessage
},
webSocketOnError(e) {
this.$notify({
title: 'WebSocket连接发生错误',
type: 'error',
duration: 0
})
},
webSocketOnMessage(e) {
const data = JSON.parse(e.data)
console.log(data)
if (data.msgType === 'INFO') {
this.$notify({
title: '',
message: data.msg,
type: 'success',
dangerouslyUseHTMLString: true,
duration: 5500
})
} else if (data.msgType === 'ERROR') {
this.$notify({
title: '',
message: data.msg,
dangerouslyUseHTMLString: true,
type: 'error',
duration: 0
})
openSocket() {
if (!('WebSocket' in window)) {
console.log('您的浏览器不支持WebSocket')
} else {
console.log('您的浏览器支持WebSocket')
const socketUrl = process.env.VUE_APP_WS_API + '/webSocket'
if (this.socket != null) {
this.socket.close()
this.socket = null
}
this.socket = new WebSocket(socketUrl)
//
this.socket.onopen = () => {
console.log('websocket已经打开')
//
this.heartCheck.start()
}
//
this.socket.onmessage = (msg) => {
console.log(msg)
//
this.heartCheck.start()
}
//
this.socket.onclose = function() {
console.log('websocket已关闭')
}
//
this.socket.onerror = function(e) {
console.log('websocket发生了错误')
console.log(e)
}
}
},
webSocketSend(agentData) {
this.websock.send(agentData)
}
// initWebSocket() {
// // if (WebSocket in window) {
// // weosocket
// const wsUri = process.env.VUE_APP_WS_API + '/webSocket'
// this.websocket = null
// 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
// // } else {
// // // WebSocket
// // console.log(' WebSocket!')
// // }
// },
// websocketonopen() {
// this.start()
// },
// start() {
// //
// const that = this
// that.timeoutObj && clearTimeout(that.timeoutObj)
// that.timeoutObj = setTimeout(function() {
// //
// if (that.websocket && that.websocket.readyState === 1) {
// //
// console.log('WebSocket')
// that.websocket.send('----timingHeart---')
// } else { //
// that.reconnect()
// }
// }, that.timeout)
// },
// reconnect() { //
// console.log('')
// const that = this
// if (that.websocket && that.websocket.readyState === 1) {
// clearInterval(that.timeoutnum)
// that.timeoutnum = null
// that.timeNum = 0
// return
// }
// if (!that.timeoutnum) {
// that.timeoutnum = setInterval(function() {
// if (that.websocket && that.websocket.readyState === 1) {
// clearInterval(that.timeoutnum)
// that.timeoutnum = null
// that.timeNum = 0
// return
// }
// //
// that.initWebSocket()
// that.timeNum++
// if (that.timeNum >= 3) {
// clearInterval(that.timeoutnum)
// that.timeoutnum = null
// that.timeNum = 0
// }
// }, 1000)
// }
// },
// websocketonerror(e) {
// //
// // this.initWebSocket()
// console.log('WebSocket')
// },
// websocketonmessage(e) {
// //
// var data = JSON.parse(e.data)
// // this.$store.commit('SET_ws', data)
// console.log('', data)
// // ...
// },
// websocketclose(e) {
// //
// this.websocket && this.websocket.close && this.websocket.close()
// }
}
}
</script>

4
src/views/storeManage/tagManage/bindTagList/index.vue

@ -141,12 +141,12 @@ export default {
sizeChangeHandler(e) {
this.page.size = e
this.page.page = 1
this.refresh()
this.initData()
},
//
pageChangeHandler(e) {
this.page.page = e
this.refresh()
this.initData()
},
selectionChangeHandler(val) {
this.selections = val

91
src/views/storeManage/warehouse3D/index.vue

@ -64,8 +64,8 @@ export default {
}
},
created() {
console.log(1111)
this.initWebSocket()
// console.log(1111)
// this.initWebSocket()
if (this.$route.params.roomId) {
this.activeIndex = this.$route.params.roomId
}
@ -98,50 +98,51 @@ export default {
},
destroyed() {
window.removeEventListener('message', this.handleMessageEvent)
},
initWebSocket() {
// weosocket
const url = 'ws://192.168.99.65:7071/webSocket'
const wsuri = url // ws
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
},
websocketonopen() {
console.log('WebSocket连接成功')
// co data = {
// type: 'user_init',
// userid: 'xxx'
// }
// this.websocket.send(
// //
// JSON.stringify(data)
// )
},
websocketonerror(e) {
//
// this.initWebSocket()
console.log('WebSocket连接发生错误')
},
websocketonmessage(e) {
//
console.log(e.data)
var data = JSON.parse(e.data)
this.$store.commit('SET_ws', data)
console.log('接收数据')
// ...
},
websocketsend(agentData) {
//
this.websocket.send(agentData)
},
websocketclose(e) {
//
console.log('WebSocket关闭')
console.log(JSON.stringify(e))
}
// ,
// initWebSocket() {
// // weosocket
// const url = 'ws://192.168.99.65:7071/webSocket'
// const wsuri = url // ws
// 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
// },
// websocketonopen() {
// console.log('WebSocket')
// // co data = {
// // type: 'user_init',
// // userid: 'xxx'
// // }
// // this.websocket.send(
// // //
// // JSON.stringify(data)
// // )
// },
// websocketonerror(e) {
// //
// // this.initWebSocket()
// console.log('WebSocket')
// },
// websocketonmessage(e) {
// //
// console.log(e.data)
// var data = JSON.parse(e.data)
// this.$store.commit('SET_ws', data)
// console.log('')
// // ...
// },
// websocketsend(agentData) {
// //
// this.websocket.send(agentData)
// },
// websocketclose(e) {
// //
// console.log('WebSocket')
// console.log(JSON.stringify(e))
// }
}
}
</script>

Loading…
Cancel
Save