util.js 911 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. const formatTime = date => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
  9. }
  10. const formatNumber = n => {
  11. n = n.toString()
  12. return n[1] ? n : '0' + n
  13. }
  14. // 显示繁忙提示
  15. var showBusy = text => wx.showToast({
  16. title: text,
  17. icon: 'loading',
  18. duration: 5000
  19. })
  20. // 显示成功提示
  21. var showSuccess = text => wx.showToast({
  22. title: text,
  23. icon: 'success'
  24. })
  25. // 显示失败提示
  26. var showModel = (title, content) => {
  27. wx.hideToast();
  28. wx.showModal({
  29. title,
  30. content: JSON.stringify(content),
  31. showCancel: false
  32. })
  33. }
  34. module.exports = { formatTime, showBusy, showSuccess, showModel }