Http.js 1.6 KB

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