WXHttpRequest.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. module.exports = {
  2. getInstance: function() {
  3. // wx.showToast({
  4. // title: '加载中...',
  5. // icon: 'loading',
  6. // duration: 600
  7. // })
  8. return {
  9. _sucCallback: null,
  10. _failCallback: null,
  11. _method: 'GET',
  12. _data: {},
  13. _header: { 'content-type': 'application/json' },
  14. _url: '',
  15. send: function() {
  16. wx.request({
  17. url: this._url,
  18. data: this._data,
  19. method: this._method,
  20. header: this._header,
  21. success: function(res) {
  22. this._sucCallback ? this._sucCallback(res) : null;
  23. }.bind(this),
  24. fail: function(res) {
  25. this._failCallback(res);
  26. }.bind(this)
  27. });
  28. return this;
  29. },
  30. success: function(callback) {
  31. this._sucCallback = callback;
  32. // setTimeout(function () {
  33. // wx.hideLoading()
  34. // }, 200)
  35. return this;
  36. },
  37. fail: function(callback) {
  38. this._failCallback = callback;
  39. // setTimeout(function () {
  40. // wx.hideLoading()
  41. // }, 200)
  42. return this;
  43. },
  44. url: function(url) {
  45. this._url = url;
  46. return this;
  47. },
  48. data: function(data) {
  49. this._data = data;
  50. return this;
  51. },
  52. header: function(header) {
  53. this._header = header;
  54. return this;
  55. },
  56. method: function(method) {
  57. this._method = method;
  58. return this;
  59. }
  60. };
  61. }
  62. };