50d4471c by yangwei

token修改

1 parent 640a4a57
/*
* @Description: 此文件主要创建 axios 实例,然后添加请求拦截器和响应拦截器
* @Autor: renchao
* @LastEditTime: 2023-06-08 09:02:53
* @LastEditTime: 2023-06-26 09:24:00
*/
import Vue from 'vue'
import axios from 'axios'
import Router from '@/router'
import Cookies from 'js-cookie'
import { Message } from 'element-ui'
import { endLoadingSubCount } from './requestLoading'
import {getToken, setToken} from "@/utils/util";
// create an axios instance
const service = axios.create({
......@@ -27,15 +27,7 @@ const service = axios.create({
service.interceptors.request.use(
config => {
if (process.env.NODE_ENV === 'development') {
const token = localStorage.getItem('token')
// 添加请求头
if (token) {
config.headers['Authorization'] = 'Bearer ' + token
} else {
config.headers.delete('Authorization')
}
} else {
const token = Cookies.get('token')
const token = getToken()
// 添加请求头
if (token) {
config.headers['Authorization'] = 'Bearer ' + token
......@@ -75,12 +67,8 @@ service.interceptors.response.use(
window.__isNeedLogin = false
Message.error('token失效,请重新登录');
let locationUrl = window.location.protocol + '//' + window.location.host + window.location.pathname;
if (process.env.NODE_ENV === 'development') {
localStorage.removeItem('token')
} else {
Cookies.remove('token')
}
setToken(undefined)
sessionStorage.removeItem('token')
if (window._config.casEnable) {
window.location.href = window._config.casBaseURL + '/logout?service=' + encodeURIComponent(locationUrl);
} else {
......