dengjunjie
5 天以前 4f39dcc195f28fa275fc2d065fbf1bf6a46c21b7
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
40
41
42
43
44
/**
 * 更新自定义顶部导航栏的高度
 */
function updateCustomBarInfo () {
  return new Promise((resolve, reject) => {
    uni.getSystemInfo({
      success: (e) => {
        let statusBarHeight = 0
        let customBarHeight = 0
        // #ifndef MP
        statusBarHeight = e.statusBarHeight
        if (e.platform == 'android') {
          customBarHeight = e.statusBarHeight + 50
        } else {
          customBarHeight = e.statusBarHeight + 45
        };
        // #endif
 
        // #ifdef MP-WEIXIN
        statusBarHeight = e.statusBarHeight
        let custom = wx.getMenuButtonBoundingClientRect()
        customBarHeight = custom.bottom + ((custom.top - e.statusBarHeight) <= 4 ? (custom.top - e
          .statusBarHeight) + 4 : (custom.top - e.statusBarHeight))
        // #endif        
 
        // #ifdef MP-ALIPAY
        statusBarHeight = e.statusBarHeight
        customBarHeight = e.statusBarHeight + e.titleBarHeight
        // #endif
        resolve({
          statusBarHeight,
          customBarHeight
        })
      },
      fail: (err) => {
        console.log("获取设备信息失败", err);
        reject()
      }
    })
 
  })
}
 
export default updateCustomBarInfo