You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 lines
1.4 KiB

  1. // const baseUrl = 'http://39.97.167.65/autoSR/api';// 测试站
  2. // const baseUrl = 'http://8kdmng.natappfree.cc/autoSR/api'; // 佳豪
  3. const baseUrl = 'http://192.168.31.134:9999/autoSR/api'; // 佳豪
  4. // const baseUrl = 'http://zanyong.hfju.com/autoSR/api';// 正式
  5. const install = (Vue, vm) => {
  6. Vue.prototype.$u.http.setConfig({
  7. baseUrl,
  8. loadingText: '加载中~',
  9. loadingTime: 800,
  10. });
  11. // 请求拦截,如果有token,携带token
  12. Vue.prototype.$u.http.interceptor.request = (config) => {
  13. const token = uni.getStorageSync('weapp_session_login_data');
  14. if(token){
  15. config.header['Authorization'] ='Bearer '+token.token;
  16. }
  17. return config
  18. }
  19. // 响应拦截,公共错误处理
  20. Vue.prototype.$u.http.interceptor.response = (res) => {
  21. if(res.code == 10000) {
  22. return res.data;
  23. }else if(res.code == 10003 || res.code == 20006){
  24. uni.hideToast();
  25. uni.showToast({
  26. icon:"none",
  27. title:"您的登录已失效,请重新登录",
  28. duration: 2000
  29. })
  30. uni.clearStorageSync();
  31. setTimeout(function () {
  32. uni.reLaunch({
  33. url: '/pages/login/index'
  34. });
  35. },2000);
  36. return false;
  37. }else{
  38. uni.hideLoading();
  39. uni.showToast({
  40. icon:"none",
  41. title:res.message,
  42. duration: 3000
  43. })
  44. return false;
  45. }
  46. }
  47. }
  48. export default {
  49. install
  50. }