request.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. //设置域名
  2. const dev_baseUrl = 'http://192.168.11.17:8800/hanghui-warehouse'; //测试
  3. const pro_baseUrl = 'https://noise.hz-hanghui.com:8088/hanghui-warehouse'; //正式
  4. //是否是正式环境
  5. const wx_rlxf = true
  6. const baseUrl = wx_rlxf ? pro_baseUrl : dev_baseUrl;
  7. // https请求
  8. const request = e => {
  9. let token = uni.getStorageSync('token');
  10. return new Promise((resolve, reject) => {
  11. uni.request({
  12. url: wx_rlxf ? (pro_baseUrl + e.url) : (dev_baseUrl + e.url),
  13. method: e.method,
  14. data: e.data,
  15. header: {
  16. 'Content-Type': e.type,
  17. 'Authorization': token ? token : null,
  18. },
  19. success: res => {
  20. if (res.data.code == 200) {
  21. resolve(res.data)
  22. uni.hideLoading(); //关闭loading
  23. } else {
  24. wx.showToast({
  25. icon: 'none',
  26. title: res.data.msg,
  27. })
  28. reject(res.data)
  29. uni.hideLoading(); //关闭loading
  30. };
  31. },
  32. fail: error => {
  33. reject(error);
  34. uni.hideLoading(); //关闭loading
  35. },
  36. complete: () => {
  37. uni.hideLoading(); //关闭loading
  38. }
  39. })
  40. })
  41. }
  42. export default request;