消息提醒优化

This commit is contained in:
zzh 2025-11-21 22:09:37 +08:00
parent 7abc508067
commit 76067d3c67

View File

@ -58,10 +58,17 @@
const data = await API.getUnreadCount(); const data = await API.getUnreadCount();
const badge = document.getElementById('notification-badge'); const badge = document.getElementById('notification-badge');
const count = data.count || 0; const count = data.count || 0;
const previousCount = parseInt(badge.textContent) || 0;
if (count > 0) { if (count > 0) {
badge.textContent = count > 99 ? '99+' : count; badge.textContent = count > 99 ? '99+' : count;
badge.style.display = 'block'; badge.style.display = 'block';
// 如果有新消息且面板是打开的,自动刷新列表
if (count > previousCount && isOpen) {
console.log('[Notifications] 检测到新消息,刷新列表');
await loadNotifications();
}
} else { } else {
badge.style.display = 'none'; badge.style.display = 'none';
} }
@ -222,14 +229,14 @@
// 初始加载未读数量 // 初始加载未读数量
await updateUnreadCount(); await updateUnreadCount();
// 每30秒更新一次未读数量 // 每5秒更新一次未读数量实时检查新消息
if (notificationInterval) { if (notificationInterval) {
clearInterval(notificationInterval); clearInterval(notificationInterval);
} }
notificationInterval = setInterval(updateUnreadCount, 30000); notificationInterval = setInterval(updateUnreadCount, 5000);
isInitialized = true; isInitialized = true;
console.log('[Notifications] 初始化完成'); console.log('[Notifications] 初始化完成实时轮询已启动5秒间隔');
} catch (e) { } catch (e) {
console.error('初始化通知系统失败:', e); console.error('初始化通知系统失败:', e);
} }