mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-11-04 19:38:21 +08:00
feat(notice): 顶栏铃铛/个人入口/未读数轮询
This commit is contained in:
@@ -54,6 +54,14 @@
|
||||
<a href="javascript:;" layuimini-content-href="{:__url('index/editPassword')}" data-title="修改密码"
|
||||
data-icon="fa fa-gears">修改密码</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="javascript:;" layuimini-content-href="{:__url('notice/mine')}" data-title="我的消息"
|
||||
data-icon="fa fa-bell">我的消息</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<a href="javascript:;" layuimini-content-href="{:__url('notice/subscribe')}" data-title="通知设置"
|
||||
data-icon="fa fa-cog">通知设置</a>
|
||||
</dd>
|
||||
<dd>
|
||||
<hr>
|
||||
</dd>
|
||||
@@ -62,6 +70,9 @@
|
||||
</dd>
|
||||
</dl>
|
||||
</li>
|
||||
<li class="layui-nav-item" lay-unselect>
|
||||
<a href="javascript:;" id="ua-notice-bell" layuimini-content-href="{:__url('notice/mine')}" data-title="我的消息"><i class="fa fa-bell"></i><span class="layui-badge" id="ua-notice-unread" style="display:none;"></span></a>
|
||||
</li>
|
||||
<li class="layui-nav-item layuimini-select-bgcolor" lay-unselect>
|
||||
<a href="javascript:;" data-bgcolor="配色方案"><i class="fa fa-ellipsis-v"></i></a>
|
||||
</li>
|
||||
|
||||
@@ -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