api.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const API_HOST = 'https://api-video.fyshz.com/' //接口前缀
  2. export const ReqClient = (url, method, data) => {
  3. return new Promise((resolve, reject) => {
  4. wx.showLoading();
  5. if (method === 'GET') {
  6. var header = {
  7. 'content-type': "application/x-www-form-urlencoded"
  8. }
  9. } else if (method === 'POST') {
  10. var header = {
  11. 'content-type': 'application/json'
  12. }
  13. }
  14. wx.request({
  15. url: API_HOST + url,
  16. data,
  17. method,
  18. header: header,
  19. timeout: 6000,
  20. success: (res) => {
  21. wx.hideLoading();
  22. if (res.statusCode === 500) {
  23. wx.showModal({
  24. title: '提示',
  25. content: '网络服务异常!',
  26. showCancel: false
  27. })
  28. reject(res);
  29. } else if (res.statusCode === 200) {
  30. if (res.data.code === 200) {
  31. resolve(res);
  32. } else {
  33. //业务处理
  34. reject(res);
  35. }
  36. } else {
  37. wx.showModal({
  38. title: '错误信息',
  39. content: '操作失败!如需帮助请联系技术人员',
  40. showCancel: false
  41. })
  42. }
  43. },
  44. fail: (err) => {
  45. wx.hideLoading();
  46. wx.showModal({
  47. title: '错误信息',
  48. content: '网络不可用,请检查你的网络状态或稍后再试!',
  49. showCancel: false
  50. })
  51. reject(err);
  52. }
  53. })
  54. })
  55. }