mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-11-10 04:50:50 +08:00
feat(notice): 顶栏铃铛/个人入口/未读数轮询
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user