fix:修复SSE消息推送导致请求堵塞(谷歌浏览器并发请求不能超过6个)

This commit is contained in:
czhqwer
2025-03-30 11:49:03 +08:00
parent ece3ae6c2c
commit 1982a450a0
3 changed files with 28 additions and 20 deletions
@@ -83,6 +83,7 @@ export default {
this.showPasswordDialog = true; this.showPasswordDialog = true;
} }
localStorage.setItem('password', password);
this.$emit('main-user', mainUser); this.$emit('main-user', mainUser);
} catch (error) { } catch (error) {
console.error('获取密码失败:', error); console.error('获取密码失败:', error);
@@ -80,14 +80,34 @@ export default {
fileList: [], fileList: [],
enableShare: false, enableShare: false,
isAdmin: false, isAdmin: false,
sharedFilesEventSource: null,
systemEventSource: null,
}; };
}, },
mounted() { mounted() {
this.fetchFiles(); this.fetchFiles();
this.getShareStatus(); this.getShareStatus();
this.getShareAddress(); 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: { methods: {
async getShareAddress() { async getShareAddress() {
@@ -112,21 +132,6 @@ export default {
this.fileList = res.data; 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) { async downloadFile(file) {
try { try {
const adjusteUrl = this.replaceLocalhost(file.accessUrl) const adjusteUrl = this.replaceLocalhost(file.accessUrl)
+2
View File
@@ -320,6 +320,8 @@ const subscribeSystemEvent = (callback) => {
console.log("连接已关闭"); console.log("连接已关闭");
} }
}; };
return eventSource;
} }