| | |
| | | import { computed, Ref, toRaw } from 'vue'; |
| | | |
| | | import { unref } from 'vue'; |
| | | import { es6Unique } from '/@/utils'; |
| | | import { uniq } from 'lodash-es'; |
| | | import { useMenuSetting } from '/@/hooks/setting/useMenuSetting'; |
| | | import { getAllParentPath } from '/@/router/helper/menuHelper'; |
| | | import { useTimeoutFn } from '/@/hooks/core/useTimeout'; |
| | | |
| | | export function useOpenKeys( |
| | | menuState: MenuState, |
| | | menus: Ref<MenuType[]>, |
| | | mode: Ref<MenuModeEnum>, |
| | | accordion: Ref<boolean> |
| | | accordion: Ref<boolean>, |
| | | ) { |
| | | const { getCollapsed, getIsMixSidebar } = useMenuSetting(); |
| | | |
| | | function setOpenKeys(path: string) { |
| | | async function setOpenKeys(path: string) { |
| | | if (mode.value === MenuModeEnum.HORIZONTAL) { |
| | | return; |
| | | } |
| | | const menuList = toRaw(menus.value); |
| | | if (!unref(accordion)) { |
| | | menuState.openKeys = es6Unique([...menuState.openKeys, ...getAllParentPath(menuList, path)]); |
| | | } else { |
| | | menuState.openKeys = getAllParentPath(menuList, path); |
| | | } |
| | | const native = unref(getIsMixSidebar); |
| | | useTimeoutFn( |
| | | () => { |
| | | const menuList = toRaw(menus.value); |
| | | if (menuList?.length === 0) { |
| | | menuState.openKeys = []; |
| | | return; |
| | | } |
| | | if (!unref(accordion)) { |
| | | menuState.openKeys = uniq([...menuState.openKeys, ...getAllParentPath(menuList, path)]); |
| | | } else { |
| | | menuState.openKeys = getAllParentPath(menuList, path); |
| | | } |
| | | }, |
| | | 16, |
| | | !native, |
| | | ); |
| | | } |
| | | |
| | | const getOpenKeys = computed(() => { |