jws-frontend/src/layouts/MainLayout.vue

573 lines
16 KiB
Vue
Raw Normal View History

2024-04-02 11:02:16 +07:00
<script setup lang="ts">
import { ref, onMounted, watch } from 'vue';
2024-04-02 11:02:16 +07:00
import { storeToRefs } from 'pinia';
import { useQuasar } from 'quasar';
2024-07-02 09:11:10 +00:00
import { getUserId, getUsername, logout } from 'src/services/keycloak';
import { Icon } from '@iconify/vue';
import { useI18n } from 'vue-i18n';
2024-04-02 11:02:16 +07:00
import useLoader from 'stores/loader';
import DrawerComponent from 'components/DrawerComponent.vue';
2024-06-07 12:20:57 +00:00
import CanvasComponent from 'components/CanvasComponent.vue';
import ProfileMenu from 'components/ProfileMenu.vue';
import useUserStore from 'src/stores/user';
2024-06-28 14:14:23 +07:00
import FormDialog from 'components/FormDialog.vue';
2024-06-18 11:47:03 +00:00
import useOptionStore from 'src/stores/options';
2024-04-22 14:05:22 +07:00
import { dialog } from 'src/stores/utils';
import { setLocale } from 'src/utils/datetime';
2024-07-02 09:11:10 +00:00
import useUtilsStore from 'src/stores/utils';
2024-07-05 11:10:00 +07:00
import useMyBranchStore from 'src/stores/my-branch';
const useMyBranch = useMyBranchStore();
const { fetchListMyBranch } = useMyBranch;
2024-04-02 11:02:16 +07:00
2024-04-02 17:55:26 +07:00
interface NotificationButton {
item: string;
color: string;
active: boolean;
}
interface Notification {
id: string;
title: string;
content: string;
read: boolean;
}
2024-04-02 11:02:16 +07:00
const $q = useQuasar();
const loaderStore = useLoader();
2024-07-02 09:11:10 +00:00
const utilsStore = useUtilsStore();
2024-06-18 11:47:03 +00:00
const optionStore = useOptionStore();
2024-04-02 11:02:16 +07:00
const { visible } = storeToRefs(loaderStore);
2024-06-28 02:27:01 +00:00
const { t, locale } = useI18n({ useScope: 'global' });
2024-04-22 14:05:22 +07:00
const userStore = useUserStore();
2024-04-02 11:02:16 +07:00
2024-06-24 07:21:36 +00:00
const rawOption = ref();
2024-06-07 12:20:57 +00:00
const canvasModal = ref(false);
2024-07-04 10:39:54 +00:00
2024-07-19 07:00:35 +00:00
const leftDrawerOpen = ref<boolean>(false);
2024-07-04 10:39:54 +00:00
const leftDrawerMini = ref(false);
2024-04-02 17:55:26 +07:00
const filterUnread = ref(false);
const unread = ref<number>(1);
2024-07-02 09:11:10 +00:00
// const filterRole = ref<string[]>();
2024-04-22 17:54:41 +07:00
const userImage = ref<string>();
2024-06-07 12:20:57 +00:00
const canvasRef = ref();
const currentLanguage = ref<string>('ไทย');
const language: {
value: string;
label: string;
2024-04-22 17:54:41 +07:00
icon: string;
date: string;
}[] = [
{ value: 'th-th', label: 'ไทย', icon: 'th', date: 'th' },
{ value: 'en-US', label: 'English', icon: 'us', date: 'en-gb' },
];
2024-04-02 17:55:26 +07:00
const notiOpen = ref(false);
const notiMenu = ref<NotificationButton[]>([
{
item: 'ทั้งหมด',
color: 'noti-switch-on',
active: true,
},
{
item: 'ยังไม่ได้อ่าน',
color: 'noti-switch-off',
active: false,
},
]);
const notification = ref<Notification[]>([
{
id: '1',
2024-04-03 15:01:39 +07:00
title: 'Unread',
content: 'Unread',
2024-04-02 17:55:26 +07:00
read: false,
},
{
id: '2',
title: 'test',
content: 'test',
read: false,
},
2024-04-03 15:01:39 +07:00
{
id: '3',
title: 'Read',
content: 'Already read',
read: true,
},
2024-04-02 17:55:26 +07:00
]);
2024-04-02 17:55:26 +07:00
function setActive(button: NotificationButton) {
notiMenu.value = notiMenu.value.map((current) => ({
item: current.item,
color: current.item !== button.item ? 'noti-switch-off' : 'noti-switch-on',
active: current.item === button.item,
}));
if (button.item === 'ยังไม่ได้อ่าน') {
// noti.value?.result &&
filterUnread.value = true;
}
if (button.item === 'ทั้งหมด') {
filterUnread.value = false;
}
}
2024-04-22 14:05:22 +07:00
function doLogout() {
dialog({
icon: 'mdi-logout-variant',
2024-06-28 02:27:01 +00:00
title: t('confirmLogoutTitle'),
2024-04-22 14:05:22 +07:00
persistent: true,
2024-06-28 02:27:01 +00:00
color: 'negative',
message: t('confirmLogoutMessage'),
2024-04-22 14:05:22 +07:00
action: async () => {
logout();
},
2024-06-28 02:27:01 +00:00
cancel: () => {},
2024-04-22 14:05:22 +07:00
});
}
watch(
() => currentLanguage.value,
() => {
localStorage.setItem('currentLanguage', currentLanguage.value);
2024-06-24 07:21:36 +00:00
if (rawOption.value) {
if (locale.value === 'en-US')
optionStore.globalOption = rawOption.value.eng;
if (locale.value === 'th-th')
optionStore.globalOption = rawOption.value.tha;
}
},
);
onMounted(async () => {
2024-07-05 11:10:00 +07:00
await fetchListMyBranch(getUserId() ?? '');
2024-07-19 07:00:35 +00:00
leftDrawerOpen.value = $q.screen.gt.xs ? true : false;
2024-07-05 11:10:00 +07:00
const getCurLang = localStorage.getItem('currentLanguage');
if (getCurLang) currentLanguage.value = getCurLang;
if (currentLanguage.value === 'English') {
locale.value = 'en-US';
setLocale('en-gb');
}
if (currentLanguage.value === 'ไทย') {
locale.value = 'th-th';
setLocale('th');
}
2024-06-18 11:47:03 +00:00
const resultOption = await fetch('/option/option.json');
2024-06-24 07:21:36 +00:00
rawOption.value = await resultOption.json();
if (locale.value === 'en-US') optionStore.globalOption = rawOption.value.eng;
if (locale.value === 'th-th') optionStore.globalOption = rawOption.value.tha;
2024-06-18 11:47:03 +00:00
const user = getUsername();
const uid = getUserId();
2024-04-23 11:13:57 +00:00
userStore.userOption.roleOpts.length === 0
? await userStore.fetchRoleOption()
: '';
if (user === 'admin') return;
if (uid) {
2024-04-22 14:05:22 +07:00
const res = await userStore.fetchById(uid);
if (res && res.profileImageUrl) userImage.value = res.profileImageUrl;
}
});
2024-04-02 11:02:16 +07:00
</script>
<template>
<q-layout view="lHh Lpr lFf">
2024-07-04 10:39:54 +00:00
<drawer-component
:mini="leftDrawerMini"
v-model:left-drawer-open="leftDrawerOpen"
/>
2024-04-02 17:55:26 +07:00
2024-07-04 11:28:51 +07:00
<q-page-container>
2024-07-02 09:11:10 +00:00
<!-- drawer control -->
2024-07-04 10:39:54 +00:00
<div style="position: relative; z-index: 1000" :hidden="$q.screen.lt.sm">
2024-07-04 09:53:16 +00:00
<div
2024-07-02 09:11:10 +00:00
size="36px"
style="
position: absolute;
2024-07-04 09:53:16 +00:00
border-radius: 50%;
2024-07-02 09:11:10 +00:00
top: 28px;
2024-07-04 09:53:16 +00:00
left: -22px;
2024-07-02 09:11:10 +00:00
background-color: var(--surface-1);
2024-07-04 09:53:16 +00:00
border: 4px solid var(--surface-1);
2024-07-02 09:11:10 +00:00
"
2024-07-04 09:53:16 +00:00
class="flex items-center justify-center"
2024-07-02 09:11:10 +00:00
>
2024-04-02 17:55:26 +07:00
<q-btn
flat
2024-07-02 09:11:10 +00:00
dense
round
size="12px"
aria-label="Menu"
id="btn-open-drawer"
style="
background-color: hsl(var(--negative-bg) / 0.1);
overflow: hidden;
"
2024-07-04 10:39:54 +00:00
@click="leftDrawerMini = !leftDrawerMini"
2024-04-02 17:55:26 +07:00
>
2024-07-02 09:11:10 +00:00
<q-icon
2024-07-04 10:39:54 +00:00
:name="!leftDrawerMini ? 'mdi-backburger' : 'mdi-forwardburger'"
2024-07-02 09:11:10 +00:00
size="16px"
style="color: hsl(var(--negative-bg))"
/>
</q-btn>
2024-07-04 09:53:16 +00:00
</div>
2024-07-02 09:11:10 +00:00
</div>
<div
2024-07-09 11:35:50 +07:00
class="surface-0 scroll column"
style="height: 100vh; flex-wrap: nowrap; padding-bottom: var(--size-4)"
2024-07-02 09:11:10 +00:00
>
<!-- header -->
<div
2024-07-04 10:39:54 +00:00
class="q-px-lg surface-0 row items-center justify-start q-pb-md q-pt-lg"
2024-07-02 09:11:10 +00:00
style="position: sticky; top: 0; z-index: 8"
>
2024-07-04 10:39:54 +00:00
<q-btn
v-if="$q.screen.lt.sm"
icon="mdi-menu"
flat
dense
rounded
class="q-mr-md"
@click="
() => {
leftDrawerMini = false;
leftDrawerOpen = !leftDrawerOpen;
}
"
/>
2024-07-02 09:11:10 +00:00
<div class="column">
2024-07-03 06:45:12 +00:00
<span
class="title-gradient text-weight-bold"
2024-07-03 06:45:12 +00:00
:class="{ 'text-h6': $q.screen.gt.xs }"
2024-07-04 15:45:20 +07:00
:style="{
filter: `brightness(${$q.dark.isActive ? '2' : '1'})`,
}"
2024-07-03 06:45:12 +00:00
>
2024-07-02 09:11:10 +00:00
{{
utilsStore.currentTitle?.title
? $t(utilsStore.currentTitle?.title)
2024-07-03 06:45:12 +00:00
: $q.screen.gt.xs
? 'Welcome to Jobs Worker Service'
: 'Jobs Worker Service'
2024-07-02 09:11:10 +00:00
}}
</span>
2024-07-08 14:08:57 +07:00
<div class="flex items-center" style="gap: var(--size-1)">
2024-07-19 07:00:35 +00:00
<template
v-for="(item, i) in utilsStore.currentTitle.path"
:key="i"
>
2024-07-08 14:08:57 +07:00
<span
class="text-caption cursor-pointer"
@click="item.handler?.()"
2024-07-24 13:55:26 +07:00
:class="{
'text-info': i !== utilsStore.currentTitle.path.length - 1,
'hover-item': i !== utilsStore.currentTitle.path.length - 1,
}"
2024-07-08 14:08:57 +07:00
>
2024-07-08 16:29:37 +07:00
{{
item.text
? $t(item.text, {
...(item.argsi18n || {}),
})
: ''
}}
2024-07-08 14:08:57 +07:00
</span>
<q-icon
2024-07-24 13:55:26 +07:00
:class="{
'text-info': i !== utilsStore.currentTitle.path.length - 1,
}"
2024-07-08 14:08:57 +07:00
name="mdi-chevron-right"
v-if="i + 1 !== utilsStore.currentTitle.path.length"
/>
</template>
</div>
2024-07-02 09:11:10 +00:00
</div>
2024-07-04 10:39:54 +00:00
<div class="row q-gutter-x-md items-center" style="margin-left: auto">
2024-07-02 09:11:10 +00:00
<!-- notification -->
<q-btn
round
dense
flat
class="noti-circle"
2024-07-03 06:45:12 +00:00
:size="$q.screen.lt.sm ? 'sm' : ''"
2024-07-02 09:11:10 +00:00
:class="{ bordered: $q.dark.isActive, dark: $q.dark.isActive }"
style="color: var(--surface-1)"
@click="notiOpen = !notiOpen"
2024-04-02 17:55:26 +07:00
>
2024-07-02 09:11:10 +00:00
<q-icon name="mdi-bell" size="20px" />
<q-badge v-if="unread !== 0" rounded floating color="negative">
{{ unread }}
</q-badge>
<q-menu
:offset="[0, 10]"
anchor="bottom middle"
self="top middle"
@before-hide="notiOpen = false"
>
<div class="q-px-md q-py-sm row col-12 items-center">
<div class="text-subtitle1 text-weight-bold">แจงเตอน</div>
<q-space />
</div>
<div class="q-px-md q-pb-md q-gutter-x-md">
<q-btn
rounded
padding="0px 10px"
class="text-weight-medium"
v-for="(btn, index) in notiMenu"
:flat="!btn.active"
:unelevated="btn.active"
:key="index"
:label="btn.item"
:class="btn.color"
@click="setActive(btn)"
/>
</div>
<q-infinite-scroll :offset="250">
<div class="caption cursor-pointer">
<q-item
dense
clickable
class="q-py-sm"
v-ripple
v-for="item in !filterUnread
? notification
: notification.filter((v) => !v.read)"
:key="item.id"
2024-04-02 17:55:26 +07:00
>
2024-07-02 09:11:10 +00:00
<q-avatar
color="positive"
style="height: 30px; width: 30px"
>
<q-icon color="white" name="mdi-check" />
</q-avatar>
<div class="col-6 column text-caption q-pl-md ellipsis">
<span
class="block ellipsis full-width text-weight-bold"
>
{{ item.title }}
</span>
<span class="block ellipsis full-width text-stone">
{{ item.content }}
</span>
</div>
<span align="right" class="col text-caption text-stone">
<!-- {{ moment(item.createdAt).fromNow() }} -->
5 s
2024-04-02 17:55:26 +07:00
</span>
2024-07-02 09:11:10 +00:00
<q-tooltip
anchor="top middle"
self="bottom middle"
:delay="1000"
:offset="[10, 10]"
>
2024-04-02 17:55:26 +07:00
{{ item.content }}
2024-07-02 09:11:10 +00:00
</q-tooltip>
</q-item>
</div>
<!-- <template v-slot:loading>
2024-04-02 17:55:26 +07:00
<div
class="text-center q-my-md"
v-if="noti && noti?.result.length < noti?.total"
>
<q-spinner-dots color="primary" size="40px" />
</div>
</template> -->
2024-07-02 09:11:10 +00:00
</q-infinite-scroll>
</q-menu>
</q-btn>
<!-- เปลนนภาษา -->
<q-btn
round
unelevated
2024-07-03 06:45:12 +00:00
:size="$q.screen.lt.sm ? 'sm' : ''"
2024-07-02 09:11:10 +00:00
v-model="currentLanguage"
class="no-uppercase"
>
2024-07-02 09:11:10 +00:00
<Icon
v-if="currentLanguage === 'English'"
icon="circle-flags:us"
2024-07-03 06:45:12 +00:00
:width="$q.screen.lt.sm ? '28px' : '36px'"
2024-07-02 09:11:10 +00:00
/>
<Icon
v-else
icon="circle-flags:th"
2024-07-03 06:45:12 +00:00
:width="$q.screen.lt.sm ? '28px' : '36px'"
2024-07-02 09:11:10 +00:00
/>
<q-menu
:offset="[0, 10]"
fit
anchor="bottom left"
self="top left"
auto-close
>
<q-list v-for="v in language" :key="v.value">
<q-item
v-if="!v.label.includes(currentLanguage)"
clickable
@click="
locale = v.value;
currentLanguage = v.label;
setLocale(v.date);
"
>
<q-item-section>
<div class="row items-center">
<Icon
:icon="`circle-flags:${v.icon}`"
class="q-mr-md"
/>
{{ v.label }}
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
<!-- User -->
<ProfileMenu
@logout="doLogout"
@edit-personal-info="console.log('edit')"
@signature="
() => {
canvasModal = true;
}
"
/>
</div>
2024-04-02 17:55:26 +07:00
</div>
2024-04-02 11:02:16 +07:00
2024-07-03 06:45:12 +00:00
<q-page class="col q-px-lg">
2024-07-02 09:11:10 +00:00
<router-view />
</q-page>
</div>
2024-04-02 11:02:16 +07:00
</q-page-container>
2024-06-07 12:20:57 +00:00
<FormDialog
2024-06-25 07:13:13 +00:00
width="800px"
height="550px"
2024-06-07 12:20:57 +00:00
v-model:modal="canvasModal"
no-app-box
2024-06-25 07:13:13 +00:00
:title="$t('addSignature')"
:close="() => (canvasModal = false)"
2024-06-07 12:20:57 +00:00
>
<CanvasComponent ref="canvasRef" v-model:modal="canvasModal" />
<template #footer>
<q-btn
flat
dense
:label="$t('clear')"
2024-06-27 03:01:19 +00:00
@click="
() => {
canvasRef.clearCanvas(), canvasRef.clearUpload();
}
"
style="color: hsl(var(--text-mute))"
2024-06-07 12:20:57 +00:00
/>
</template>
</FormDialog>
2024-04-02 11:02:16 +07:00
<global-loading :visibility="visible" />
</q-layout>
</template>
2024-04-02 17:55:26 +07:00
<style scoped>
.text-stone {
--_color: var(--stone-5);
color: var(--_color);
}
.noti-circle {
--_color: var(--stone-5);
background-color: var(--_color);
&.dark {
--_color: var(--stone-9);
}
}
.noti-switch-on {
2024-04-03 15:01:39 +07:00
--_color: var(--blue-6-hsl);
background-color: hsla(var(--_color) / 0.1) !important;
color: hsl(var(--_color));
2024-04-02 17:55:26 +07:00
}
.noti-switch-off {
--_color: var(--stone-6);
color: var(--_color);
}
.account-menu-down {
& ::before {
color: var(--foreground);
}
}
2024-04-22 17:54:41 +07:00
.badge {
display: inline-block;
border-radius: var(--radius-6);
background-color: var(--indigo-0);
text-wrap: nowrap;
&.dark {
background-color: var(--surface-3);
}
}
.account-cover {
height: 65px;
background-color: var(--indigo-0);
&.dark {
background-color: var(--surface-3);
}
}
.avartar-border {
margin-top: 24px;
border: 5px solid var(--surface-1);
border-radius: 50%;
position: absolute;
}
.logout-btn {
color: hsl(var(--negative-bg));
background-color: hsl(var(--stone-3-hsl));
&.dark {
background-color: transparent;
border: 1px solid hsl(var(--negative-bg));
}
}
2024-07-02 09:11:10 +00:00
.title-gradient {
background: linear-gradient(to right, var(--brand-1), var(--brand-2));
background-clip: text; /* Standard property */
-webkit-background-clip: text; /* WebKit fallback */
-webkit-text-fill-color: transparent; /* WebKit fallback */
color: transparent; /* Fallback for browsers not supporting text-clip */
}
2024-07-02 09:11:10 +00:00
:deep(main.q-page) {
min-height: 0 !important;
}
2024-07-24 13:55:26 +07:00
.hover-item:hover {
text-decoration: underline;
}
2024-04-02 17:55:26 +07:00
</style>