From 1982a450a0ea39eee3cba541c8729ec345a45bef Mon Sep 17 00:00:00 2001 From: czhqwer Date: Sun, 30 Mar 2025 11:49:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8DSSE=E6=B6=88?= =?UTF-8?q?=E6=81=AF=E6=8E=A8=E9=80=81=E5=AF=BC=E8=87=B4=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=A0=B5=E5=A1=9E=EF=BC=88=E8=B0=B7=E6=AD=8C=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E5=B9=B6=E5=8F=91=E8=AF=B7=E6=B1=82=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E8=B6=85=E8=BF=876=E4=B8=AA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PasswordConfig/PasswordConfig.vue | 1 + .../src/components/ShareFile/ShareFile.vue | 45 ++++++++++--------- upload-file-frontend/src/utils/api.js | 2 + 3 files changed, 28 insertions(+), 20 deletions(-) diff --git a/upload-file-frontend/src/components/PasswordConfig/PasswordConfig.vue b/upload-file-frontend/src/components/PasswordConfig/PasswordConfig.vue index 8633e78..4252266 100644 --- a/upload-file-frontend/src/components/PasswordConfig/PasswordConfig.vue +++ b/upload-file-frontend/src/components/PasswordConfig/PasswordConfig.vue @@ -83,6 +83,7 @@ export default { this.showPasswordDialog = true; } + localStorage.setItem('password', password); this.$emit('main-user', mainUser); } catch (error) { console.error('获取密码失败:', error); diff --git a/upload-file-frontend/src/components/ShareFile/ShareFile.vue b/upload-file-frontend/src/components/ShareFile/ShareFile.vue index df34652..f7705ab 100644 --- a/upload-file-frontend/src/components/ShareFile/ShareFile.vue +++ b/upload-file-frontend/src/components/ShareFile/ShareFile.vue @@ -80,14 +80,34 @@ export default { fileList: [], enableShare: false, isAdmin: false, + sharedFilesEventSource: null, + systemEventSource: null, }; }, mounted() { this.fetchFiles(); this.getShareStatus(); this.getShareAddress(); - this.subscribeSharedFiles(); - this.subscribeSystemEvent(); + + this.sharedFilesEventSource = subscribeSharedFiles(() => { + this.fetchFiles(); + }); + + this.systemEventSource = subscribeSystemEvent((event) => { + if (event.type === 'enableShare') { + this.fileList = []; + this.enableShare = event.data.enable; + this.fetchFiles(); + } + }); + }, + beforeDestroy() { + if (this.sharedFilesEventSource) { + this.sharedFilesEventSource.close(); + } + if (this.systemEventSource) { + this.systemEventSource.close(); + } }, methods: { async getShareAddress() { @@ -112,21 +132,6 @@ export default { this.fileList = res.data; } }, - subscribeSharedFiles() { - subscribeSharedFiles(() => { - this.fetchFiles(); - }); - }, - subscribeSystemEvent() { - subscribeSystemEvent((event) => { - if (event.type === 'enableShare') { - this.fileList = []; - this.enableShare = event.data.enable; - this.fetchFiles(); - } - }); - }, - async downloadFile(file) { try { const adjusteUrl = this.replaceLocalhost(file.accessUrl) @@ -154,7 +159,7 @@ export default { if (!this.shareAddress || !url) return url; const shareIp = new URL(this.shareAddress).hostname; return url.replace(/localhost/g, shareIp); - }, + }, copyLink(accessUrl) { const adjusteUrl = this.replaceLocalhost(accessUrl) if (navigator.clipboard && navigator.clipboard.writeText) { @@ -196,8 +201,8 @@ export default { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning' - }).then(async() => { - + }).then(async () => { + const res = await unShareFile(fileIdentifier); if (res.code === 200) { this.fetchFiles(); diff --git a/upload-file-frontend/src/utils/api.js b/upload-file-frontend/src/utils/api.js index ecb9faf..1f5ba11 100644 --- a/upload-file-frontend/src/utils/api.js +++ b/upload-file-frontend/src/utils/api.js @@ -320,6 +320,8 @@ const subscribeSystemEvent = (callback) => { console.log("连接已关闭"); } }; + + return eventSource; }