Http.js 1.7 KB

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