Http.js 1.2 KB

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