liujie
23 小时以前 384bce80449b17651937429038c4370dbce60e7b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<script>
// 个人中心 tab 在 pages.json → tabBar.list 中的索引(0 起)
const PROFILE_TAB_INDEX = 3
// TODO: 后端「个人中心待处理/未读数量」接口就绪后替换为真实请求
const MOCK_PROFILE_BADGE_COUNT = 1
 
export default {
    onLaunch: function() {
        console.log('App Launch')
    },
    onShow: function() {
        console.log('App Show')
        this._syncTabBarBadge()
    },
    onHide: function() {
        console.log('App Hide')
    },
    methods: {
        // 同步个人中心 tab 原生角标(原生 tabBar 无法用 CSS 实现角标)
        _syncTabBarBadge() {
            if (MOCK_PROFILE_BADGE_COUNT > 0) {
                uni.setTabBarBadge({
                    index: PROFILE_TAB_INDEX,
                    text: String(MOCK_PROFILE_BADGE_COUNT),
                    fail: (err) => {
                        console.error('[TABBAR_BADGE] set failed', err)
                    }
                })
            } else {
                uni.removeTabBarBadge({ index: PROFILE_TAB_INDEX })
            }
        }
    }
}
</script>
 
<style>
    /*每个页面公共css */
</style>