Skip to content

Commit

Permalink
fixbug: 修复退出登录不跳转登录页问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Aug 27, 2022
1 parent f28d628 commit 75d0307
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/components/Application/AppAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@

<script setup lang="ts">
import { usePermissionStoreHook } from '@/store/modules/permission';
import { removeStorage } from '@/utils/storage';
import { useRouter } from 'vue-router';
const router = useRouter();
const command = (value: string) => {
if (value === 'signOut') {
usePermissionStoreHook().handleRemoveMultiTabs();
localStorage.removeItem('userInfo');
removeStorage('userInfo');
router.push('/login');
}
};
Expand Down
23 changes: 12 additions & 11 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import NProgress from '@/utils/plugin/progress';
import { getConfig } from '@/config';
import { translateI18n } from '@/hooks/web/useI18n';
import { isUrl } from '@/utils/is';
import { getStorage } from '@/utils/storage';
import { getStorage, removeStorage } from '@/utils/storage';
import { UseInfoType } from '@/server/useInfo';

const { whiteRouteModulesList, routeModulesList } = configRouteList();
Expand Down Expand Up @@ -44,17 +44,18 @@ router.beforeEach((to, from, next) => {
}

const userInfo = getStorage<UseInfoType>('userInfo');
console.log(userInfo, from.name);
if (userInfo) {
// 已登陆状态不允许去登录页
if (to.path === '/login') {
next({
path: from.path,
query: from.query,
});
}

if (from.name) {
// 已登陆状态不允许去登录页
if (to.path === '/login') {
next({
path: from.path,
query: from.query,
});
} else {
next();
}
next();
} else {
if (usePermissionStoreHook().wholeMenus.length === 0) {
initAsyncRoute(userInfo.power || '').then((res) => {
Expand All @@ -64,7 +65,7 @@ router.beforeEach((to, from, next) => {
query: to.query,
});
} else {
localStorage.removeItem('userInfo');
removeStorage('userInfo');
router.push('login');
}
});
Expand Down

0 comments on commit 75d0307

Please sign in to comment.