1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- import { commonConfig } from '@/common/config.js';
- import store from '../store/index.js'
- import {againToken} from '../utils/leaderToken.js'
- const install = (Vue, vm) => {
- Vue.prototype.$u.http.setConfig({
- baseUrl: commonConfig.baseUrl,
- timeout: 40000,
-
-
-
-
-
-
-
- });
-
- Vue.prototype.$u.http.interceptor.request = (config) => {
-
-
-
- if(vm.vuex_user.accessToken){config.header.Authorization = `Bearer ${vm.vuex_user.accessToken}`;}
- if(vm.vuex_user.userId){config.header['user_id'] = `${vm.vuex_user.userId}`;}
-
-
-
-
-
-
-
-
-
-
- if(config.url.indexOf('?') > -1){
- config.url = config.url + '&t=' + Date.now()
- } else {
- 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){
- if(vm.vuex_user.userId) {
- againToken(vm.vuex_user.userId)
- } else {
- const backUrl = location.href
- const loginUrl = 'phoneLogin'
- if (backUrl.indexOf(loginUrl) > 0) {
- localStorage.clear()
- } else {
-
-
-
-
-
- localStorage.setItem('backUrl', location.href)
-
- setTimeout(() => {
- uni.navigateTo({
- url: "/pages/login/login"
- })
- }, 1000)
- }
- }
-
-
- }else return res;
- }
- }
- export default {
- install
- }
|