76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
![]() |
import useUserStore from "../stores/useUserStore";
|
|||
|
|
|||
|
const msg = (title, duration = 1500, mask = false, icon = 'none', image) => {
|
|||
|
if (Boolean(title) === false) {
|
|||
|
return;
|
|||
|
}
|
|||
|
uni.showToast({
|
|||
|
title,
|
|||
|
duration,
|
|||
|
mask,
|
|||
|
icon,
|
|||
|
image
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
const prePage = () => {
|
|||
|
let pages = getCurrentPages();
|
|||
|
let prePage = pages[pages.length - 2];
|
|||
|
return prePage.$vm;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
const navTo = function(url, needLogin) {
|
|||
|
if (needLogin && useUserStore().hasLogin) {
|
|||
|
uni.navigateTo({
|
|||
|
url: '/pages/login/login'
|
|||
|
});
|
|||
|
return
|
|||
|
}
|
|||
|
uni.navigateTo({
|
|||
|
url
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
function getdeviceInfo() {
|
|||
|
const globalData = {
|
|||
|
statusBarHeight: 0, // 状态导航栏高度
|
|||
|
topHeight: 0, // 距离顶部高度
|
|||
|
navHeight: 0, // 总体高度
|
|||
|
windowHeight: 0, // 可使用窗口高度
|
|||
|
tabBarHight: 0, //底部导航栏高度
|
|||
|
};
|
|||
|
let systemInfo = uni.getSystemInfoSync()
|
|||
|
globalData.windowHeight = systemInfo.screenHeight
|
|||
|
// 底部导航栏
|
|||
|
globalData.tabBarHight = systemInfo.screenHeight - systemInfo.safeArea.bottom
|
|||
|
// 状态栏高度
|
|||
|
globalData.statusBarHeight = systemInfo.statusBarHeight
|
|||
|
// #ifdef MP-MP-WEIXIN
|
|||
|
let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
|
|||
|
// 胶囊距离顶部高度
|
|||
|
globalData.topHeight = menuButtonInfo.top
|
|||
|
// 胶囊高度
|
|||
|
globalData.navHeight = menuButtonInfo.height
|
|||
|
// #endif
|
|||
|
return {
|
|||
|
...globalData
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
function sleep(time) {
|
|||
|
return new Promise((resolve) => setTimeout(resolve, time))
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
export default {
|
|||
|
'$api': {
|
|||
|
msg,
|
|||
|
prePage,
|
|||
|
sleep
|
|||
|
},
|
|||
|
navTo,
|
|||
|
getdeviceInfo
|
|||
|
}
|