|
|
@@ -131,6 +131,13 @@ service.interceptors.response.use(
|
|
|
return res;
|
|
|
}
|
|
|
if (code === 401) {
|
|
|
+ if (msg === '未登录' || res.data.message === '未登录') {
|
|
|
+ // 未登录情况直接跳登录页,无需弹窗确认
|
|
|
+ useUserStore().logout().then(() => {
|
|
|
+ location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'login';
|
|
|
+ });
|
|
|
+ return Promise.reject('未登录,即将跳转到登录页。');
|
|
|
+ }
|
|
|
// prettier-ignore
|
|
|
if (!isRelogin.show) {
|
|
|
isRelogin.show = true;
|
|
|
@@ -174,6 +181,27 @@ service.interceptors.response.use(
|
|
|
},
|
|
|
(error: any) => {
|
|
|
console.log(error)
|
|
|
+
|
|
|
+ // 如果是 HTTP 401,跳转到登录
|
|
|
+ if (error.response && error.response.status === 401) {
|
|
|
+ if (!isRelogin.show) {
|
|
|
+ isRelogin.show = true;
|
|
|
+ ElMessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
|
|
|
+ confirmButtonText: '重新登录',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ type: 'warning'
|
|
|
+ }).then(() => {
|
|
|
+ isRelogin.show = false;
|
|
|
+ useUserStore().logout().then(() => {
|
|
|
+ location.href = import.meta.env.VITE_APP_CONTEXT_PATH + 'index';
|
|
|
+ });
|
|
|
+ }).catch(() => {
|
|
|
+ isRelogin.show = false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return Promise.reject('无效的会话,或者会话已过期,请重新登录。');
|
|
|
+ }
|
|
|
+
|
|
|
let { message } = error;
|
|
|
if (message == 'Network Error') {
|
|
|
message = '网络异常';
|