Http.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // const baseUrl = "https://meida.cnyunl.com/yos/rest/index";
  2. const baseUrl = "http://61.164.207.46:8000/yos/rest/index";
  3. class HTTP {
  4. request({
  5. url,
  6. data = {},
  7. method = "POST",
  8. header = {
  9. 'content-type': 'application/json'
  10. },
  11. showLoading = '加载中...'
  12. }) {
  13. return new Promise((resolve, reject) => {
  14. this._request(url, resolve, reject, data, method, header, showLoading);
  15. })
  16. }
  17. _request(url, resolve, reject, data, method, header, showLoading) {
  18. if (showLoading) wx.showLoading({
  19. title: showLoading,
  20. mask: true
  21. })
  22. wx.request({
  23. url: baseUrl + url,
  24. data: data,
  25. method: method,
  26. header: header,
  27. timeout: 60000,
  28. success: (res) => {
  29. resolve(res.data);
  30. },
  31. fial: (err) => {
  32. reject(err);
  33. },
  34. complete: (res) => {
  35. if (showLoading) wx.hideLoading()
  36. if (res.errMsg != 'request:ok') {
  37. wx.showToast({
  38. title: '网络异常,请重新进入',
  39. icon: "none"
  40. })
  41. } else if (res.data.msg == '登陆状态已过期,请重新登陆!') {
  42. wx.redirectTo({
  43. url: '/pages/login/phone',
  44. });
  45. wx.showToast({
  46. title: res.msg,
  47. icon: "none"
  48. })
  49. }
  50. }
  51. })
  52. }
  53. }
  54. export {
  55. HTTP
  56. }