From abcbe39d4f2cba799140bc6564b712b09b1f6f88 Mon Sep 17 00:00:00 2001 From: jmal Date: Thu, 25 Jul 2024 15:28:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96sse=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 1 - src/sse/SSEClient.js | 22 ++++++++++++++++++++-- src/store/modules/user.js | 1 - 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index ea000be..bb7612e 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -1351,7 +1351,6 @@ export default { keydown(event) { const { keyCode } = event const isCmd = this.checkCmdKey(event) - console.log('keydown', 'keyCode', keyCode, 'isCmd', isCmd) const checkPreviewVisible = this.checkPreviewVisible() // space diff --git a/src/sse/SSEClient.js b/src/sse/SSEClient.js index 3f428df..23f22c9 100644 --- a/src/sse/SSEClient.js +++ b/src/sse/SSEClient.js @@ -5,6 +5,7 @@ import { generateUUID } from "ant-design-vue/lib/vc-select/util"; let eventSource = null; let timer = null; +let lastHeartbeat = new Date().getTime(); const uuid = generateUUID(); const throttledConnectSSE = _.throttle((username) => { @@ -31,11 +32,16 @@ function connectToSSE(username) { eventSource.addEventListener('message', handleMessage); eventSource.addEventListener('error', handleError.bind(null, username)); + startHeartbeatCheck(username); } function handleMessage(event) { - const msg = JSON.parse(event.data); - onMessage(msg); + if (event.data === 'h') { + lastHeartbeat = new Date().getTime(); + } else { + const msg = JSON.parse(event.data); + onMessage(msg); + } } function handleError(username) { @@ -49,6 +55,18 @@ function clearExistingTimer() { } } +function startHeartbeatCheck(username) { + clearExistingTimer(); + timer = setInterval(() => { + if (eventSource.readyState === 1 && new Date().getTime() - lastHeartbeat > 5000) { + eventSource.close(); + } + if (eventSource.readyState === 2) { + throttledConnectSSE(username); + } + }, 3000); +} + function onMessage(msg) { const { url, body } = msg; const eventMapping = { diff --git a/src/store/modules/user.js b/src/store/modules/user.js index 75c10f0..9de0f06 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -209,7 +209,6 @@ const actions = { // update token setToken({ commit }, jmalToken) { commit('SET_TOKEN', jmalToken) - console.log('jmalToken', jmalToken) }, // remove share token From 00d0d829123321b0c07875153169b3aeb3e9f0b8 Mon Sep 17 00:00:00 2001 From: jmal Date: Thu, 25 Jul 2024 16:41:10 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E6=98=BE=E7=A4=BA=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E5=A4=B9=E5=A4=A7=E5=B0=8F=E7=9A=84=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/ShowFile/ShowFile.vue | 8 ++++++-- src/views/trash/index.vue | 3 ++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/ShowFile/ShowFile.vue b/src/components/ShowFile/ShowFile.vue index bb7612e..13ba41e 100644 --- a/src/components/ShowFile/ShowFile.vue +++ b/src/components/ShowFile/ShowFile.vue @@ -2594,7 +2594,7 @@ export default { child[1].iconClass = 'menu-empty' } if (child[2]) { - if (localStorage.getItem('showFolderSize') === 'true') { + if (localStorage.getItem('showFolderSize') === '1') { child[2].iconClass = 'duigou' } else { child[2].iconClass = 'menu-empty' @@ -3413,7 +3413,11 @@ export default { break case 'show-folder-size': const showFolderSize = localStorage.getItem('showFolderSize') - localStorage.setItem('showFolderSize', showFolderSize ? false : true) + if (showFolderSize === '1') { + localStorage.setItem('showFolderSize', '0') + } else { + localStorage.setItem('showFolderSize', '1') + } this.getFileList() break case 'orderName': diff --git a/src/views/trash/index.vue b/src/views/trash/index.vue index ecbacf6..c189644 100644 --- a/src/views/trash/index.vue +++ b/src/views/trash/index.vue @@ -34,7 +34,8 @@ export default { { label: '查看', operation: 'viewMode', child: [ { iconClass: this.grid ? '' : 'menu-point', label: '列表', operation: 'vmode-list' }, - { iconClass: this.grid ? 'menu-point' : '', label: '缩略图', operation: 'vmode-grid' } + { iconClass: this.grid ? 'menu-point' : '', label: '缩略图', operation: 'vmode-grid' }, + { label: '显示文件夹大小', operation: 'show-folder-size'}, ] }, {