request.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //测试地址
  2. const baseUrl = 'http://dms.66km.com.cn/'
  3. //const baseUrl = 'http://192.168.0.14:20187/'
  4. //正式地址
  5. const http = (url = '', date = {}, type = 'POST', header = {
  6. }) => {
  7. return new Promise((resolve, reject) => {
  8. header={};
  9. var token=uni.getStorageSync('token')
  10. header['token']=token;
  11. if(url=='enterprise/wechat/extCustomerMobile'){
  12. header['Content-Type']='application/x-www-form-urlencoded';
  13. }else{
  14. header['Content-Type']='application/json;charset=utf-8';
  15. }
  16. uni.request({
  17. method: type,
  18. url: baseUrl + url,
  19. data: date,
  20. header: header,
  21. dataType: 'json',
  22. }).then((response) => {
  23. // console.log(response.data.code)
  24. //console.log(response.data.data.code)
  25. //let [error, res] = response;
  26. // console.log(res)
  27. /* if(res.data.code==401||res.data.code==403){
  28. uni.clearStorageSync()
  29. }else if(res.data.code==409){
  30. // getToken(url,date,type,header)
  31. } */
  32. /* if(response.data.data.code!=1){
  33. console.log(res.data.data.msg)
  34. uni.hideLoading();
  35. uni.clearStorageSync()
  36. uni.showToast({
  37. title: res.data.data.msg,
  38. icon: 'none',
  39. duration: 3000
  40. });
  41. } */
  42. /* if(response.data.code!=1){
  43. //console.log(res.data.msg)
  44. uni.hideLoading();
  45. //uni.clearStorageSync()
  46. uni.showToast({
  47. title: response.data.msg,
  48. icon: 'none',
  49. duration: 3000
  50. });
  51. }else{
  52. } */
  53. resolve(response.data);
  54. }).catch(error => {
  55. let [err, res] = error;
  56. reject(err)
  57. })
  58. });
  59. }
  60. export default {
  61. http
  62. }