Browse Source

websocket

master
z_yu 3 years ago
parent
commit
0ddeddeaee
  1. 126
      src/views/components/WarehouseWarning.vue
  2. 3
      src/views/storeManage/warehouse3D/index.vue

126
src/views/components/WarehouseWarning.vue

@ -31,9 +31,13 @@ export default {
}, },
data() { data() {
return { return {
tableData: []
tableData: [],
timeout: 1000
} }
}, },
created() {
this.initWebSocket()
},
mounted() { mounted() {
this.getData() this.getData()
console.log(11333) console.log(11333)
@ -104,15 +108,129 @@ export default {
} }
} }
}, 1000 * 3 * this.scollNum) }, 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
})
} }
},
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> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
@import '~@/assets/styles/lend-manage.scss';
.warehouse-left{
@import "~@/assets/styles/lend-manage.scss";
.warehouse-left {
position: relative; position: relative;
h2{
h2 {
position: absolute; position: absolute;
left: 50%; left: 50%;
top: 0; top: 0;

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

@ -101,7 +101,7 @@ export default {
}, },
initWebSocket() { initWebSocket() {
// weosocket // weosocket
const url = 'ws://192.168.99.65:7070/webSocket/testname'
const url = 'ws://192.168.99.65:7071/webSocket'
const wsuri = url // ws const wsuri = url // ws
this.websocket = new WebSocket(wsuri) this.websocket = new WebSocket(wsuri)
this.websocket.onopen = this.websocketonopen this.websocket.onopen = this.websocketonopen
@ -127,6 +127,7 @@ export default {
}, },
websocketonmessage(e) { websocketonmessage(e) {
// //
console.log(e.data)
var data = JSON.parse(e.data) var data = JSON.parse(e.data)
this.$store.commit('SET_ws', data) this.$store.commit('SET_ws', data)
console.log('接收数据') console.log('接收数据')

Loading…
Cancel
Save