25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

http.js 1.0 KiB

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