request.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const baseUrl = 'http://mz.tshe.cn:802/prod-api';
  2. module.exports = {
  3. query({url, data, method = 'GET'}) {
  4. return new Promise((resolve, reject) => {
  5. wx.request({
  6. url: `${baseUrl}/${url}`,
  7. data: data,
  8. method: method,
  9. timeout: 5000,
  10. header: {
  11. 'content-type': 'application/x-www-form-urlencoded;charset=UTF-8;'
  12. },
  13. // dataType: 'json',
  14. success: resolve,
  15. fail: reject,
  16. });
  17. });
  18. },
  19. query2({url, data, method = 'GET'}) {
  20. return new Promise((resolve, reject) => {
  21. wx.request({
  22. url: `${baseUrl}/${url}`,
  23. data: data,
  24. method: method,
  25. timeout: 5000,
  26. header: {
  27. 'content-type': 'application/json;'
  28. },
  29. dataType: 'json',
  30. success: resolve,
  31. fail: reject,
  32. });
  33. });
  34. },
  35. fetch({url, id}) {
  36. return new Promise((resolve, reject) => {
  37. wx.request({
  38. url: `${baseUrl}/${url}/${id}`,
  39. method: 'GET',
  40. header: {'content-type': 'application/json'},
  41. dataType: 'json',
  42. success: resolve,
  43. fail: reject,
  44. });
  45. });
  46. },
  47. }