navigationBar.js
3.62 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// components/navigationBar/navigationBar.js
import util from '../../utils/util'
const app = getApp()
Component({
options: {
styleIsolation: 'shared'
},
/**
* 组件的属性列表
*/
properties: {
navStyle: String,
showBack: Boolean,
showMenu: Boolean,
showWhiteMenu: Boolean
},
/**
* 组件的初始数据
*/
data: {
// navigationBarHeight: 70
// // 状态栏高度
// statusBarHeight: app.globalData.statusBarHeight,
// // 导航栏高度
// navigationBarHeight: app.globalData.navigationBarHeight,
// navigationBarStyle: 'font-size: var(--fontSize34)',
// // navigationBarTextWidth: `width:${app.globalData.navigationBarWidth / 2}rpx;padding:0 ${app.globalData.navigationBarPadding / 2}rpx; 0 ${app.globalData.navigationBarPadding / 2}rpx;`
// navigationBarTextWidth: `width:${app.globalData.navigationBarWidth / 2}rpx;padding:${app.globalData.navigationBarPadding / 2}rpx;`
},
/**
* 组件的方法列表
*/
methods: {
back() {
this.triggerEvent('back')
},
showMenuPopup() {
this.triggerEvent('showMenuPopup')
},
init() {
/**
* 获取自定义导航栏信息
*/
let _this = this
// 获取屏幕宽度和高度
const { windowWidth, windowHeight } = wx.getSystemInfoSync()
// 判断屏幕方向
const isLandscape = windowWidth > windowHeight // '横屏' : '竖屏'
wx.getSystemInfo({
success(res) {
let {
fontSizeSetting,
statusBarHeight,
screenWidth,
pixelRatio,
safeArea,
platform
} = res
console.log(safeArea, 'safeArea')
const { height, right, width, top } =
wx.getMenuButtonBoundingClientRect()
// 判断是否是华为平板设备
// && pixelRatio >= 2
let isPad = screenWidth >= 600
statusBarHeight = platform == 'ios' ? safeArea.top : statusBarHeight
if (isLandscape) statusBarHeight = 0
// console.log(isPad, screenWidth, 'screenWidth');
// let navigationBarHeight = height + (top - statusBarHeight) * 2 + 5
let navigationBarHeight = `var(--fontSize${
(height + (top - statusBarHeight) * 2) * (isPad ? 1 : 2)
})`
let navigationBarPadding = screenWidth - right
let navigationBarWidth =
screenWidth - (navigationBarPadding * 2 + width) - width
// if(deviceOrientation == 'landscape') statusBarHeight = 0
_this.setData({
statusBarHeight: `var(--fontSize${
statusBarHeight * (isPad ? 1 : 2)
})`,
navigationBarHeight,
// navigationBarStyle: `font-size:${fontSizeSetting}px;`,
navigationBarStyle: 'font-size: var(--fontSize34)',
navigationBarTextWidth: `width:${navigationBarWidth}px;padding:0 ${navigationBarPadding}px; 0 ${navigationBarPadding}px;`
})
},
complete() {
// console.log('#navigation-bar');
// setTimeout(() => {
util.getViewInfo(
'#navigation-bar',
res => {
// console.log(res, '#navigation-bar');
_this.triggerEvent('navbarReady', res)
_this.setData({
showNavBar: true
})
},
_this
)
// }, 0)
}
})
}
},
pageLifetimes: {
resize(res) {
// console.log(res, 'res');
// this.setData({
// statusBarHeight: 0
// })
// else
this.init()
}
},
ready() {
this.init()
}
})