EP-WachatApp/eaterplanet_ecommerce/components/skeleton/getSystemInfo.js

35 lines
848 B
JavaScript
Raw Normal View History

2023-03-24 11:24:28 +08:00
/**
* 获取系统信息
*/
class SystemInfo {
static fetchAllInfo() {
const menuButton = wx.getMenuButtonBoundingClientRect()
const systemInfo = wx.getSystemInfoSync()
const statusBarHeight = systemInfo.statusBarHeight
const headerHeight = (menuButton.top - systemInfo.statusBarHeight) * 2 + menuButton.height
let data = {
source: {
menu: menuButton,
system: systemInfo
},
statusBarHeight: statusBarHeight,
headerHeight: headerHeight,
headerRight: systemInfo.windowWidth - menuButton.left
}
wx.setStorageSync('SystemInfo', data)
return data
}
static getInfo() {
let storageInfoSync = wx.getStorageSync('SystemInfo')
if (!storageInfoSync) {
storageInfoSync = this.fetchAllInfo()
}
return storageInfoSync
}
}
export default SystemInfo