1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { config } from '@/common/config.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.header.timestamp = new Date().getTime();
- config.header.nonce = vm.$u.guid(20);
-
- config.header.signature = vm.$u.guid(20);
-
-
-
-
-
-
-
-
-
-
-
- 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){
-
-
-
- uni.showModal({
- title: '温馨提示',
- content: '登录失效,请重新登录',
- showCancel: false,
- success: (res) => {
- if(res.confirm){
- uni.reLaunch({
- url: '/pages/login/login'
- });
- }
- }
- });
-
-
-
- }else return false;
- }
- }
- export default {
- install
- }
|