auto expand menu when menu open by search/recent
This commit is contained in:
@ -24,19 +24,9 @@ watch(route, (to, _) => {
|
|||||||
closeSideBar()
|
closeSideBar()
|
||||||
})
|
})
|
||||||
|
|
||||||
// onMounted(() => {
|
onMounted(() => {
|
||||||
// menu.menuSelected = router.currentRoute.value.fullPath
|
menu.expandCurrentActiveMenu()
|
||||||
|
})
|
||||||
// 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)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
|
|
||||||
const isMenu = (name: string) => {
|
const isMenu = (name: string) => {
|
||||||
return menu.menuSelected === name
|
return menu.menuSelected === name
|
||||||
|
@ -88,6 +88,9 @@ export const useCommandPalattesStore = defineStore('command_palettes', () => {
|
|||||||
addRecent(routeTarget)
|
addRecent(routeTarget)
|
||||||
route.push(routeTarget.path)
|
route.push(routeTarget.path)
|
||||||
closeCommand()
|
closeCommand()
|
||||||
|
setTimeout(() => {
|
||||||
|
menu.expandCurrentActiveMenu()
|
||||||
|
}, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
const closeCommand = () => {
|
const closeCommand = () => {
|
||||||
|
@ -17,7 +17,7 @@ export const useMenuStore = defineStore('menu', () => {
|
|||||||
const menuSelected = ref(route.fullPath)
|
const menuSelected = ref(route.fullPath)
|
||||||
const toggleSidebar = () => (sidebarOpen.value = !sidebarOpen.value)
|
const toggleSidebar = () => (sidebarOpen.value = !sidebarOpen.value)
|
||||||
const toggleSidebarMenu = (path: string, newExpanded: boolean): void => {
|
const toggleSidebarMenu = (path: string, newExpanded: boolean): void => {
|
||||||
// console.log('expanded', path);
|
console.log('expanded', path);
|
||||||
|
|
||||||
const toggleItemExpanded = (items: MenuItemModel[]): void => {
|
const toggleItemExpanded = (items: MenuItemModel[]): void => {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
@ -40,22 +40,6 @@ export const useMenuStore = defineStore('menu', () => {
|
|||||||
}
|
}
|
||||||
const toggleSidebarDesktop = () => (sidebarShowed.value = !sidebarShowed.value)
|
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) => {
|
watch(router, (value) => {
|
||||||
if (value.currentRoute.value.fullPath === '/' || value.currentRoute.value.fullPath === '/home') {
|
if (value.currentRoute.value.fullPath === '/' || value.currentRoute.value.fullPath === '/home') {
|
||||||
for (const item of navigation.value) {
|
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 {
|
return {
|
||||||
|
expandCurrentActiveMenu,
|
||||||
navigation,
|
navigation,
|
||||||
toggleSidebar,
|
toggleSidebar,
|
||||||
sidebarOpen,
|
sidebarOpen,
|
||||||
|
Reference in New Issue
Block a user