request.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. const api_url = 'https://sqtg.hdlkeji.com' //社区团购
  2. var requestHandler = {
  3. url: "",
  4. params: {},
  5. success: function(res) {
  6. },
  7. fail: function() {
  8. }
  9. }
  10. //GET
  11. function GET(requestHandler) {
  12. request('GET', requestHandler)
  13. }
  14. //POST
  15. function POST(requestHandler) {
  16. request_post('POST', requestHandler)
  17. }
  18. function request(method, requestHandler) {
  19. var params = requestHandler.params;
  20. var url = requestHandler.url;
  21. wx.request({
  22. url: api_url + url,
  23. data: params,
  24. method: method,
  25. header: {
  26. 'Content-Type': 'application/json' // 默认值
  27. },
  28. success: function(res) {
  29. requestHandler.success(res)
  30. },
  31. fail: function() {
  32. requestHandler.fail();
  33. }
  34. })
  35. }
  36. function request_post(method, requestHandler) {
  37. var params = requestHandler.params;
  38. var url = requestHandler.url
  39. var distanceType = requestHandler.distance;
  40. wx.showLoading({
  41. title: '加载中',
  42. mask: true
  43. })
  44. wx.request({
  45. url: api_url + url,
  46. data: params,
  47. method: method,
  48. header: {
  49. 'content-type': 'application/x-www-form-urlencoded'
  50. },
  51. success: function (res) {
  52. wx.hideLoading();
  53. requestHandler.success(res)
  54. },
  55. fail: function() {
  56. requestHandler.fail();
  57. }
  58. })
  59. }
  60. module.exports = {
  61. GET: GET,
  62. POST: POST,
  63. drawTextVertical: drawTextVertical
  64. }