request.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* wx.request */
  2. const BASE_API = 'http://itt.chl6zk.store/api'
  3. export const wxRequest = (url,data) => {
  4. return new Promise((resolve, reject) => {
  5. wx.showLoading({
  6. title: '加载中...',
  7. mask: true
  8. })
  9. wx.request({
  10. url: BASE_API + url,
  11. data: data,
  12. method: 'POST',
  13. success (response) {
  14. if (response.statusCode !== 200) {
  15. wx.showToast({
  16. title: response.errMsg || '网络错误!',
  17. icon: 'error',
  18. duration: 2500,
  19. mask: true
  20. })
  21. } else {
  22. if (response.data.code !== '100') {
  23. wx.showToast({
  24. title: response.data.msg || '请求错误!',
  25. icon: 'error',
  26. duration: 2500,
  27. mask: true
  28. })
  29. } else {
  30. resolve(response.data)
  31. }
  32. }
  33. },
  34. fail (e) {
  35. wx.showToast({
  36. title: '请求错误!',
  37. icon: 'error',
  38. duration: 2500,
  39. mask: true
  40. })
  41. reject(e)
  42. },
  43. complete () {
  44. wx.hideLoading()
  45. }
  46. })
  47. })
  48. }