Skip to content

Commit

Permalink
fixbug: 退出登录清除标签页
Browse files Browse the repository at this point in the history
  • Loading branch information
jsxiaosi committed Jul 7, 2022
1 parent b1fc36a commit af6d8d0
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions src/components/Application/AppAccount.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
</template>

<script setup lang="ts">
import { usePermissionStoreHook } from '@/store/modules/permission';
import { useRouter } from 'vue-router';
const router = useRouter();
const command = (value: string) => {
if (value === 'signOut') {
usePermissionStoreHook().handleRemoveMultiTabs();
localStorage.removeItem('userInfo');
router.push('/login');
}
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/AppTabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
import { useTabsView } from './hooks/useTabsView';
import { useTabsChange } from './hooks/useTabsChange';
import { emitter } from '@/utils/mitt';
import { useSelectMenu } from '../../hooks/useSelectMenu';
import { useNavSideBar } from '../../hooks/useNavSideBar';
const route = useRoute();
const router = useRouter();
Expand All @@ -80,7 +80,7 @@
const { setTabPaneKey, addRouteTabs, onFresh, removeTab } = useTabsChange(multiTabs);
const { selectMenu } = useSelectMenu();
const { selectMenu } = useNavSideBar();
const { visible, rightClickTags, rightViewStyle, contextmenu, rightViewChange } =
useTabsView(multiTabs);
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/Sidebar/MinSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
import { usePermissionStoreHook } from '@/store/modules/permission';
import { computed } from 'vue';
import { useRoute } from 'vue-router';
import { useSelectMenu } from '../../hooks/useSelectMenu';
import { useNavSideBar } from '../../hooks/useNavSideBar';
import { AppRouteRecordRaw } from '#/route';
import { getParentPaths, findRouteByPath } from '@/router/utils';
const { selectMenu } = useSelectMenu();
const { selectMenu } = useNavSideBar();
const route = useRoute();
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/pageLayouts/components/Sidebar/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import { usePermissionStoreHook } from '@/store/modules/permission';
import { AppRouteRecordRaw } from '#/route';
import { getParentPaths, findRouteByPath } from '@/router/utils';
import { useSelectMenu } from '../../hooks/useSelectMenu';
import { useNavSideBar } from '../../hooks/useNavSideBar';
const { selectMenu } = useSelectMenu();
const { selectMenu } = useNavSideBar();
const route = useRoute();
const { appConfigMode } = getAppCollapseMenu();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { AppRouteRecordRaw } from '#/route';
import { findRouteByPath } from '@/router/utils';
import { usePermissionStoreHook } from '@/store/modules/permission';
import { emitter } from '@/utils/mitt';
import { useRouter } from 'vue-router';

export const useSelectMenu = () => {
export const useNavSideBar = () => {
const router = (useRouter().options.routes.find((i) => i.path === '/') ||
[]) as AppRouteRecordRaw;

const selectMenu = (path: string) => {
console.log(router);
const findRoute = findRouteByPath(path, router.children || []);
console.log(findRoute);
if (findRoute) {
if (findRoute.redirect && findRoute.children && findRoute.children.length) {
selectMenu(findRoute.children[0].path);
Expand All @@ -21,5 +21,9 @@ export const useSelectMenu = () => {
}
};

return { selectMenu };
const logout = () => {
usePermissionStoreHook().handleRemoveMultiTabs();
};

return { selectMenu, logout };
};
1 change: 0 additions & 1 deletion src/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ function findRouteByPath(path: string, routes: AppRouteRecordRaw[]): AppRouteRec
function resetRouter() {
sidebarRouteList.forEach((route) => {
const { name } = route;
console.log(name);
if (name) {
router.hasRoute(name) && router.removeRoute(name);
}
Expand Down
5 changes: 5 additions & 0 deletions src/store/modules/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ const usePermissionStore = defineStore({
}
setlocalStorage('multiTabsList', this.multiTabs);
},
handleRemoveMultiTabs() {
setlocalStorage('multiTabsList');
this.multiTabs = [];
this.clearAllCachePage();
},
},
});

Expand Down
8 changes: 6 additions & 2 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
export function setlocalStorage(key: string, value: Recordable) {
localStorage.setItem(key, JSON.stringify(value));
export function setlocalStorage(key: string, value?: Recordable) {
if (value) {
localStorage.setItem(key, JSON.stringify(value));
} else {
localStorage.removeItem(key);
}
}

export function getlocalStorage(key: string) {
Expand Down

0 comments on commit af6d8d0

Please sign in to comment.