|
1 | 1 | <template> |
2 | 2 | <RouterLink |
3 | | - :to="{name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}" |
| 3 | + :to="item.url || { name: item.resourceId ? 'resource-list' : item.path, params: item.resourceId ? { resourceId: item.resourceId }: {}}" |
| 4 | + :target="item.isOpenInNewTab ? '_blank' : '_self'" |
4 | 5 | class="af-menu-link flex group relative items-center w-full py-2 text-lightSidebarText dark:text-darkSidebarText rounded-default transition-all duration-200 ease-in-out" |
5 | 6 | :class="{ |
6 | 7 | 'hover:bg-lightSidebarItemHover hover:text-lightSidebarTextHover dark:hover:bg-darkSidebarItemHover dark:hover:text-darkSidebarTextHover active:bg-lightSidebarActive dark:active:bg-darkSidebarHover': !['divider', 'gap', 'heading'].includes(item.type), |
7 | 8 | 'pl-6 pr-3.5': (isChild && !isSidebarIconOnly && !isSidebarHovering) || (isChild && isSidebarIconOnly && isSidebarHovering), |
8 | 9 | 'px-3.5 ': !isChild || (isSidebarIconOnly && !isSidebarHovering), |
9 | 10 | 'max-w-12': isSidebarIconOnly && !isSidebarHovering, |
10 | | - 'bg-lightSidebarItemActive dark:bg-darkSidebarItemActive': item.resourceId ? |
11 | | - ($route.params.resourceId === item.resourceId && $route.name === 'resource-list') : |
12 | | - ($route.name === item.path) |
| 11 | + 'bg-lightSidebarItemActive dark:bg-darkSidebarItemActive': isItemActive(item) |
13 | 12 | }" |
14 | 13 | > |
15 | 14 | <component v-if="item.icon" :is="getIcon(item.icon)" |
@@ -61,6 +60,21 @@ import { Tooltip } from '@/afcl'; |
61 | 60 | import { ref, watch, computed } from 'vue'; |
62 | 61 | import { useCoreStore } from '@/stores/core'; |
63 | 62 | import { IconFileImageOutline } from '@iconify-prerendered/vue-flowbite'; |
| 63 | +import { useRoute } from 'vue-router'; |
| 64 | +
|
| 65 | +const route = useRoute(); |
| 66 | +
|
| 67 | +const isItemActive = (item: any) => { |
| 68 | + if (item.url) { |
| 69 | + return route.fullPath === item.url; |
| 70 | + } |
| 71 | +
|
| 72 | + if (item.resourceId) { |
| 73 | + return route.params.resourceId === item.resourceId && route.name === 'resource-list'; |
| 74 | + } |
| 75 | +
|
| 76 | + return route.name === item.path; |
| 77 | +}; |
64 | 78 |
|
65 | 79 | const props = defineProps(['item', 'isChild', 'isSidebarIconOnly', 'isSidebarHovering']); |
66 | 80 |
|
|
0 commit comments