Http.js 1.7 KB

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