auto expand menu when menu open by search/recent

This commit is contained in:
Dede Fuji Abdul
2023-10-27 09:47:02 +07:00
parent 3b4e2ae1b9
commit 4fc30443e3
3 changed files with 24 additions and 30 deletions

View File

@ -24,19 +24,9 @@ watch(route, (to, _) => {
closeSideBar()
})
// onMounted(() => {
// menu.menuSelected = router.currentRoute.value.fullPath
// if (menu.menuSelected !== '/' && menu.menuSelected !== '/home' && menu.menuSelected.includes('/home')) {
// const result = splitRoutePath(menu.menuSelected)
// for (const route of result) {
// if (route !== '/home') {
// menu.toggleSidebarMenu(route, true)
// }
// }
// }
// })
onMounted(() => {
menu.expandCurrentActiveMenu()
})
const isMenu = (name: string) => {
return menu.menuSelected === name

View File

@ -88,6 +88,9 @@ export const useCommandPalattesStore = defineStore('command_palettes', () => {
addRecent(routeTarget)
route.push(routeTarget.path)
closeCommand()
setTimeout(() => {
menu.expandCurrentActiveMenu()
}, 200);
}
const closeCommand = () => {

View File

@ -17,7 +17,7 @@ export const useMenuStore = defineStore('menu', () => {
const menuSelected = ref(route.fullPath)
const toggleSidebar = () => (sidebarOpen.value = !sidebarOpen.value)
const toggleSidebarMenu = (path: string, newExpanded: boolean): void => {
// console.log('expanded', path);
console.log('expanded', path);
const toggleItemExpanded = (items: MenuItemModel[]): void => {
for (const item of items) {
@ -40,22 +40,6 @@ export const useMenuStore = defineStore('menu', () => {
}
const toggleSidebarDesktop = () => (sidebarShowed.value = !sidebarShowed.value)
onMounted(() => {
const menuData = convertRouteToMenu(routes.at(0)?.children || [])
navigation.value = menuData
menuSelected.value = router.currentRoute.value.fullPath
if (menuSelected.value !== '/' && menuSelected.value !== '/home' && menuSelected.value.includes('/home')) {
const result = splitRoutePath(menuSelected.value)
for (const route of result) {
if (route !== '/home') {
toggleSidebarMenu(route, true)
}
}
}
})
watch(router, (value) => {
if (value.currentRoute.value.fullPath === '/' || value.currentRoute.value.fullPath === '/home') {
for (const item of navigation.value) {
@ -79,7 +63,24 @@ export const useMenuStore = defineStore('menu', () => {
}
})
const expandCurrentActiveMenu = (): void => {
const menuData = convertRouteToMenu(routes.at(0)?.children || [])
navigation.value = menuData
menuSelected.value = router.currentRoute.value.fullPath
if (menuSelected.value !== '/' && menuSelected.value !== '/home' && menuSelected.value.includes('/home')) {
const result = splitRoutePath(menuSelected.value)
for (const route of result) {
if (route !== '/home') {
toggleSidebarMenu(route, true)
}
}
}
}
return {
expandCurrentActiveMenu,
navigation,
toggleSidebar,
sidebarOpen,