util.js 912 B

1234567891011121314151617181920212223242526272829303132333435363738
  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. function http(url, option) {
  15. const baseURL = "http://192.168.31.28:8084";//后台服务提供的地址
  16. return new Promise ((resolve, reject) => {
  17. wx.request({
  18. url: baseURL + url,
  19. ...option,
  20. success(res) {
  21. console.log(res);
  22. resolve(res.data);
  23. },
  24. fail(err) {
  25. console.log(err);
  26. reject(err);
  27. }
  28. })
  29. })
  30. }
  31. module.exports = {
  32. formatTime,
  33. http
  34. }