Files
ks-app-employment-service/common/globalFunction.js
2024-11-08 11:55:23 +08:00

76 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}