封装小程序 弹窗方法

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
}

你可能感兴趣的:(小程序,小程序,javascript,前端)