jiuyiUniapp/service/components/public/Mixins.js

46 lines
1.2 KiB
JavaScript

// 状态栏高度
export const statusBarHeight = (isUnit) => {
let h = uni.getSystemInfoSync().statusBarHeight
h = h ? h : 0
return isUnit ? h : `${h}px`
}
// 底部安全区域高度
export const bottomSafeAreaHeight = (isUnit) => {
let b = uni.getSystemInfoSync().safeAreaInsets.bottom
b = b ? b : 0
return isUnit ? b : `${b}px`
}
// 获取屏幕宽
export const screenWidth = (isUnit) => {
let w = uni.getSystemInfoSync().screenWidth
w = w ? w : 0
return isUnit ? w : `${w}px`
}
// 顶部导航栏的高度
export const windowTop = (isUnit) => {
let h = uni.getSystemInfoSync().windowTop
h = h ? h : 0
return isUnit ? h : `${h}px`
}
// 获取屏幕高 x 小数
export const screenHeight = (isUnit) => {
let h = uni.getSystemInfoSync().screenHeight
h = h ? h : 0
return isUnit ? h : `${h}px`
}
// 判断是否有上一页 返回上一页 否则跳转首页
export const goBack = (url) => {
// 获取当前页面栈
const pages = getCurrentPages();
// 判断是否存在上一页
if (pages.length > 1) {
return uni.navigateBack({
delta: 1
})
} else {
return uni.reLaunch({
url: url
})
}
}