优化:websocket 链接

修复:删除文件后,画矩形选取的问题
This commit is contained in:
jmal 2021-03-03 16:18:39 +08:00
parent 7d66081362
commit 0cda85c43c
3 changed files with 50 additions and 46 deletions

View File

@ -588,8 +588,6 @@ import '@/utils/directives.js'
import 'pl-table/themes/index.css'; import 'pl-table/themes/index.css';
import {PlTable, PlTableColumn} from 'pl-table'; import {PlTable, PlTableColumn} from 'pl-table';
import ws from '@/websocket/websocket_config';
import fileConfig from '@/utils/file-config' import fileConfig from '@/utils/file-config'
var rowStyleExecuting = false var rowStyleExecuting = false
@ -942,17 +940,7 @@ export default {
// 画矩形选区 // 画矩形选区
this.darwRectangle() this.darwRectangle()
// 监听websocket Bus.$on('msg/file/change', (msg) => this.onmessage(msg))
if (ws.isConnected) {
this.onmessage()
} else {
const that = this
setTimeout(function () {
if (ws.isConnected) {
that.onmessage()
}
}, 3000)
}
}, },
destroyed() { destroyed() {
window.removeEventListener('popstate', this.goBack, false); window.removeEventListener('popstate', this.goBack, false);
@ -990,32 +978,29 @@ export default {
} }
}, },
methods: { methods: {
onmessage() { onmessage(msg) {
// 订阅消息 let fileDoc = JSON.parse(msg.body)
this.stompClient = ws.stompClient.subscribe('/user/queue/update', (msg) => { const url = msg.headers.url
let fileDoc = JSON.parse(msg.body) let index = this.fileList.findIndex(file => file.id === fileDoc.id)
const url = msg.headers.url if ('updateFile' === url) {
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
}
} }
if ('deleteFile' === url) { }
if (index > -1) { if ('deleteFile' === url) {
this.fileList.splice(index, 1) if (index > -1) {
} this.fileList.splice(index, 1)
} }
if ('createFile' === url) { }
if (!this.path) { if ('createFile' === url) {
this.path = '' if (!this.path) {
} this.path = ''
if (this.path + '/' === fileDoc.$set.path) {
this.getFileList()
}
} }
}, ws.headers); if (this.path + '/' === fileDoc.$set.path) {
this.getFileList()
}
}
}, },
load() { load() {
this.getFileList(true) this.getFileList(true)
@ -2849,6 +2834,8 @@ export default {
for (let i = 0; i < removeFileIndexList.length; i++) { for (let i = 0; i < removeFileIndexList.length; i++) {
that.fileList.splice(removeFileIndexList[i], 1) that.fileList.splice(removeFileIndexList[i], 1)
} }
// 改变拖拽目标
that.rowDrop()
}, 300) }, 300)
}, },
// 预览压缩文件 // 预览压缩文件

View File

@ -16,7 +16,7 @@
</el-menu> </el-menu>
</el-scrollbar> </el-scrollbar>
<div class="quota-space"> <div class="quota-space">
<el-progress :class="{'collapse': isCollapse}" :percentage="percentage" :format="progressFormat" :color="customColors"></el-progress> <el-progress v-show="percentage > 0" :class="{'collapse': isCollapse}" :percentage="percentage" :format="progressFormat" :color="customColors"></el-progress>
</div> </div>
<div class="webdav"> <div class="webdav">
<div :class="{'normal': true, 'collapse': isCollapse}" @mousemove="showCopyBtn = true" @mouseleave="showCopyBtn = false"> <div :class="{'normal': true, 'collapse': isCollapse}" @mousemove="showCopyBtn = true" @mouseleave="showCopyBtn = false">
@ -32,6 +32,7 @@
</template> </template>
<script> <script>
import Bus from '@/assets/js/bus'
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import Logo from './Logo' import Logo from './Logo'
import SidebarItem from './SidebarItem' import SidebarItem from './SidebarItem'
@ -52,7 +53,8 @@ export default {
{color: '#1989fa', percentage: 40}, {color: '#1989fa', percentage: 40},
{color: '#6f7ad3', percentage: 20} {color: '#6f7ad3', percentage: 20}
], ],
showCopyBtn: false showCopyBtn: false,
takeUpSpace: 0,
} }
}, },
computed: { computed: {
@ -102,10 +104,20 @@ export default {
}, },
watch: { watch: {
isCollapse(val){ isCollapse(val){
this.progressFormat()
} }
}, },
mounted() {
Bus.$on('msg/file/change', (msg) => this.onmessage(msg))
},
methods: { methods: {
onmessage(msg) {
const takeUpSpace = msg.headers.space
if (takeUpSpace) {
this.takeUpSpace = takeUpSpace
const space = takeUpSpace/1024/1024/1024
this.percentage = Number((space/this.userInfo.quota * 100).toFixed(1))
}
},
copyWebDAVLink(className) { copyWebDAVLink(className) {
let clipboard = new Clipboard(className) let clipboard = new Clipboard(className)
clipboard.on('success', e => { clipboard.on('success', e => {
@ -120,23 +132,24 @@ export default {
}) })
}, },
mouseleave() { mouseleave() {
console.log('mouseleave')
}, },
onmousemove() { onmousemove() {
console.log('onmousemove')
}, },
progressFormat() { progressFormat() {
const space = this.userInfo.takeUpSpace/1024/1024/1024 if (this.takeUpSpace === 0) {
this.takeUpSpace = this.userInfo.takeUpSpace
}
const quota = this.userInfo.quota const quota = this.userInfo.quota
const space = this.takeUpSpace/1024/1024/1024
if(space && quota > 0){ if(space && quota > 0){
this.percentage = Number((space/quota * 100).toFixed(1)) this.percentage = Number((space/quota * 100).toFixed(1))
if(this.isCollapse){ if(this.isCollapse){
return `${formatSize(this.userInfo.takeUpSpace)}` return `${formatSize(this.takeUpSpace)}`
} else { } else {
return `${formatSize(this.userInfo.takeUpSpace)}/${quota}GB` return `${formatSize(this.takeUpSpace)}/${quota}GB`
} }
} }
}, }
} }
} }
</script> </script>

View File

@ -1,6 +1,7 @@
import SockJS from 'sockjs-client'; import SockJS from 'sockjs-client';
import Stomp from './stomp-index'; import Stomp from './stomp-index';
import ws from './websocket_config'; import ws from './websocket_config';
import Bus from '@/assets/js/bus'
export function toConnection(username,token) { export function toConnection(username,token) {
connect(username,token); connect(username,token);
@ -30,10 +31,13 @@ function connect(username,token){
// 向服务器发起websocket连接 // 向服务器发起websocket连接
ws.stompClient.connect(ws.headers,() => { ws.stompClient.connect(ws.headers,() => {
ws.isConnected = true; ws.isConnected = true;
// 订阅消息
ws.stompClient.subscribe('/user/queue/update', (msg) => {
Bus.$emit('msg/file/change', msg)
}, ws.headers);
}, (err) => { }, (err) => {
ws.isConnected = false; ws.isConnected = false;
// 连接发生错误时的处理函数 // 连接发生错误时的处理函数
console.log(err);
}); });
} }