request.js 2.1 KB

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