hrms-user/src/views/MainLayout.vue

457 lines
13 KiB
Vue
Raw Normal View History

2023-07-07 16:54:53 +07:00
<script setup lang="ts">
2023-09-08 13:31:48 +07:00
import http from "@/plugins/http";
import config from "@/app.config";
import { onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useQuasar } from "quasar";
import keycloak from "@/plugins/keycloak";
import { useCounterMixin } from "@/stores/mixin";
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
const route = useRoute();
const router = useRouter();
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
const $q = useQuasar();
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
const mixin = useCounterMixin();
2024-01-18 11:36:19 +07:00
const {
date2Thai,
dialogRemove,
showLoader,
hideLoader,
messageError,
success,
} = mixin;
2023-09-08 13:31:48 +07:00
const fullname = ref<string>("");
const notiList = ref<any>([]);
const notiTrigger = ref(false);
const currentRouteName = router.currentRoute.value.name;
const tab = ref<any>(currentRouteName);
2023-09-08 13:31:48 +07:00
const link = ref<string>("");
2023-07-07 16:54:53 +07:00
2023-08-08 14:03:12 +07:00
/**
* เรยกฟงกนทงหมดตอนเรยกใชไฟล
*/
onMounted(async () => {
2024-01-18 11:36:19 +07:00
await fetchlistNotification(1, "NOMAL");
2023-09-08 13:31:48 +07:00
if (keycloak.tokenParsed != null) {
fullname.value = keycloak.tokenParsed.name;
}
});
2024-01-18 11:36:19 +07:00
const fetchlistNotification = async (index: number, type: string) => {
2023-09-08 13:31:48 +07:00
await http
.get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`)
2023-09-08 13:31:48 +07:00
.then((res: any) => {
const data = res.data.result.data;
2024-01-18 11:36:19 +07:00
2023-09-08 13:31:48 +07:00
let list: any[] = [];
2024-01-18 11:36:19 +07:00
if (type === "DEL") {
totalInbox.value = res.data.result.total;
console.log(notiList.value.length);
if (notiList.value.length === 14) {
notiList.value = [];
data.map((e: any) => {
list.push({
id: e.id,
sender:
e.createdFullName == "" || e.createdFullName == null
? "เจ้าหน้าที่"[0]
: e.createdFullName[0],
body: e.body ?? "",
timereceive: date2Thai(e.createdAt),
});
});
notiList.value.push(...list);
}
} else {
data.map((e: any) => {
list.push({
id: e.id,
sender:
e.createdFullName == "" || e.createdFullName == null
? "เจ้าหน้าที่"[0]
: e.createdFullName[0],
body: e.body ?? "",
timereceive: date2Thai(e.createdAt),
});
2023-09-08 13:31:48 +07:00
});
2024-01-18 11:36:19 +07:00
notiList.value.push(...list);
totalInbox.value = res.data.result.total;
}
2023-09-08 13:31:48 +07:00
})
.catch((err) => {
console.log(err);
});
};
2023-08-08 14:03:12 +07:00
/**
* logout keycloak
* confirm อนออกจากระบบ
*/
const doLogout = () => {
2023-09-08 13:31:48 +07:00
$q.dialog({
title: "ยืนยันการออกจากระบบ",
message: `ต้องการออกจากระบบใช้หรือไม่?`,
cancel: "ยกเลิก",
ok: "ยืนยัน",
persistent: true,
}).onOk(() => {
keycloak.logout();
});
};
2024-01-18 11:36:19 +07:00
const clickDelete = async (id: string, index: number) => {
dialogRemove($q, async () => {
showLoader();
await http
.delete(config.API.msgId(id))
.then(() => {
notiList.value.splice(index, 1);
success($q, "ลบข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
fetchlistNotification(1, "DEL");
hideLoader();
});
});
};
const totalInbox = ref<number>(0);
2024-01-18 11:36:19 +07:00
const page = ref<number>(1);
function onLoad(index: any, done: any) {
2024-01-18 11:36:19 +07:00
page.value = index + 1;
if (notiList.value.length < totalInbox.value) {
setTimeout(() => {
2024-01-18 11:36:19 +07:00
fetchlistNotification(page.value, "NOMAL");
done();
}, 2000);
}
}
2023-07-07 16:54:53 +07:00
</script>
<!-- โครงเว -->
<template>
2023-09-08 13:31:48 +07:00
<q-layout view="hHh LpR fFr">
<!-- header -->
<q-header flat class="text-dark col-12 bg-top header-br" height-hint="7">
<q-toolbar
class="q-my-xs items-center"
:style="$q.screen.gt.xs ? 'padding: 1% 2%;' : 'padding: 1% 4%;'"
>
2023-09-08 13:31:48 +07:00
<div class="row items-center no-wrap" v-if="$q.screen.gt.xs">
<q-img
src="@/assets/logo.png"
spinner-color="white"
style="height: 35px; max-width: 35px"
/>
2023-09-08 13:31:48 +07:00
<div class="row q-ml-md items-center q-pt-xs">
<div
style="color: #ffffff; letter-spacing: 1px; line-height: 10px"
class="text-body2 text-weight-bolder col-12"
>
2023-09-08 13:31:48 +07:00
ระบบ<span class="text-primary">ทรพยากรบคคล</span>
</div>
<div class="text-caption text-white">กรงเทพมหานคร</div>
</div>
</div>
<div v-else class="row items-center">
<img src="@/assets/logo.png" style="height: 35px; max-width: 35px" />
</div>
<div v-if="$q.screen.gt.xs">
<q-tabs
v-model="tab"
align="justify"
indicator-color="transparent"
active-color="white bg-white-btn border-100"
dense
inline-label
class="text-grey-5 tabsHome"
>
<q-tab
class="border-100 q-mr-sm"
name="dashboard"
label="หน้าแรก"
icon="mdi-view-dashboard-outline"
@click="router.push(`/`)"
/>
<!-- <q-tab class="border-100" name="Checkin" label="ลงเวลางาน" icon="mdi-map-marker-check-outline"
@click="router.push(`/check-in`)" /> -->
<q-tab
class="border-100 q-mr-sm"
name="leave"
label="การลา"
icon="mdi-calendar-blank-outline"
@click="router.push(`/leave`)"
/>
2023-09-08 13:31:48 +07:00
</q-tabs>
</div>
<q-space />
<!-- Notification -->
<q-btn
round
dense
flat
size="13px"
:class="$q.screen.gt.xs ? 'bg-white-btn q-mx-md' : 'q-mr-sm'"
:color="notiList.length === 0 ? 'grey-6' : 'grey-8'"
:disable="notiList.length === 0"
>
2023-09-08 13:31:48 +07:00
<q-icon name="mdi-bell-outline" size="22px" color="white" />
<q-badge
rounded
v-show="notiList.length > 0"
color="negative"
text-color="white"
floating
>{{ totalInbox }}</q-badge
>
<q-menu v-model="notiTrigger" :offset="[0, 10]">
2023-09-08 13:31:48 +07:00
<div class="q-px-md q-py-sm row col-12 items-center">
<div class="text-subtitle1 text-weight-medium">การแจงเตอน</div>
<q-space />
2024-01-18 11:36:19 +07:00
<!-- <q-btn
label="ล้างข้อมูล"
color="pink"
dense
class="text-caption"
flat
2024-01-18 11:36:19 +07:00
/> -->
2023-09-08 13:31:48 +07:00
</div>
2023-07-07 16:54:53 +07:00
2024-01-18 11:36:19 +07:00
<q-infinite-scroll @load="onLoad" :offset="250">
<div
v-for="(item, index) in notiList"
:key="index"
class="caption"
style="max-width: 480px"
>
<q-item v-ripple class="mytry q-py-sm" dense>
<q-item-section avatar top style="min-width: 10px">
<q-avatar
rounded
color="primary"
size="25px"
text-color="white"
>
<span class="text-weight-medium text-uppercase">{{
item.sender[0]
}}</span>
</q-avatar>
</q-item-section>
<q-item-section>
<q-item-label caption class="text-black">{{
item.body
}}</q-item-label>
<q-item-label
caption
class="row items-center text-grey-7"
style="font-size: 12px"
>{{ item.timereceive }}</q-item-label
>
</q-item-section>
<div>
<q-btn
size="sm"
unelevated
dense
icon="mdi-close"
class="mybtn q-mx-xs"
2024-01-18 11:36:19 +07:00
@click="clickDelete(item.id, index)"
></q-btn>
</div>
</q-item>
</div>
2024-01-18 11:36:19 +07:00
<template
v-slot:loading
v-if="notiList.length < totalInbox || notiList.length !== 19"
>
<div class="row justify-center q-my-md">
<q-spinner-dots color="primary" size="40px" />
</div>
</template>
</q-infinite-scroll>
2023-09-08 13:31:48 +07:00
</q-menu>
</q-btn>
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
<!-- User -->
<q-btn-dropdown
v-if="$q.screen.gt.xs"
rounded
dense
flat
:class="$q.screen.gt.xs ? 'bg-white-btn' : ''"
color="white"
class="q-pr-sm border-10"
dropdown-icon="mdi-chevron-down"
>
2023-09-08 13:31:48 +07:00
<template v-slot:label>
<q-item dense v-close-popup class="q-pa-none q-pl-xs">
<q-item-section avatar class="q-pa-none" style="min-width: 30px">
<q-img
src="@/assets/avatar_user.jpg"
class="border-100"
spinner-color="white"
style="height: 30px; max-width: 30px"
/>
2023-09-08 13:31:48 +07:00
</q-item-section>
<q-item-section class="text-left text-white q-pa-none q-pl-sm">
<q-item-label class="text-caption text-weight-medium">{{
fullname
}}</q-item-label>
</q-item-section>
</q-item>
</template>
<q-list>
<q-item clickable v-close-popup>
<q-item-section avatar style="min-width: 30px">
<q-icon color="orange-9" size="18px" name="mdi-lock-outline" />
</q-item-section>
<q-item-section
><q-item-label>เปลยนรหสผาน</q-item-label></q-item-section
>
2023-09-08 13:31:48 +07:00
</q-item>
2023-07-07 16:54:53 +07:00
<q-item clickable v-close-popup @click="doLogout">
2023-09-08 13:31:48 +07:00
<q-item-section avatar style="min-width: 30px">
<q-icon color="primary" size="18px" name="mdi-logout-variant" />
</q-item-section>
<q-item-section>
<q-item-label>ออกจากระบบ</q-item-label>
</q-item-section>
2023-09-08 13:31:48 +07:00
</q-item>
</q-list>
</q-btn-dropdown>
<div v-else class="q-ml-sm" style="width: 30px">
<q-img
src="@/assets/avatar_user.jpg"
class="border-100"
spinner-color="white"
style="height: 30px; max-width: 30px"
/>
2023-09-08 13:31:48 +07:00
</div>
</q-toolbar>
</q-header>
<div
class="bg-top"
:style="$q.screen.gt.xs ? 'height: 200px;' : 'height: 200px;'"
/>
2023-09-08 13:31:48 +07:00
<!-- end header -->
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
<q-footer class="bg-top" v-if="!$q.screen.gt.xs">
<q-toolbar style="padding: 2% 2%">
<div class="row col-12 justify-around">
<q-btn
flat
round
color="white"
icon="mdi-view-dashboard-outline"
@click="router.push(`/`)"
/>
<q-btn
flat
round
color="white"
icon="mdi-map-marker-check-outline"
@click="router.push(`/check-in`)"
/>
<q-btn
flat
round
color="white"
icon="mdi-calendar-blank-outline"
@click="router.push(`/leave`)"
/>
2023-09-08 13:31:48 +07:00
<q-btn flat round color="white" icon="mdi-account-outline" />
</div>
</q-toolbar>
</q-footer>
2023-07-07 16:54:53 +07:00
2023-09-08 13:31:48 +07:00
<q-page-container class="bg-grey-2 q-pb-md">
<q-page
:style="
$q.screen.gt.xs
? 'padding: 1.8% 2%; margin-top: -200px;'
: 'padding: 5% 4%; margin-top: -200px;'
"
>
2023-09-08 13:31:48 +07:00
<router-view :key="$route.fullPath" />
</q-page>
</q-page-container>
</q-layout>
2023-07-07 16:54:53 +07:00
</template>
<style>
2023-08-08 14:03:12 +07:00
.bg-drawer {
2023-09-08 13:31:48 +07:00
background: #242a3d;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.menu {
2023-09-08 13:31:48 +07:00
padding-bottom: 5px;
padding-top: 5px;
2023-07-07 16:54:53 +07:00
}
2023-08-08 14:03:12 +07:00
.tabsHome .q-tab__icon {
2023-09-08 13:31:48 +07:00
font-size: 18px;
2023-07-07 16:54:53 +07:00
}
2023-08-08 14:03:12 +07:00
.border-100 {
2023-09-08 13:31:48 +07:00
border-radius: 100px;
2023-07-07 16:54:53 +07:00
}
2023-08-08 14:03:12 +07:00
.bg-top {
2023-09-08 13:31:48 +07:00
background: #273238;
2023-07-07 16:54:53 +07:00
}
2023-08-08 14:03:12 +07:00
.header-br {
2023-09-08 13:31:48 +07:00
border-bottom: 1px solid #fdfdfd31;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.menuActive {
2023-09-08 13:31:48 +07:00
background: #1e2234;
border-radius: 0 100px 100px 0;
margin-right: 4%;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.q-card {
2023-09-08 13:31:48 +07:00
box-shadow: 3px 3px 20px -10px rgba(151, 150, 150, 0.261) !important;
/* border: 1px solid #eeeded; */
border-radius: 8px;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.q-menu {
2023-09-08 13:31:48 +07:00
box-shadow: 3px 3px 10px 1px rgba(95, 95, 95, 0.15) !important;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.toptitle {
2023-09-08 13:31:48 +07:00
font-size: 1.2rem;
font-weight: bold;
margin-bottom: 1.2%;
2023-07-07 16:54:53 +07:00
}
2023-08-08 14:03:12 +07:00
.q-field--outlined .q-field__control {
2023-09-08 13:31:48 +07:00
border-radius: 5px;
2023-07-07 16:54:53 +07:00
}
2023-07-07 16:54:53 +07:00
.q-field--outlined .q-field__control:before {
2023-09-08 13:31:48 +07:00
border-color: #c8d3db;
2023-07-07 16:54:53 +07:00
}
/* .q-field--outlined .q-icon {
2023-09-08 13:31:48 +07:00
color: #7474747f;
} */
.shadow-0 {
box-shadow: none !important;
}
.btnBlue {
background-color: #016987;
color: #fff;
}
2023-07-07 16:54:53 +07:00
</style>