From 1aaf0f6da002adb7613e0adca7d67dac5e3265b1 Mon Sep 17 00:00:00 2001 From: dong <58670809@qq.com> Date: Fri, 7 Jul 2023 09:27:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/boot/axios.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/boot/axios.ts b/src/boot/axios.ts index 3fe93a6..414e620 100644 --- a/src/boot/axios.ts +++ b/src/boot/axios.ts @@ -66,7 +66,7 @@ export class ApiError { // "export default () => {}" function below (which runs individually // for each client) const api = axios.create({ baseURL: getHttpBase() }); - +let isOpenDialog = false; // 认证弹窗是否打开 export default boot(({ app, router }) => { // for use inside Vue files (Options API) through this.$axios and this.$api @@ -86,14 +86,20 @@ export default boot(({ app, router }) => { return response; }, (err) => { - if (err.response && err.response.status === 401) { + if (err.response && err.response.status === 401 && !isOpenDialog) { + isOpenDialog = true; Dialog.create({ title: '认证失败', message: '认证失败或登录超时,请重新登录', persistent: true, - }).onOk(() => { - router.push({ name: 'login' }); - }); + }) + .onOk(() => { + router.push({ name: 'login' }); + isOpenDialog = false; + }) + .onCancel(() => { + isOpenDialog = false; + }); } return Promise.reject(ApiError.from(err)); }