fix: 保持SSE长连接不断开,移除主动closeConnection逻辑

前端修复:
- init()无条件建立SSE连接
- error handler无条件重连,去掉hasActiveTasks判断

后端修复:
- notifyAllTasksCompleted不再延迟关闭连接
- SSE保持长连接持续接收任务状态更新
This commit is contained in:
小蟑螂
2026-04-16 13:27:48 +08:00
parent 3ce5eba22e
commit ae16f6ab06
3 changed files with 6 additions and 36 deletions
@@ -203,13 +203,10 @@ export const useImportTaskStore = defineStore('import-task', () => {
connection.addEventListener('error', (event) => {
console.error('SSE连接错误:', event);
sseConnected.value = false;
// 如果连接关闭,尝试重连
// 如果连接关闭,无条件重连,不判断活跃任务
if (connection.getReadyState() === EventSource.CLOSED) {
// 延迟重连,避免频繁重连
setTimeout(() => {
if (hasActiveTasks.value) {
connectSse();
}
connectSse();
}, 5000);
}
});
@@ -238,10 +235,8 @@ export const useImportTaskStore = defineStore('import-task', () => {
async function init() {
await fetchTasks(true);
// 如果有进行中的任务,建立SSE连接
if (hasActiveTasks.value && !sseConnection.value) {
connectSse();
}
// 页面加载时无条件建立SSE连接,接收实时任务状态更新
connectSse();
}
/**