소스 검색

刷新登录页面弹出一条提示

sangwenwei 1 년 전
부모
커밋
414b1badf1
1개의 변경된 파일18개의 추가작업 그리고 14개의 파일을 삭제
  1. 18 14
      src/utils/httpRequest.js

+ 18 - 14
src/utils/httpRequest.js

@@ -21,7 +21,7 @@ const BASE_URL =
 		: import.meta.env.VITE_APP_BASE;
 // 对面暴露的基础请求路径
 axios.BASE_URL = BASE_URL;
-
+let showAlert = true;
 /**
  * 请求拦截
  */
@@ -100,20 +100,24 @@ axios.interceptors.response.use(
 		if (error.response) {
 			// eslint-disable-next-line no-debugger
 			if (error.response.status === 408) {
-				// 超时自动刷新
-				ElMessageBox.confirm(
-					"当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。",
-					"无权限访问",
-					{
-						type: "error",
-						closeOnClickModal: false,
-						center: true,
-						confirmButtonText: "重新登录",
+					if (showAlert){
+						// 超时自动刷新
+						ElMessageBox.confirm(
+							"当前用户已被登出或无权限访问当前资源,请尝试重新登录后再操作。",
+							"无权限访问",
+							{
+								type: "error",
+								closeOnClickModal: false,
+								center: true,
+								confirmButtonText: "重新登录",
+							}
+						).then(() => {
+							clearLoginInfo();
+							router.replace({ path: "/login" });
+						});
+						// 将标识变量设置为 false,表示已经弹出了提示
+						showAlert = false;
 					}
-				).then(() => {
-					clearLoginInfo();
-					router.replace({ path: "/login" });
-				});
 			} else if (error.response.status === 401) {
 				// 需要重新登录
 				ElNotification.error({