Http.js 2.4 KB

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