From 93e3eab6bf6063fc5a04ed1e18998955fdd09011 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A6=86=E9=92=B1=E8=90=BD=E5=B0=BD=E6=A7=BF=E8=8A=B1?= =?UTF-8?q?=E7=A8=80?= <2675540038@qq.com> Date: Thu, 3 Apr 2025 15:54:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=8D=95=E7=82=B9=E7=99=BB?= =?UTF-8?q?=E9=99=86bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/http.ts | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/api/http.ts b/src/api/http.ts index c78cadd..4a98148 100644 --- a/src/api/http.ts +++ b/src/api/http.ts @@ -11,15 +11,15 @@ type TAxiosOption = { //记得修改上传路径/api/common/upload const baseURL = 'http://yfyd.hschool.com.cn' // 设置基础URL前缀 //const baseURL="http://127.0.0.1"; - + // 导出baseURL,使其可以在其他页面使用 export { baseURL }; const config: TAxiosOption = { timeout: 5000, baseURL: baseURL, - headers:{ - 'content-type':'application/x-www-form-urlencoded' + headers: { + 'content-type': 'application/x-www-form-urlencoded' } } @@ -34,7 +34,7 @@ class Http { if (userInfoStore.token) { (config.headers as AxiosRequestHeaders).token = userInfoStore.token as string } else { - if(router.currentRoute.value.path!=='/login') { + if (router.currentRoute.value.path !== '/login') { router.push('/login'); } } @@ -45,20 +45,17 @@ class Http { /* 响应拦截 */ this.service.interceptors.response.use((response: AxiosResponse) => { + if (response.data.code == 99998) { + layer.msg('会话超时, 请重新登录!', { icon: 2 }); + router.push('/login'); + return; + } switch (response.data.code) { case 1: return response.data; case 500: return response.data; - case 99998: - layer.confirm( - '会话超时, 请重新登录', - { icon : 2, yes: function(){ - router.push('/login'); - layer.closeAll() - }}); - return response.data; - default: + case 0: return response.data; } }, error => {