|
26 | 26 | import { difference, remove, union } from 'lodash'; |
27 | 27 | import type { MenuValue } from 'tdesign-vue-next'; |
28 | 28 | import type { PropType } from 'vue'; |
29 | | -import { computed, onMounted, ref, watch } from 'vue'; |
| 29 | +import { computed, onMounted, onUnmounted, ref, watch } from 'vue'; |
30 | 30 | import { useRouter } from 'vue-router'; |
31 | 31 |
|
32 | 32 | import AssetLogoFull from '@/assets/assets-logo-full.svg?component'; |
@@ -79,12 +79,18 @@ const active = computed(() => getActive()); |
79 | 79 |
|
80 | 80 | const expanded = ref<MenuValue[]>([]); |
81 | 81 |
|
| 82 | +const getExpanded = () => { |
| 83 | + const path = getActive(); |
| 84 | + const parts = path.split('/').slice(1); |
| 85 | + const result = parts.map((_, index) => `/${parts.slice(0, index + 1).join('/')}`); |
| 86 | +
|
| 87 | + expanded.value = menuAutoCollapsed.value ? result : union(result, expanded.value); |
| 88 | +}; |
| 89 | +
|
82 | 90 | watch( |
83 | 91 | () => active.value, |
84 | 92 | () => { |
85 | | - const path = getActive(); |
86 | | - const parentPath = path.substring(0, path.lastIndexOf('/')); |
87 | | - expanded.value = menuAutoCollapsed.value ? [parentPath] : union([parentPath], expanded.value); |
| 93 | + getExpanded(); |
88 | 94 | }, |
89 | 95 | ); |
90 | 96 |
|
@@ -144,13 +150,14 @@ const autoCollapsed = () => { |
144 | 150 | }; |
145 | 151 |
|
146 | 152 | onMounted(() => { |
147 | | - const path = getActive(); |
148 | | - const parentPath = path.substring(0, path.lastIndexOf('/')); |
149 | | - expanded.value = union([parentPath], expanded.value); |
| 153 | + getExpanded(); |
150 | 154 | autoCollapsed(); |
151 | | - window.onresize = () => { |
152 | | - autoCollapsed(); |
153 | | - }; |
| 155 | +
|
| 156 | + window.addEventListener('resize', autoCollapsed); |
| 157 | +}); |
| 158 | +
|
| 159 | +onUnmounted(() => { |
| 160 | + window.removeEventListener('resize', autoCollapsed); |
154 | 161 | }); |
155 | 162 |
|
156 | 163 | const goHome = () => { |
|
0 commit comments