request.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. const _my = require("../../__antmove/api/index.js")(my);
  2. const wx = _my;
  3. //设置域名
  4. const dev_baseUrl_wxrlxf = "http://192.168.11.3:9100/yx-fyzd"; //测试
  5. const pro_baseUrl_wxrlxf = "https://tx.hz-hanghui.com:8088/yx-fyzd"; //正式
  6. //是否是正式环境
  7. const wx_rlxf = true;
  8. const baseUrl = wx_rlxf ? pro_baseUrl_wxrlxf : dev_baseUrl_wxrlxf;
  9. //https请求
  10. const request_wxrlxf = e => {
  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.11.11:9100"; //测试
  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 showToast = title => {
  64. wx.showToast({
  65. title: title,
  66. icon: "none",
  67. duration: 3000
  68. });
  69. };
  70. const showModal = (
  71. { text, title = "提示", showCancel = false } = {},
  72. successCallback = function() {}
  73. ) => {
  74. return wx.showModal({
  75. title: title,
  76. content: text,
  77. showCancel: showCancel,
  78. success: res => {
  79. if (res.confirm) {
  80. successCallback();
  81. } else if (res.cancel) {
  82. console.log("用户点击取消");
  83. }
  84. }
  85. });
  86. };
  87. // 等待
  88. const showLoading = title => {
  89. wx.showLoading({
  90. title: title
  91. });
  92. };
  93. module.exports = {
  94. wx_rlxf: wx_rlxf,
  95. baseUrl,
  96. dev_baseUrl_wxrlxf: dev_baseUrl_wxrlxf,
  97. pro_baseUrl_wxrlxf: pro_baseUrl_wxrlxf,
  98. request_wxrlxf: request_wxrlxf,
  99. env: env,
  100. dev_baseUrl: dev_baseUrl,
  101. pro_baseUrl: pro_baseUrl,
  102. request: request,
  103. showToast,
  104. showModal,
  105. showLoading
  106. };