From 02c14089f100dadfc2259d288ed663d35950bf5d Mon Sep 17 00:00:00 2001 From: Andrian Roshandy Date: Wed, 12 Nov 2025 06:51:03 +0700 Subject: [PATCH] feat/menu-structure: update role switcher --- app/components/layout/AppSidebar.vue | 30 ++++++++++++++---- app/components/layout/SidebarNavFooter.vue | 36 ++++++++++++---------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/app/components/layout/AppSidebar.vue b/app/components/layout/AppSidebar.vue index c3d2d45e..a14b2137 100644 --- a/app/components/layout/AppSidebar.vue +++ b/app/components/layout/AppSidebar.vue @@ -4,6 +4,8 @@ type NavGroup = { items: any[] } +const { getActiveRole } = useUserStore() + const navMenu = ref([]) const teams: { @@ -41,18 +43,34 @@ onMounted(async () => { await setMenu() }) +async function setMenu() { + const activeRole = getActiveRole() + const activeRoleParts = activeRole ? activeRole.split('|') : [] + const role = activeRoleParts[0]+(activeRoleParts.length > 1 ? `-${activeRoleParts[1]}` : '') + try { + const res = await fetch(`/side-menu-items/${role.toLowerCase()}.json`) + const rawMenu = await res.text() + navMenu.value = JSON.parse(rawMenu) + } catch (e) { + const res = await fetch(`/side-menu-items/blank.json`) + const rawMenu = await res.text() + navMenu.value = JSON.parse(rawMenu) + } +} + function resolveNavItemComponent(item: any): any { if ('children' in item) return resolveComponent('LayoutSidebarNavGroup') return resolveComponent('LayoutSidebarNavLink') } -async function setMenu() { - const position_code = 'sys' - const res = await fetch(`/side-menu-items/${position_code}.json`) - const rawMenu = await res.text() - navMenu.value = JSON.parse(rawMenu) -} +watch(getActiveRole, async () => { + await setMenu() + // const activeRole = getActiveRole() + // const res = await fetch(`/side-menu-items/${activeRole}.json`) + // const rawMenu = await res.text() + // navMenu.value = JSON.parse(rawMenu) +})