123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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_user.userId){config.header.user_id = vm.vuex_user.userId;}
-
-
-
-
-
-
-
-
-
- let lifeData = uni.getStorageSync('lifeData');
- let token = lifeData.vuex_user?.token;
- if(token){config.header.Authorization = `Bearer ${token}`;}
-
-
-
-
-
- let noTokenList = ['/wechat/h5/user'];
- 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 value = uni.getStorageSync('session_login_out');
- if (!value){
- uni.setStorageSync('session_login_out', 'test');
- uni.showModal({
- title: '温馨提示',
- content: '登录失效,请重新登录',
- showCancel: false,
- success: (res) => {
- if(res.confirm){
- uni.reLaunch({
- url: '/pages/login/login'
- });
- uni.removeStorageSync('session_login_out');
- }
- }
- });
- }
-
-
-
- const backUrl = location.href
- console.log('backUrl',backUrl);
- const loginUrl = 'login'
- if (backUrl.indexOf(loginUrl) > 0) {
- localStorage.clear()
- } else {
- localStorage.setItem('backUrl', location.href)
-
- uni.showModal({
- title: '温馨提示',
- content: '登录失效,请重新登录',
- showCancel: false,
- success: (res) => {
- if(res.confirm){
- uni.reLaunch({
- url: '/pages/login/login'
- });
- }
- }
- });
- }
-
- }else return res;
- }
- }
- export default {
- install
- }
|