AI销管
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.
 
 
 
 

51 lines
1.1 KiB

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