1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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 = ['/client/wechat/h5/code/', '/client/auth/sendSmsCodeV2', '/client/auth/verifyCodeV2'];
- 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.code == 401 || res.code == 400) {
- const backUrl = location.href
-
- const ua = window.navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
-
- vm.$u.route('pages/wechatLogin/wechatLogin', { backUrl })
- } else {
-
- localStorage.setItem('backUrl', backUrl)
- localStorage.removeItem('lifeData')
- uni.showModal({
- title: '提示',
- content: '未查询到登录信息或信息已失效, 请重新登录',
- showCancel: false,
- success: function(res) {
- if (res.confirm) {
- uni.navigateTo({
- url: "/pages/center/phoneLogin/phoneLogin"
- })
- }
- }
- });
- }
- } else {
- uni.showToast({
- title: res.msg || '程序错误!',
- duration: 2000,
- icon: 'none'
- })
- };
- }
- }
- export default {
- install
- }
|