diff --git a/src/layouts/DrawerComponent.vue b/src/layouts/DrawerComponent.vue index 29eb7a74..b029a245 100644 --- a/src/layouts/DrawerComponent.vue +++ b/src/layouts/DrawerComponent.vue @@ -6,6 +6,7 @@ import { Icon } from '@iconify/vue'; import useMyBranch from 'stores/my-branch'; import { getUserId, getRole } from 'src/services/keycloak'; import { useQuasar } from 'quasar'; +import { useI18n } from 'vue-i18n'; type Menu = { label: string; @@ -14,11 +15,13 @@ type Menu = { hidden?: boolean; disabled?: boolean; isax?: boolean; + noI18n?: boolean; children?: Menu[]; }; const router = useRouter(); const $q = useQuasar(); +const { locale } = useI18n(); const userBranch = useMyBranch(); const { currentMyBranch } = storeToRefs(userBranch); @@ -58,38 +61,22 @@ function branchSetting() { //TODO: click setting (cog icon) on drawer menu } -watch( - () => currentPath.value, - () => { - if (currentPath.value === '/') { - menuActive.value.fill(false); - menuActive.value[0] = true; - } else reActiveMenu(); - }, -); - -watch( - () => props.mini, - () => { - if (props.mini) { - reActiveMenu(); - } - }, -); - -onMounted(async () => { - const uid = getUserId(); - - role.value = getRole(); - - if (!uid) return; - - if (role.value.includes('system')) { - const result = await userBranch.fetchListOptionBranch(); - if (result && result.total > 0) currentMyBranch.value = result.result[0]; - } - const result = await userBranch.fetchListMyBranch(uid); - if (result && result.total > 0) currentMyBranch.value = result.result[0]; +function initMenu() { + // TODO: replace mock + const test = [ + { + label: 'หน้าแรก', + labelEN: 'Home Page', + category: 'jws', + page: [ + { + name: 'chapter-01-main', + label: 'หลัก', + labelEN: 'Main', + }, + ], + }, + ]; menuData.value = [ { @@ -185,7 +172,60 @@ onMounted(async () => { { label: 'dashboard', route: '/dash-board' }, ], }, + + { + label: 'menu.manual', + icon: 'mdi-book-open-variant-outline', + children: test.map((m) => ({ + label: locale.value === 'eng' ? m.labelEN : m.label, + route: `/manual/${m.category}`, + noI18n: true, + })), + }, ]; +} + +watch( + () => currentPath.value, + () => { + if (currentPath.value === '/') { + menuActive.value.fill(false); + menuActive.value[0] = true; + } else reActiveMenu(); + }, +); + +watch( + () => props.mini, + () => { + if (props.mini) { + reActiveMenu(); + } + }, +); + +watch( + () => locale.value, + () => { + initMenu(); + }, +); + +onMounted(async () => { + const uid = getUserId(); + + role.value = getRole(); + + if (!uid) return; + + if (role.value.includes('system')) { + const result = await userBranch.fetchListOptionBranch(); + if (result && result.total > 0) currentMyBranch.value = result.result[0]; + } + const result = await userBranch.fetchListMyBranch(uid); + if (result && result.total > 0) currentMyBranch.value = result.result[0]; + + initMenu(); menuActive.value = menuData.value.map(() => false); @@ -266,10 +306,10 @@ onMounted(async () => { style="white-space: nowrap" :style="!menuActive[i] && `color: var(--foreground)`" > - {{ $t(`${menu.label}.title`) }} + {{ menu.noI18n ? menu.label : $t(`${menu.label}.title`) }} - {{ $t(`${menu.label}.title`) }} + {{ menu.noI18n ? menu.label : $t(`${menu.label}.title`) }} { }" > - {{ $t(`${menu.label}.${sub.label}`) }} + {{ + sub.noI18n + ? sub.label + : $t(`${menu.label}.${sub.label}`) + }} + + +