jws-frontend/src/components/DrawerComponent.vue

297 lines
6.7 KiB
Vue
Raw Normal View History

2024-04-02 11:02:16 +07:00
<script setup lang="ts">
2024-07-10 13:21:32 +07:00
import { computed, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
2024-07-10 13:21:32 +07:00
import { storeToRefs } from 'pinia';
2024-04-05 17:58:34 +07:00
import { Icon } from '@iconify/vue';
2024-07-10 13:21:32 +07:00
import useMyBranch from 'stores/my-branch';
import { getUserId, getRole } from 'src/services/keycloak';
2024-04-03 14:21:02 +07:00
2024-07-04 09:53:16 +00:00
defineProps<{
mini?: boolean;
}>();
2024-07-10 13:21:32 +07:00
onMounted(async () => {
const uid = getUserId();
const role = getRole();
if (!uid) return;
if (role?.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];
});
const router = useRouter();
2024-07-10 13:21:32 +07:00
const userBranch = useMyBranch();
const { currentMyBranch } = storeToRefs(userBranch);
2024-04-02 11:02:16 +07:00
const currentRoute = ref<string>('');
2024-07-02 10:15:29 +00:00
const currentPath = computed(() => {
return router.currentRoute.value.path;
});
2024-04-03 14:21:02 +07:00
2024-07-01 11:14:01 +07:00
const labelMenu = ref<
2024-08-08 02:16:50 +00:00
{
label: string;
icon: string;
route: string;
disabled?: boolean;
isax?: boolean;
}[]
2024-07-01 11:14:01 +07:00
>([
2024-04-03 14:21:02 +07:00
{
label: 'drawerDashboard',
2024-08-08 02:16:50 +00:00
icon: 'isax-element-35',
2024-07-03 03:39:02 +00:00
route: '',
2024-08-08 02:16:50 +00:00
isax: true,
2024-07-03 03:39:02 +00:00
disabled: true,
2024-04-03 14:21:02 +07:00
},
{
2024-04-03 14:21:02 +07:00
label: 'drawerBranchManagement',
2024-08-08 02:16:50 +00:00
icon: 'mdi-chart-donut',
route: '/branch-management',
},
{
2024-04-03 14:21:02 +07:00
label: 'drawerPersonnelManagement',
2024-08-08 02:16:50 +00:00
icon: 'isax-frame5',
route: '/personnel-management',
2024-08-08 02:16:50 +00:00
isax: true,
},
2024-04-03 14:21:02 +07:00
{
label: 'drawerCustomerManagement',
2024-08-08 02:16:50 +00:00
icon: 'isax-frame5',
route: '/customer-management',
2024-08-08 02:16:50 +00:00
isax: true,
2024-04-03 14:21:02 +07:00
},
{
label: 'drawerProductsAndServices',
2024-08-08 02:16:50 +00:00
icon: 'heroicons-truck-solid',
2024-06-10 16:42:40 +07:00
route: '/product-service',
2024-04-03 14:21:02 +07:00
},
2024-07-01 11:14:01 +07:00
{
label: 'drawerQuotation',
2024-08-08 02:16:50 +00:00
icon: 'mdi-file-document',
2024-07-01 11:14:01 +07:00
route: '',
disabled: true,
},
{
label: 'drawerRequestList',
2024-08-08 02:16:50 +00:00
icon: 'isax-device-message5',
2024-07-01 11:14:01 +07:00
route: '',
disabled: true,
2024-08-08 02:16:50 +00:00
isax: true,
2024-07-01 11:14:01 +07:00
},
{
label: 'drawerWorkOrder',
2024-08-08 02:16:50 +00:00
icon: 'isax-receipt-2-15',
2024-07-01 11:14:01 +07:00
route: '',
disabled: true,
2024-08-08 02:16:50 +00:00
isax: true,
2024-07-01 11:14:01 +07:00
},
{
label: 'drawerInvoice',
2024-08-08 02:16:50 +00:00
icon: 'material-symbols:box',
2024-07-01 11:14:01 +07:00
route: '',
disabled: true,
},
2024-04-03 14:21:02 +07:00
{
label: 'drawerAccountingLedger',
2024-08-08 02:16:50 +00:00
icon: 'isax-dollar-circle4',
2024-04-03 14:21:02 +07:00
route: '',
2024-08-08 02:16:50 +00:00
isax: true,
2024-07-01 11:14:01 +07:00
disabled: true,
},
{
label: 'drawerReport',
2024-08-08 02:16:50 +00:00
icon: 'mdi-file-document',
2024-07-01 11:14:01 +07:00
route: '',
disabled: true,
2024-04-03 14:21:02 +07:00
},
]);
2024-04-02 11:02:16 +07:00
const leftDrawerOpen = defineModel<boolean>('leftDrawerOpen', {
2024-07-04 09:53:16 +00:00
default: true,
2024-04-02 11:02:16 +07:00
});
function navigateTo(label: string, destination: string) {
currentRoute.value = label;
router.push(`${destination}`);
}
2024-07-04 07:43:50 +00:00
function branchSetting() {}
2024-04-02 11:02:16 +07:00
</script>
<template>
<!-- Drawer -->
<q-drawer
2024-07-04 10:39:54 +00:00
no-swipe-open
v-model="leftDrawerOpen"
side="left"
2024-07-02 09:11:10 +00:00
:breakpoint="599"
2024-07-04 07:43:50 +00:00
class="column justify-between no-wrap"
2024-07-31 06:09:10 +00:00
:class="{ dark: $q.dark.isActive }"
2024-07-05 16:29:06 +07:00
:width="mini ? 80 : 256"
2024-07-08 10:44:36 +07:00
show-if-above
>
2024-07-04 09:53:16 +00:00
<!-- :width="$q.screen.lt.sm ? $q.screen.width - 16 : 256" -->
2024-07-05 16:29:06 +07:00
<div class="scroll" style="overflow-x: hidden; scrollbar-gutter: stable">
2024-07-04 07:43:50 +00:00
<div
2024-07-05 16:29:06 +07:00
class="flex justify-center items-center q-pl-sm cursor-pointer"
2024-07-04 07:43:50 +00:00
@click="$router.push('/')"
id="btn-drawer-home"
2024-07-04 09:53:16 +00:00
style="height: 128px"
2024-07-04 07:43:50 +00:00
>
2024-07-04 15:22:59 +07:00
<q-img
2024-07-04 09:53:16 +00:00
fit="contain"
:src="mini ? 'logo_jws.png' : '/logo.png'"
2024-07-04 15:22:59 +07:00
:style="{ filter: `brightness(${$q.dark.isActive ? '1.3' : '1'})` }"
2024-07-04 09:53:16 +00:00
style="height: 64px"
2024-07-04 15:22:59 +07:00
/>
2024-07-04 07:43:50 +00:00
</div>
2024-07-05 16:29:06 +07:00
<div id="drawer-menu" class="q-pl-md q-mr-xs">
2024-07-04 07:43:50 +00:00
<q-item
v-for="v in labelMenu"
dense
clickable
2024-07-05 16:29:06 +07:00
class="row items-center q-my-xs q-px-xs"
2024-07-04 09:53:16 +00:00
:key="v.label"
2024-07-04 07:43:50 +00:00
:disable="!!v.disabled"
:class="{
active: currentPath === v.route,
'border-active': currentPath === v.route,
dark: $q.dark.isActive,
}"
@click="navigateTo(v.label, v.route)"
>
2024-07-04 09:53:16 +00:00
<div class="row justify-center items-center">
2024-08-08 02:16:50 +00:00
<i
v-if="v.isax"
:class="`isax ${v.icon}`"
style="font-size: 24px"
/>
<Icon v-else :icon="v.icon" width="24px" />
2024-07-04 09:53:16 +00:00
<q-tooltip v-if="mini">
2024-07-04 07:43:50 +00:00
{{ $t(v.label) }}
2024-07-04 09:53:16 +00:00
</q-tooltip>
</div>
<div v-if="!mini" class="q-ml-md" style="white-space: nowrap">
{{ $t(v.label) }}
</div>
2024-07-04 07:43:50 +00:00
</q-item>
</div>
2024-04-02 11:02:16 +07:00
</div>
2024-07-04 09:53:16 +00:00
<div
class="surface-2 q-px-md q-py-sm row items-center no-wrap justify-start"
:class="{ 'justify-center': mini }"
style="min-height: 56px; overflow-x: hidden"
>
<q-avatar
text-color="white"
size="md"
:style="`background-color: hsla(var(--violet-${$q.dark.isActive ? '10' : '11'}-hsl)/0.15)`"
class="relative-position"
>
<q-icon
name="mdi-home-group"
size="sm"
:style="`color: var(--violet-${$q.dark.isActive ? '10' : '11'})`"
/>
<div class="dot absolute-bottom-right" />
</q-avatar>
<div
v-if="!mini"
class="text-caption column q-ml-sm"
style="white-space: nowrap"
>
<span class="text-weight-bold">
2024-07-10 13:21:32 +07:00
{{
($i18n.locale === 'en-US'
? currentMyBranch?.nameEN
: currentMyBranch?.name) ?? '-'
}}
2024-07-04 09:53:16 +00:00
</span>
<span>
2024-07-10 13:21:32 +07:00
{{ currentMyBranch?.code ?? '-' }}
2024-07-04 09:53:16 +00:00
</span>
2024-07-04 07:43:50 +00:00
</div>
2024-07-04 09:53:16 +00:00
2024-07-04 07:43:50 +00:00
<q-btn
2024-07-04 09:53:16 +00:00
v-if="!mini"
2024-07-04 07:43:50 +00:00
dense
flat
rounded
icon="mdi-cog-outline"
size="sm"
@click="branchSetting"
2024-07-04 09:53:16 +00:00
style="margin-left: auto"
/>
2024-04-02 11:02:16 +07:00
</div>
</q-drawer>
</template>
<style lang="scss" scoped>
#drawer-menu :deep(.q-item) {
2024-07-24 03:03:00 +00:00
color: var(--gray-7);
2024-07-04 07:43:50 +00:00
border-radius: var(--radius-2);
2024-08-01 02:55:21 +00:00
&.dark {
color: var(--gray-3);
}
2024-04-02 11:02:16 +07:00
}
2024-08-01 02:55:21 +00:00
2024-04-02 11:02:16 +07:00
#drawer-menu :deep(.q-item.active) {
--_drawer-item-background-color: var(--brand-1) !important;
2024-04-09 14:52:53 +07:00
background-color: var(--_drawer-item-background-color);
2024-04-02 11:02:16 +07:00
color: white;
2024-07-04 07:43:50 +00:00
// border-left: 10px solid $secondary;
2024-04-02 11:02:16 +07:00
}
2024-07-04 13:16:28 +07:00
2024-07-04 07:43:50 +00:00
#drawer-menu :deep(.q-item.active)::before {
display: block;
position: absolute;
content: ' ';
background: var(--brand-2);
border-radius: 99rem;
width: 6px;
2024-07-04 09:53:16 +00:00
left: -0.6rem;
2024-07-04 07:43:50 +00:00
top: 18%;
bottom: 18%;
cursor: context-menu;
}
2024-07-04 09:53:16 +00:00
:deep(.q-drawer) {
transition: 0.1s width ease-in-out;
2024-07-04 10:39:54 +00:00
background-color: transparent;
2024-07-04 09:53:16 +00:00
padding: var(--size-4);
padding-right: 0;
}
:deep(.q-drawer__content) {
border-radius: var(--radius-2);
2024-07-31 06:09:10 +00:00
background-color: rgba(255, 255, 255, 0.5);
backdrop-filter: blur(11.2px);
-webkit-backdrop-filter: blur(11.2px);
&.dark {
background-color: hsla(var(--gray-10-hsl) / 0.5);
}
2024-07-04 09:53:16 +00:00
}
2024-07-04 07:43:50 +00:00
.dot {
height: 10px;
width: 10px;
background-color: var(--teal-6);
border-radius: 50%;
display: inline-block;
border: 1.5px solid white;
}
2024-04-02 11:02:16 +07:00
</style>