diff --git a/dist/production-dist/index.html b/dist/production-dist/index.html index 90b16f38..ebf26c1f 100644 --- a/dist/production-dist/index.html +++ b/dist/production-dist/index.html @@ -5,7 +5,7 @@ ray template - + diff --git a/src/store/modules/menu.ts b/src/store/modules/menu.ts index a1b10365..5560d93e 100644 --- a/src/store/modules/menu.ts +++ b/src/store/modules/menu.ts @@ -7,6 +7,7 @@ import type { RouteRecordRaw } from 'vue-router' export const useMenu = defineStore('menu', () => { const router = useRouter() + const route = useRoute() const { t } = useI18n() const cacheMenuKey = @@ -47,6 +48,30 @@ export const useMenu = defineStore('menu', () => { setCache('menuKey', key) } + /** + * + * @param path 路由地址 + * + * 监听路由地址变化更新菜单状态 + */ + const updateMenuKeyWhenRouteUpdate = (path: string) => { + const matchMenuItem = (options: MenuOption[]) => { + for (const i of options) { + if (i?.children?.length) { + matchMenuItem(i.children) + } + + if (path === i.path) { + menuModelValueChange(i.path, i) + + break + } + } + } + + matchMenuItem(menuState.options) + } + /** * * 获取菜单列表 @@ -108,6 +133,13 @@ export const useMenu = defineStore('menu', () => { const spliceMenTagOptions = (idx: number) => menuState.menuTagOptions.splice(idx, 1) + watch( + () => route.fullPath, + (newData) => { + updateMenuKeyWhenRouteUpdate(newData) + }, + ) + return { ...toRefs(menuState), menuModelValueChange,