| | |
| | | return null; |
| | | }; |
| | | |
| | | // tabbar 角标:异步返回时可能已切到非 tabBar 页面,失败静默忽略 |
| | | const callTabBarApi = (api, options) => { |
| | | try { |
| | | const ret = uni[api](options); |
| | | if (ret && typeof ret.catch === "function") ret.catch(() => {}); |
| | | } catch (e) { |
| | | /* 非 tabBar 页面,忽略 */ |
| | | } |
| | | }; |
| | | |
| | | // 更新 tab 栏角标 |
| | | const updateTabBarBadge = () => { |
| | | if (userId.value) { |
| | |
| | | const count = res.data || 0; |
| | | // 更新tabbar的角标 |
| | | if (count > 0) { |
| | | uni.setTabBarBadge({ |
| | | callTabBarApi("setTabBarBadge", { |
| | | index: 2, // 消息标签页的索引 |
| | | text: count.toString(), |
| | | }); |
| | | } else { |
| | | uni.removeTabBarBadge({ |
| | | callTabBarApi("removeTabBarBadge", { |
| | | index: 2, |
| | | }); |
| | | } |