From 76067d3c6785762652e3cd9dd3f49404d514f875 Mon Sep 17 00:00:00 2001 From: zzh Date: Fri, 21 Nov 2025 22:09:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/js/components/notifications.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend/js/components/notifications.js b/frontend/js/components/notifications.js index 39adda4..657d64e 100644 --- a/frontend/js/components/notifications.js +++ b/frontend/js/components/notifications.js @@ -58,10 +58,17 @@ const data = await API.getUnreadCount(); const badge = document.getElementById('notification-badge'); const count = data.count || 0; + const previousCount = parseInt(badge.textContent) || 0; if (count > 0) { badge.textContent = count > 99 ? '99+' : count; badge.style.display = 'block'; + + // 如果有新消息且面板是打开的,自动刷新列表 + if (count > previousCount && isOpen) { + console.log('[Notifications] 检测到新消息,刷新列表'); + await loadNotifications(); + } } else { badge.style.display = 'none'; } @@ -222,14 +229,14 @@ // 初始加载未读数量 await updateUnreadCount(); - // 每30秒更新一次未读数量 + // 每5秒更新一次未读数量(实时检查新消息) if (notificationInterval) { clearInterval(notificationInterval); } - notificationInterval = setInterval(updateUnreadCount, 30000); + notificationInterval = setInterval(updateUnreadCount, 5000); isInitialized = true; - console.log('[Notifications] 初始化完成'); + console.log('[Notifications] 初始化完成,实时轮询已启动(5秒间隔)'); } catch (e) { console.error('初始化通知系统失败:', e); }