123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import { config } from '@/common/config.js';
- import store from '../store/index.js'
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
- baseUrl: config.baseUrl,
-
-
-
-
-
-
-
- });
-
- Vue.prototype.$u.http.interceptor.request = (config) => {
-
-
-
-
- if(vm.vuex_token){config.header.Authorization = `Bearer ${vm.vuex_token}`;}
-
-
-
-
-
-
-
-
-
-
-
- config.url = config.url + '?t=' + Date.now()
-
- let noTokenList = ['/wechat/h5/user','/client/auth/verifyCode'];
- if(noTokenList.includes(config.url)) config.header.noToken = true;
-
-
- return config;
- }
-
- Vue.prototype.$u.http.interceptor.response = (res) => {
-
-
-
- if(res.code == 200) {
-
- return res;
- } else if(res.msg == "令牌不能为空" || res.code == 401){
- const backUrl = location.href
- const loginUrl = 'phoneLogin'
- if (backUrl.indexOf(loginUrl) > 0) {
- localStorage.clear()
- } else {
- localStorage.setItem('backUrl', location.href)
- alert('还未登录,即将跳转登录');
- uni.navigateTo({
- url: "/pages/center/phoneLogin/phoneLogin"
- })
- }
-
- }else return res;
- }
- }
- export default {
- install
- }
|