From 6fabd38953d88bdd5d0ec716f6961758ca4545e8 Mon Sep 17 00:00:00 2001 From: Amjacks <1932302177@qq.com> Date: Mon, 7 Apr 2025 16:54:32 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E7=99=BB=E5=BD=95=E6=9C=AA=E9=87=8D?= =?UTF-8?q?=E5=AE=9A=E5=90=91=EF=BC=8C=E5=89=8D=E7=AB=AF=E9=80=80=E5=87=BA?= =?UTF-8?q?=E6=9C=AA=E6=B8=85=E7=A9=BA=E6=95=B0=E6=8D=AE=E3=80=81=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E9=87=8D=E5=A4=8D=E7=82=B9=E5=87=BB=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layout/components/Navbar/index.vue | 2 ++ src/router/guard.ts | 9 +++++++-- src/views/login/index.vue | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/layout/components/Navbar/index.vue b/src/layout/components/Navbar/index.vue index 9c85f40..e0e5c6b 100644 --- a/src/layout/components/Navbar/index.vue +++ b/src/layout/components/Navbar/index.vue @@ -212,6 +212,8 @@ function logout() { localStorage.removeItem('userId'); localStorage.removeItem('userName'); localStorage.removeItem('orgNo'); + localStorage.removeItem('session'); + localStorage.removeItem('token'); }); } diff --git a/src/router/guard.ts b/src/router/guard.ts index dc76927..24b00e8 100644 --- a/src/router/guard.ts +++ b/src/router/guard.ts @@ -13,7 +13,13 @@ function setGuard(router: any) { const hasToken = user.getToken(); // 未登录 - if (!hasToken) { + if (hasToken) { + // 已登录 + if (to.path === '/login') { + next('/'); + return; + } + } else { // 未登录时放通login if (to.path === '/login') { next(); @@ -27,7 +33,6 @@ function setGuard(router: any) { const routes = app.getRoutes; // 若没有设置routes if (routes && routes.length === 0) { - const { app } = useStore(); // 获取menuList const menuList: any = await app.getMenuList(); // 如果menuList不存在或为空,则不走下面 diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 95112f4..3e18be0 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -163,6 +163,7 @@ function handleLogin() { localStorage.removeItem('ut'); localStorage.removeItem('userId'); localStorage.removeItem('userName'); + state.loading = true // 1、store请求 user.login(form) .then((res) => { @@ -172,8 +173,9 @@ function handleLogin() { // 请求失败时的处理逻辑 console.log(res); ElMessageBox.alert(res.response.data.message, '提醒框', { - confirmButtonText: 'OK' - }) + confirmButtonText: 'OK' + }) + state.loading = false }); } else { state.loading = false;