request.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //设置域名
  2. const dev_baseUrl = 'http://192.168.77.47:14001/ma-meeting'; //测试
  3. const pro_baseUrl = 'https://common.hz-hanghui.com:8087/ma-meeting'; //正式
  4. //是否是正式环境
  5. const wx_rlxf = true
  6. const baseUrl = wx_rlxf ? pro_baseUrl : dev_baseUrl;
  7. //https请求
  8. const request = e => {
  9. let userInfo = wx.getStorageSync('userInfo');
  10. return new Promise(function (resolve, reject) {
  11. wx.request({
  12. url: wx_rlxf ? (pro_baseUrl + e.url) : (dev_baseUrl + e.url),
  13. data: e.data,
  14. method: e.method,
  15. header: {
  16. 'content-type': e.type,
  17. 'Authorization': userInfo ? userInfo.token : null,
  18. },
  19. success: res => {
  20. if (res.data.code == 200) {
  21. resolve(res.data)
  22. } else if (res.data.code == 401) {
  23. wx.removeStorageSync('userInfo')
  24. } else {
  25. wx.showToast({
  26. icon: 'none',
  27. title: res.data.msg,
  28. })
  29. };
  30. },
  31. fail: error => {
  32. wx.hideLoading()
  33. }
  34. })
  35. })
  36. }
  37. module.exports = {
  38. wx_rlxf: wx_rlxf,
  39. baseUrl,
  40. dev_baseUrl: dev_baseUrl,
  41. pro_baseUrl: pro_baseUrl,
  42. request: request,
  43. }