api.js 893 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. const app = getApp();
  2. let request = (_url, _method, _data, callback, failcallback ) => {
  3. wx.showLoading()
  4. wx.request({
  5. url: _url,
  6. method: _method,
  7. data: _data,
  8. header: {
  9. 'content-type': 'application/json',
  10. 'appletId': '',
  11. 'token': ''
  12. },
  13. success: ((res) => {
  14. wx.hideLoading()
  15. console.log(res.statusCode)
  16. if ((res.statusCode == 200 || res.statusCode == 201) && callback) {
  17. callback(res)
  18. }else{
  19. if(failcallback){
  20. failcallback(res)
  21. }else{
  22. wx.showToast({
  23. title: '服务器开小差',
  24. icon: 'none'
  25. })
  26. }
  27. }
  28. }),
  29. fail: ((res) => {
  30. wx.hideLoading()
  31. failcallback(res)
  32. wx.showToast({
  33. title: '服务器开小差',
  34. icon: 'none'
  35. })
  36. })
  37. })
  38. }
  39. module.exports = {
  40. request: request
  41. }