Http.js 2.0 KB

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