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;