消息模块完善

This commit is contained in:
Dev
2026-10-08 16:28:21 +08:00
parent 379d29a356
commit 107cbbe971
17 changed files with 401 additions and 28 deletions
+35
View File
@@ -25,8 +25,43 @@ App({
});
},
});
//启动未读消息轮询(tabbar红点)
this.startUnreadPolling();
},
onShow: function () {
updateManager();
//从后台切回前台,立即刷新未读红点
this.refreshUnread();
},
onHide: function () {},
globalData: {
unread: 0, //未读消息数(tabbar红点共享缓存)
},
/**
* 未读消息轮询:小程序前台每10s刷新一次底部tabbar红点
* (切后台后JS执行会被系统挂起,定时器自然暂停,回前台由onShow立即补一次)
*/
startUnreadPolling: function () {
if (this.unreadTimer) {
return;
}
this.unreadTimer = setInterval(() => {
this.refreshUnread();
}, 10000);
},
/**
* 刷新当前 tab 页 tabbar 实例的红点(非tab页无tabbar实例,自动跳过)
*/
refreshUnread: function () {
if (!wx.getStorageSync('token')) {
return;
}
const page = getCurrentPages().pop();
const tabBar = page && typeof page.getTabBar === 'function' ? page.getTabBar() : null;
if (tabBar && typeof tabBar.refreshUnread === 'function') {
tabBar.refreshUnread();
}
},
});