修改ws接收方式,通过headers.url来判断消息来源

This commit is contained in:
jmal 2020-07-10 10:24:30 +08:00
parent 505f19def1
commit 1cfbf3f8d5

View File

@ -663,6 +663,7 @@
notPreviewDialogVisible: false, notPreviewDialogVisible: false,
openingFile: '', openingFile: '',
openCompressionVisible: false, openCompressionVisible: false,
stompClient: undefined,//websocket订阅集合
} }
}, },
computed: { computed: {
@ -811,25 +812,24 @@
methods: { methods: {
onmessage(){ onmessage(){
// 订阅消息 // 订阅消息
console.log("订阅",'/user/queue/updateFile') this.stompClient = ws.stompClient.subscribe('/user/queue/update', (msg) => {
this.stompClient = ws.stompClient.subscribe('/user/queue/updateFile', (msg) => {
let fileDoc = JSON.parse(msg.body) let fileDoc = JSON.parse(msg.body)
console.log('/queue/updateFile', fileDoc) const url = msg.headers.url
console.log('onmessage.url', url, fileDoc)
let index = this.fileList.findIndex(file=>file.id === fileDoc.id) let index = this.fileList.findIndex(file=>file.id === fileDoc.id)
if(index > -1){ if('updateFile' === url){
this.fileList[index].size = fileDoc.size if(index > -1){
this.fileList[index].agoTime = 1 this.fileList[index].size = fileDoc.size
} this.fileList[index].agoTime = 1
},ws.headers); }
console.log("订阅",'/user/queue/deleteFile') }
this.stompClient = ws.stompClient.subscribe('/user/queue/deleteFile', (msg) => { if('deleteFile' === url){
let fileDoc = JSON.parse(msg.body) if(index > -1){
console.log('/queue/deleteFile', fileDoc) this.fileList.splice(index,1)
let index = this.fileList.findIndex(file=>file.id === fileDoc.id) }
if(index > -1){
this.fileList.splice(index,1)
} }
},ws.headers); },ws.headers);
console.log("订阅",'/user/queue/update')
}, },
load () { load () {
this.getFileList(true) this.getFileList(true)