window.pageType = 'index'; $(function () { var options = { iniUrl: ua.url('ajax/initAdmin'), // 初始化接口 clearUrl: ua.url("ajax/clearCache"), // 缓存清理接口 urlHashLocation: true, // 是否打开hash定位 bgColorDefault: 0, // 主题默认配置(0=标准皮肤经典配色) menuChildOpen: false, // 是否默认展开菜单 loadingTime: 0, // 初始化加载时间 pageAnim: true, // iframe窗口动画 maxTabNum: 20, // 最大的tab打开数量 }; miniAdmin.render(options); $('.login-out').on("click", function () { ua.request.get({ url: 'login/out', prefix: true, }, function (res) { ua.msg.success(res.msg, function () { window.location = ua.url('login/index'); }); }); }); }); // 顶栏铃铛未读数轮询(仅框架首页执行;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); } // content_js 注入时机早于顶栏 DOM 就绪,必须等 DOM ready 再捕获 #ua-notice-unread, // 否则闭包固化空 jQuery 集合,text/show 静默 no-op,badge 永不显示 $(function () { if (window.pageType === 'index') { initUnreadPolling(); } });