request.js 1.3 KB

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