|
1 | | -import { defineComponent, computed, nextTick, onMounted, watch } from 'vue'; |
| 1 | +import { defineComponent, computed, nextTick, onMounted, watch, onBeforeUnmount } from 'vue'; |
2 | 2 | import { storeToRefs } from 'pinia'; |
3 | 3 | import { useRoute, useRouter } from 'vue-router'; |
4 | 4 | import { usePermissionStore, useSettingStore, useTabsRouterStore } from '@/store'; |
@@ -37,7 +37,6 @@ export default defineComponent({ |
37 | 37 | const headerMenu = computed(() => { |
38 | 38 | if (settingStore.layout === 'mix') { |
39 | 39 | if (settingStore.splitMenu) { |
40 | | - console.log(menuRouters); |
41 | 40 | return menuRouters.value.map((menu) => ({ |
42 | 41 | ...menu, |
43 | 42 | children: [], |
@@ -70,10 +69,28 @@ export default defineComponent({ |
70 | 69 | tabsRouterStore.appendTabRouterList({ path, title: title as string, name, isAlive: true }); |
71 | 70 | }; |
72 | 71 |
|
| 72 | + const getTabRouterListCache = () => { |
| 73 | + tabsRouterStore.initTabRouterList(JSON.parse(localStorage.getItem('tabRouterList'))); |
| 74 | + }; |
| 75 | + const setTabRouterListCache = () => { |
| 76 | + const { tabRouters } = tabsRouterStore; |
| 77 | + localStorage.setItem('tabRouterList', JSON.stringify(tabRouters)); |
| 78 | + }; |
| 79 | + |
73 | 80 | onMounted(() => { |
74 | 81 | appendNewRoute(); |
75 | 82 | }); |
76 | 83 |
|
| 84 | + // 如果不需要持久化标签页可以注释掉以下的 onMounted 和 onBeforeUnmount 的内容 |
| 85 | + onMounted(() => { |
| 86 | + if (localStorage.getItem('tabRouterList')) getTabRouterListCache(); |
| 87 | + window.addEventListener('beforeunload', setTabRouterListCache); |
| 88 | + }); |
| 89 | + |
| 90 | + onBeforeUnmount(() => { |
| 91 | + window.removeEventListener('beforeunload', setTabRouterListCache); |
| 92 | + }); |
| 93 | + |
77 | 94 | watch( |
78 | 95 | () => route.path, |
79 | 96 | () => { |
@@ -159,7 +176,7 @@ export default defineComponent({ |
159 | 176 | class={`${prefix}-layout-tabs-nav`} |
160 | 177 | value={route.path} |
161 | 178 | onChange={handleChangeCurrentTab} |
162 | | - style={{ maxWidth: '100%', position: 'fixed', overflow: 'visible' }} |
| 179 | + style={{ width: '100%', position: 'sticky', top: 0 }} |
163 | 180 | onRemove={handleRemove} |
164 | 181 | > |
165 | 182 | {tabRouters.map((router: TRouterInfo, idx: number) => ( |
|
0 commit comments