Http.js 2.1 KB

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