|
56 | 56 |
|
57 | 57 | <script> |
58 | 58 | import { useRoute } from 'vue-router' |
59 | | -import { defineComponent, reactive, computed, toRefs, onMounted, onUnmounted } from 'vue' |
| 59 | +import { defineComponent, reactive, computed, toRefs, watch, onMounted, onUnmounted } from 'vue' |
60 | 60 | import { TreeMenu, Dropdown, DropdownMenu, Tooltip, Tag, Radio, RadioGroup, Button } from '@opentiny/vue' |
61 | 61 | import { genMenus, getMenuIcons } from '@/menus.jsx' |
62 | 62 | import { router } from '@/router.js' |
@@ -96,6 +96,7 @@ export default defineComponent({ |
96 | 96 | }) |
97 | 97 |
|
98 | 98 | const lang = getWord('zh-CN', 'en-US') |
| 99 | + const route = useRoute() |
99 | 100 | const { all: allPathParam, theme = defaultTheme } = useRoute().params |
100 | 101 | const allPath = allPathParam ? allPathParam + '/' : '' |
101 | 102 | const getTo = (route, key) => `${import.meta.env.VITE_CONTEXT}${allPath}${lang}/${theme}/${route}${key}` |
@@ -128,6 +129,19 @@ export default defineComponent({ |
128 | 129 | } |
129 | 130 | let routerCbDestroy = null |
130 | 131 |
|
| 132 | + watch( |
| 133 | + () => route.path, |
| 134 | + (currentVal) => { |
| 135 | + // 监听路由变化,反作用与左侧列表菜单展开对应的列表 |
| 136 | + const list = currentVal.split('/') |
| 137 | + if (list && list[list.length - 1]) { |
| 138 | + const key = list[list.length - 1] |
| 139 | + state.expandKeys = [key] |
| 140 | + state.treeMenuRef.setCurrentKey(key) |
| 141 | + } |
| 142 | + } |
| 143 | + ) |
| 144 | +
|
131 | 145 | onMounted(async () => { |
132 | 146 | // 每次切换路由,有锚点则跳转到锚点,否则导航到顶部 |
133 | 147 | routerCbDestroy = router.afterEach((to) => { |
|
0 commit comments