消息提醒优化
This commit is contained in:
parent
7abc508067
commit
76067d3c67
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user