mp.js
2.23 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
export default {
data() {
return {
windowInfo: getWindowInfo(),
}
},
computed: {
/**
* 小程序和H5的标题
*/
navbarStyle() {
let windowInfo = getWindowInfo();
return {
statusBarHeightPx: windowInfo.system.statusBarHeight + 'px',
navbarHeightPx: windowInfo.navbar.bodyHeightPx + 'px',
}
},
},
methods: {
back() {
uni.navigateBack()
}
}
}
/**
* 获取当前窗口数据
*
*/
function getWindowInfo() {
let systemInfo = uni.getSystemInfoSync();
systemInfo.pixelRatio = Math.round(systemInfo.pixelRatio * 100) / 100;
let windowInfo = {
system: systemInfo,
capsule: {
bottom: 78,
height: 30,
left: 283,
right: 363,
top: 48,
width: 0,
},
navbar: {
heightPx: uni.upx2px(100) + systemInfo.statusBarHeight,
bodyHeightPx: uni.upx2px(100),
bodyWidthPx: systemInfo.windowWidth,
capsuleWidthPx: 0,
capsuleRightPx: 0,
},
height: systemInfo.windowHeight * (750 / systemInfo.windowWidth),
width: 750,
statusBarHeight: systemInfo.statusBarHeight * (750 / systemInfo.windowWidth),
safeBottom: systemInfo.windowHeight - systemInfo.safeArea.bottom,
safeBottomRpx: (systemInfo.windowHeight - systemInfo.safeArea.bottom) * (750 / systemInfo.windowWidth),
/**
* 原生端 底部导航栏高度
*/
footNavbarHeight: uni.upx2px(100) + (systemInfo.windowHeight - systemInfo.safeArea.bottom),
}
// #ifdef MP-QQ || MP-WEIXIN
let capsuleInfo = uni.getMenuButtonBoundingClientRect();
windowInfo.capsule = capsuleInfo;
let capsuleToStatusBarPx = capsuleInfo.top - systemInfo.statusBarHeight; //胶囊和状态栏之间的高度
windowInfo.navbar.bodyHeightPx = capsuleInfo.height + (capsuleToStatusBarPx * 2);
windowInfo.navbar.heightPx = windowInfo.navbar.bodyHeightPx + systemInfo.statusBarHeight;
let capsuleWidthPx = (systemInfo.windowWidth - capsuleInfo.right) * 2 + capsuleInfo.width;
windowInfo.navbar.bodyWidthPx = systemInfo.windowWidth - capsuleWidthPx;
windowInfo.navbar.capsuleWidthPx = capsuleWidthPx;
windowInfo.navbar.capsuleRightPx = capsuleWidthPx - (systemInfo.windowWidth - capsuleInfo.right);
// #endif
return windowInfo;
}