Http.js 1.9 KB

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