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 showLoading(message) {
wx.showLoading({
title: message,
mask: true,
})
}
function hideLoading() {
wx.hideLoading({
success: (res) => {},
})
}
function showToast(message) {
wx.showToast({
title: message,
icon: 'none',
duration: 3000
});
}
function successToast(message) {
wx.showToast({
title: message,
icon: 'none',
duration: 1000
});
setTimeout(function(){
wx.navigateBack(1)
},2000)
}
function showModal(title, message) {
wx.showModal({
title: title,
content: message,
showCancel: false,
success(res) {
if (res.confirm) {
console.log('用户点击确定')
}
}
})
}
module.exports = {
formatTime,
showLoading,
hideLoading,
showToast,
showModal,
successToast
}
封装小程序 弹窗方法
最新推荐文章于 2024-04-08 18:00:21 发布