request.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. //是否是正式环境
  4. const wx_rlxf = true;
  5. //设置域名
  6. const dev_baseUrl_wxrlxf = "http://192.168.11.11:8081/yx-fyzd"; //测试
  7. const pro_baseUrl_wxrlxf = "https://tx.hz-hanghui.com:8088/yx-fyzd"; //正式
  8. const baseUrl = wx_rlxf ? pro_baseUrl_wxrlxf : dev_baseUrl_wxrlxf;
  9. //https请求
  10. const request_wxrlxf = e => {0
  11. return new Promise(function(resolve, reject) {
  12. wx.request({
  13. url: e.url.startsWith('http') ? e.url : (wx_rlxf
  14. ? pro_baseUrl_wxrlxf + e.url
  15. : dev_baseUrl_wxrlxf + e.url),
  16. data: e.data,
  17. method: e.method,
  18. header: {
  19. "content-type": e.type
  20. },
  21. success: res => {
  22. if (res.statusCode == 200) {
  23. resolve(res.data);
  24. } else {
  25. reject(res.data);
  26. }
  27. },
  28. fail: error => {
  29. reject(error.errMsg);
  30. }
  31. });
  32. });
  33. };
  34. //是否是正式环境
  35. const env = true;
  36. //设置域名
  37. const dev_baseUrl = "http://192.168.18.117:8088"; //测试
  38. const pro_baseUrl = "https://renhe.hz-hanghui.com"; //正式
  39. //https请求
  40. const request = e => {
  41. return new Promise(function(resolve, reject) {
  42. wx.request({
  43. url: e.url.startsWith('http') ? e.url : (env ? pro_baseUrl + e.url : dev_baseUrl + e.url),
  44. data: e.data,
  45. method: e.method,
  46. header: {
  47. "content-type": e.type
  48. },
  49. success: res => {
  50. if (res.statusCode == 200) {
  51. resolve(res.data);
  52. } else {
  53. reject(res.data);
  54. }
  55. },
  56. fail: error => {
  57. reject(error.errMsg);
  58. }
  59. });
  60. });
  61. };
  62. //判断输入是否为空
  63. const matchNull = e => {
  64. return e ? e : false;
  65. };
  66. module.exports = {
  67. wx_rlxf: wx_rlxf,
  68. dev_baseUrl_wxrlxf: dev_baseUrl_wxrlxf,
  69. pro_baseUrl_wxrlxf: pro_baseUrl_wxrlxf,
  70. request_wxrlxf: request_wxrlxf,
  71. env: env,
  72. dev_baseUrl: dev_baseUrl,
  73. pro_baseUrl: pro_baseUrl,
  74. request: request,
  75. baseUrl: baseUrl
  76. };