request.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. //设置域名
  2. const dev_baseUrl = "http://192.168.8.21:14300/temporary-library"; //测试
  3. const pro_baseUrl = "https://tx.hz-hanghui.com:8088/temporary-library"; //正式
  4. const pro_bassurl2 = 'https://ldb-permit.hz-hanghui.com:8088/hanghui/outapi/alipay'
  5. //是否是正式环境
  6. const wx_rlxf = true;
  7. const baseUrl = wx_rlxf ? pro_baseUrl : dev_baseUrl; //https请求
  8. const url1 = (e) => wx_rlxf ? pro_baseUrl + e.url : dev_baseUrl + e.url
  9. const url2 = (e) => wx_rlxf ? pro_bassurl2 + e.url : pro_bassurl2 + e.url
  10. // https请求
  11. const request = e => {
  12. const userInfo = my.getStorageSync({ key: "userInfo" });
  13. let url = ''
  14. switch (e.extra) {
  15. case 1:
  16. url = url1(e)
  17. break;
  18. case 2:
  19. url = url2(e)
  20. break;
  21. case 3:
  22. url = e.url
  23. break;
  24. default:
  25. break;
  26. }
  27. return new Promise(function (resolve, reject) {
  28. my.request({
  29. url: url,
  30. data: e.data,
  31. method: e.method,
  32. header: {
  33. "content-type": e.type,
  34. "Authorization": e.extra === 1 && userInfo.data ? userInfo.data.token : ""
  35. },
  36. success: res => {
  37. if (res.data.code == 200) {
  38. resolve(res.data);
  39. } else {
  40. my.hideLoading();
  41. my.showToast({
  42. type: 'none',
  43. content: res.data.msg,
  44. duration: 3000
  45. });
  46. // reject(res.data);
  47. }
  48. },
  49. fail: error => {
  50. my.hideLoading();
  51. my.showToast({
  52. content: error.errorMessage,
  53. duration: 3000,
  54. });
  55. // reject(error.errMsg);
  56. }
  57. });
  58. });
  59. };
  60. module.exports = {
  61. wx_rlxf: wx_rlxf,
  62. baseUrl,
  63. dev_baseUrl: dev_baseUrl,
  64. pro_baseUrl: pro_baseUrl,
  65. request: request
  66. };