Ver código fonte

feat: 修复登录超时问题

doi 2 meses atrás
pai
commit
f606620569
1 arquivos alterados com 18 adições e 2 exclusões
  1. 18 2
      src/utils/request.js

+ 18 - 2
src/utils/request.js

@@ -1,9 +1,20 @@
 import axios from 'axios';
-import { ElNotification, ElMessageBox } from 'element-plus';
+import { ElNotification, ElMessageBox, ElMessage } from 'element-plus';
 import sysConfig from "@/config";
 import tool from '@/utils/tool';
 import router from '@/router';
-
+import store from '@/store';
+function clearLoginSession() {
+	tool.cookie.remove('TOKEN');
+	tool.data.remove('USER_INFO');
+	tool.data.remove('MENU');
+	tool.data.remove('PERMISSIONS');
+	tool.data.remove('DASHBOARDGRID');
+	tool.data.remove('grid');
+	store.commit('clearViewTags');
+	store.commit('clearKeepLive');
+	store.commit('clearIframeList');
+}
 axios.defaults.baseURL = ''
 
 axios.defaults.timeout = sysConfig.TIMEOUT
@@ -39,6 +50,11 @@ let MessageBox_401_show = false
 // HTTP response 拦截器
 axios.interceptors.response.use(
 	(response) => {
+		if (response.data.code == 401) {
+			clearLoginSession();
+			ElMessage.warning('登录已失效,请重新登录');
+			router.replace({ path: '/login' });
+		}
 		return response;
 	},
 	(error) => {