feat(notice): 顶栏铃铛/个人入口/未读数轮询

This commit is contained in:
augushong
2026-10-12 12:41:03 +00:00
parent cc1459383f
commit b91a8c0907
2 changed files with 45 additions and 1 deletions

View File

@@ -22,4 +22,37 @@ $(function () {
});
});
});
});
});
// 顶栏铃铛未读数轮询(仅框架首页执行;60s 轮询一次;接口失败静默,badge 维持现状;无退避,页面关闭即停)
function initUnreadPolling() {
var unreadCountUrl = ua.url('notice/unreadCount');
var pollInterval = 60000;
var $badge = $('#ua-notice-unread');
function renderBadge(count) {
count = parseInt(count, 10) || 0;
if (count <= 0) {
$badge.text('').hide();
} else {
$badge.text(count > 99 ? '99+' : count).show();
}
}
function fetchUnreadCount() {
$.getJSON(unreadCountUrl).done(function (res) {
if (res && res.code === 0 && res.data) {
renderBadge(res.data.count);
}
}).fail(function () {
// 静默失败,不做任何处理
});
}
fetchUnreadCount();
setInterval(fetchUnreadCount, pollInterval);
}
if (window.pageType === 'index') {
initUnreadPolling();
}