shuziren/job-seeker/miniprogram-2/utils/util.js

76 lines
2.3 KiB
JavaScript

const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : `0${n}`
}
function rem(height, successData) {
//获取设备信息
wx.getSystemInfo({
success: (res) => {
//判断是否传入高度
if (height != null && height != undefined && height != '') {
//如果传入高度则用设备的高度减去设备宽度除以设计图的宽度750再乘以传参进来的高度
var myheight = res.windowHeight - res.windowWidth / 750 * height
} else {
//如果没有传入高度则直接等于设备高度
var myheight = res.windowHeight
}
myheight = myheight
//调用成功函数并把算出来的高度传出去
successData(myheight)
},
fail: function (res) {},
complete: function (res) {},
})
}
function isObjectEmpty(obj) {
for (let key in obj) {
if (obj.hasOwnProperty(key) && key !== "performance" && key !== "startTime" && key !== "endTime" && (obj[key] === null || obj[key] === undefined || obj[key] === "")) {
return false; // 如果发现除了 performance、startTime 和 endTime 以外的属性为空,返回 false
}
}
return true; // 如果所有属性都为空或只有 performance、startTime 和 endTime 不为空,返回 true
}
const showLoading = (tips = '加载中...') => {
wx.showNavigationBarLoading()
wx.showLoading({
title: tips,
})
}
const hideLoading = () => {
wx.hideLoading()
wx.hideNavigationBarLoading()
}
const hideLoadingWithErrorTips = (err = '加载失败...') => {
hideLoading()
wx.showToast({
title: err,
icon: 'error',
duration: 2000
})
}
module.exports = {
formatTime,
rem,
isObjectEmpty: isObjectEmpty,
showLoading: showLoading,
hideLoading: hideLoading,
hideLoadingWithErrorTips: hideLoadingWithErrorTips
}