request.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // uni-app请求封装
  2. export default class Request {
  3. http(router, data = {}, method,contentType) {
  4. let that = this;
  5. // let path = 'http://localhost:8008';
  6. // let path = 'http://t8756345.natappfree.cc';
  7. // let path = 'http://uis.ftrur.com/prod-api';
  8. let path = 'https://bd-1.muyii.top/prod-api';
  9. // let path = 'https://bd.runtzh.com/prod-api';
  10. // let path = 'https://www.jrwlcq.com/prod-api';
  11. uni.setStorageSync('requestPath',path)
  12. // uni.showLoading({
  13. // title: '載入中'
  14. // });
  15. return new Promise((resolve, reject) => {
  16. let token = uni.getStorageSync('AppToken');
  17. var httpContentType='application/x-www-form-urlencoded';
  18. if(contentType!=undefined){
  19. //application/json;charset=UTF-8
  20. httpContentType=contentType;
  21. }
  22. var routers=router;
  23. // 请求
  24. uni.request({
  25. header: {
  26. // 'Content-Type': 'application/x-www-form-urlencoded',
  27. 'Content-Type': httpContentType,
  28. },
  29. url: `${path}${router}`,
  30. data: data,
  31. method: method,
  32. success: (res) => {
  33. //收到开发者服务器成功返回的回调函数
  34. resolve(res.data)
  35. },
  36. fail:(res) =>{
  37. //接口调用失败的回调函数
  38. },
  39. complete:(res) =>{
  40. //接口调用结束的回调函数(调用成功、失败都会执行)
  41. if (res.data.code == 401) {
  42. return false
  43. }
  44. uni.hideLoading();
  45. }
  46. })
  47. })
  48. }
  49. }