Http.js 1.8 KB

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