Commit 00e0e9bd authored by 耿迪迪's avatar 耿迪迪

出入库websocket前台调整

parent 1fe1e635
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
shelfId: null, shelfId: null,
}, },
ws: null, ws: null,
heartbeatInterval: null
} }
}, },
created(){ created(){
...@@ -240,19 +241,26 @@ ...@@ -240,19 +241,26 @@
this.ws = new WebSocket('ws://' + window.location.host + process.env.VUE_APP_BASE_API + '/ws/notifications'); this.ws = new WebSocket('ws://' + window.location.host + process.env.VUE_APP_BASE_API + '/ws/notifications');
this.ws.onopen = () => { this.ws.onopen = () => {
console.log('WebSocket Connected'); console.log('WebSocket Connected');
// 连接建立后,开始定期发送心跳
this.heartbeatInterval = setInterval(() => {
if (this.ws.readyState === WebSocket.OPEN) {
this.ws.send(JSON.stringify({ type: 'ping' }));
console.log("发送心跳")
}
}, 30000);
}; };
this.ws.onmessage = (event) => { this.ws.onmessage = (event) => {
// Add received message to the list // Add received message to the list
const message = JSON.parse(event.data); const message = JSON.parse(event.data);
if(message && message.SHELFID && message.SHELFID == this.$route.query.shelfId){ if(message && message.shelfId && message.shelfId == this.$route.query.shelfId){
//入库 //入库
if("I" == message.OPTYPE){ if("I" == message.optype){
const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.LOCATION); const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.location);
locationInfo.rid = message.RID; locationInfo.rid = message.rid;
} }
//出库 //出库
if("O" == message.OPTYPE){ if("O" == message.optype){
const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.LOCATION); const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.location);
locationInfo.rid = null; locationInfo.rid = null;
} }
} }
...@@ -262,6 +270,7 @@ ...@@ -262,6 +270,7 @@
}; };
this.ws.onclose = () => { this.ws.onclose = () => {
console.log('WebSocket Closed'); console.log('WebSocket Closed');
clearInterval(this.heartbeatInterval);
}; };
}, },
disconnect() { disconnect() {
......
...@@ -87,6 +87,7 @@ ...@@ -87,6 +87,7 @@
shelfId: null, shelfId: null,
}, },
ws: null, ws: null,
heartbeatInterval: null
} }
}, },
created(){ created(){
...@@ -240,19 +241,26 @@ ...@@ -240,19 +241,26 @@
this.ws = new WebSocket('ws://' + window.location.host + process.env.VUE_APP_BASE_API + '/ws/notifications'); this.ws = new WebSocket('ws://' + window.location.host + process.env.VUE_APP_BASE_API + '/ws/notifications');
this.ws.onopen = () => { this.ws.onopen = () => {
console.log('WebSocket Connected'); console.log('WebSocket Connected');
// 连接建立后,开始定期发送心跳
this.heartbeatInterval = setInterval(() => {
if (this.ws.readyState === WebSocket.OPEN) {
this.ws.send(JSON.stringify({ type: 'ping' }));
console.log("发送心跳")
}
}, 30000);
}; };
this.ws.onmessage = (event) => { this.ws.onmessage = (event) => {
// Add received message to the list // Add received message to the list
const message = JSON.parse(event.data); const message = JSON.parse(event.data);
if(message && message.SHELFID && message.SHELFID == this.$route.query.shelfId){ if(message && message.shelfId && message.shelfId == this.$route.query.shelfId){
//入库 //入库
if("I" == message.OPTYPE){ if("I" == message.optype){
const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.LOCATION); const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.location);
locationInfo.rid = message.RID; locationInfo.rid = message.rid;
} }
//出库 //出库
if("O" == message.OPTYPE){ if("O" == message.optype){
const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.LOCATION); const locationInfo = this.shelfLayoutList.flat().find(location => location.location === message.location);
locationInfo.rid = null; locationInfo.rid = null;
} }
} }
...@@ -262,6 +270,7 @@ ...@@ -262,6 +270,7 @@
}; };
this.ws.onclose = () => { this.ws.onclose = () => {
console.log('WebSocket Closed'); console.log('WebSocket Closed');
clearInterval(this.heartbeatInterval);
}; };
}, },
disconnect() { disconnect() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment