From 0cda85c43cff7bcdea7cbf5da3f774d00d4f8d6f Mon Sep 17 00:00:00 2001 From: jmal Date: Wed, 3 Mar 2021 16:18:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=EF=BC=9Awebsocket=20?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=20=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=96=87=E4=BB=B6=E5=90=8E=EF=BC=8C=E7=94=BB=E7=9F=A9?= =?UTF-8?q?=E5=BD=A2=E9=80=89=E5=8F=96=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 59 ++++++++++--------------- src/layout/components/Sidebar/index.vue | 31 +++++++++---- src/websocket/sockJS.js | 6 ++- 3 files changed, 50 insertions(+), 46 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index 5025e13..93d34a5 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -588,8 +588,6 @@ import '@/utils/directives.js' import 'pl-table/themes/index.css'; import {PlTable, PlTableColumn} from 'pl-table'; - -import ws from '@/websocket/websocket_config'; import fileConfig from '@/utils/file-config' var rowStyleExecuting = false @@ -942,17 +940,7 @@ export default { // 画矩形选区 this.darwRectangle() - // 监听websocket - if (ws.isConnected) { - this.onmessage() - } else { - const that = this - setTimeout(function () { - if (ws.isConnected) { - that.onmessage() - } - }, 3000) - } + Bus.$on('msg/file/change', (msg) => this.onmessage(msg)) }, destroyed() { window.removeEventListener('popstate', this.goBack, false); @@ -990,32 +978,29 @@ export default { } }, methods: { - onmessage() { - // 订阅消息 - this.stompClient = ws.stompClient.subscribe('/user/queue/update', (msg) => { - let fileDoc = JSON.parse(msg.body) - const url = msg.headers.url - let index = this.fileList.findIndex(file => file.id === fileDoc.id) - if ('updateFile' === url) { - if (index > -1) { - this.fileList[index].size = fileDoc.size - this.fileList[index].agoTime = 1 - } + onmessage(msg) { + let fileDoc = JSON.parse(msg.body) + const url = msg.headers.url + let index = this.fileList.findIndex(file => file.id === fileDoc.id) + if ('updateFile' === url) { + if (index > -1) { + this.fileList[index].size = fileDoc.size + this.fileList[index].agoTime = 1 } - if ('deleteFile' === url) { - if (index > -1) { - this.fileList.splice(index, 1) - } + } + if ('deleteFile' === url) { + if (index > -1) { + this.fileList.splice(index, 1) } - if ('createFile' === url) { - if (!this.path) { - this.path = '' - } - if (this.path + '/' === fileDoc.$set.path) { - this.getFileList() - } + } + if ('createFile' === url) { + if (!this.path) { + this.path = '' } - }, ws.headers); + if (this.path + '/' === fileDoc.$set.path) { + this.getFileList() + } + } }, load() { this.getFileList(true) @@ -2849,6 +2834,8 @@ export default { for (let i = 0; i < removeFileIndexList.length; i++) { that.fileList.splice(removeFileIndexList[i], 1) } + // 改变拖拽目标 + that.rowDrop() }, 300) }, // 预览压缩文件 diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue index c056a79..554cd49 100644 --- a/src/layout/components/Sidebar/index.vue +++ b/src/layout/components/Sidebar/index.vue @@ -16,7 +16,7 @@
- +
@@ -32,6 +32,7 @@ diff --git a/src/websocket/sockJS.js b/src/websocket/sockJS.js index b584d48..4d8351f 100644 --- a/src/websocket/sockJS.js +++ b/src/websocket/sockJS.js @@ -1,6 +1,7 @@ import SockJS from 'sockjs-client'; import Stomp from './stomp-index'; import ws from './websocket_config'; +import Bus from '@/assets/js/bus' export function toConnection(username,token) { connect(username,token); @@ -30,10 +31,13 @@ function connect(username,token){ // 向服务器发起websocket连接 ws.stompClient.connect(ws.headers,() => { ws.isConnected = true; + // 订阅消息 + ws.stompClient.subscribe('/user/queue/update', (msg) => { + Bus.$emit('msg/file/change', msg) + }, ws.headers); }, (err) => { ws.isConnected = false; // 连接发生错误时的处理函数 - console.log(err); }); }