Skip to content

Commit d9c6500

Browse files
committed
update: get message count when initalize application
1 parent 443b3de commit d9c6500

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/app.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,31 @@ App({
99
this.fnInitMoment();
1010
this.fnNetVerifyAccessToken();
1111
},
12+
// 获取未读消息数量
13+
fnNetGetUnreadMessageCount() {
14+
// 显示标题栏加载效果
15+
wx.showNavigationBarLoading();
16+
wx.dc.message
17+
.count()
18+
.then(res => {
19+
if (res && res.data) {
20+
wx.setTabBarBadge({
21+
index: 1,
22+
text: `${res.data}`
23+
});
24+
}
25+
wx.hideNavigationBarLoading();
26+
})
27+
.catch(err => {
28+
wx.hideNavigationBarLoading();
29+
});
30+
},
1231
// 验证access token有效性
1332
fnNetVerifyAccessToken() {
33+
// sAccessToken不存在时,终止执行
34+
if (!wx.getStorageSync('sAccessToken')) {
35+
return;
36+
}
1437
// 显示标题栏加载效果
1538
wx.showNavigationBarLoading();
1639
wx.dc.user
@@ -21,6 +44,8 @@ App({
2144
}
2245
// access token有效,更新用户登录状态
2346
this.globalData.bIsLogin = true;
47+
// 获取用户未读消息数量
48+
this.fnNetGetUnreadMessageCount();
2449
wx.hideNavigationBarLoading();
2550
})
2651
.catch(err => {

0 commit comments

Comments
 (0)