Http.js 1.8 KB

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