Http.js 1.9 KB

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