diff --git a/src/store/modules/user.js b/src/store/modules/user.js index df2f0ee4f..e93fa2ba5 100644 --- a/src/store/modules/user.js +++ b/src/store/modules/user.js @@ -179,7 +179,6 @@ const user = { commit('SET_TOKEN', ''); commit('SET_ID', ''); commit('SET_ROLES', []); - removeToken(); }, // 登出系统 @@ -191,6 +190,7 @@ const user = { dispatch('disconnect').then(()=>{ dispatch('FedLogOut').then(resp => { logout(token).then(() => { + removeToken(); resolve(); }).catch(error => { reject(error); @@ -215,6 +215,7 @@ const user = { return new Promise((resolve, reject) => { dispatch('FedLogOut').then(resp => { logout(token).then(() => { + removeToken(); resolve(); }).catch(error => { reject(error); @@ -234,7 +235,6 @@ const user = { }, disconnect({commit}, params) { commit('Disconnect', params); - removeToken(); }, setBaseUrl ({commit}, baseUrl) { commit('setBaseUrl', baseUrl); diff --git a/src/utils/auth.js b/src/utils/auth.js index 01775a9a2..0566c531c 100644 --- a/src/utils/auth.js +++ b/src/utils/auth.js @@ -5,13 +5,13 @@ const TokenKey = 'Admin-Token'; // 设置教学,实训,仿真系统token, 设置城市轨道交通设计平台token export function getToken() { - return SessionStorage.getItem(TokenKey); + return localStorage.getItem(TokenKey); } export function setToken(token) { - return SessionStorage.setItem(TokenKey, token); + return localStorage.setItem(TokenKey, token); } export function removeToken() { - return SessionStorage.removeItem(TokenKey); + return localStorage.removeItem(TokenKey); } // 操作sessionStorage diff --git a/src/utils/request.js b/src/utils/request.js index 543e9cd07..f9c055975 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -22,6 +22,7 @@ const service = axios.create({ // request拦截器108 service.interceptors.request.use(config => { if (getToken()) { + config.headers['Authorization'] = `Bearer ${getToken()}`; // 让每个请求携带自定义token 请根据实际情况自行修改 config.headers['X-Token'] = getToken(); // 让每个请求携带自定义token 请根据实际情况自行修改 }