การแจ้งเตือน

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-01-18 12:00:52 +07:00
parent 60d67f2720
commit af4c2eadcd

View file

@ -54,14 +54,7 @@ const role = ref<string[]>([]);
const notiTrigger = ref<boolean>(false); const notiTrigger = ref<boolean>(false);
const text = ref<string>(""); const text = ref<string>("");
const notiList = ref<notiType[]>([ const notiList = ref<notiType[]>([]);
{
id: "1",
sender: "ท",
body: "ขอแก้ไขข้อมูลทะเบียนประวัติ",
timereceive: new Date(),
},
]);
const options = ref<optionType[]>([ const options = ref<optionType[]>([
{ {
icon: "mdi-account-cog", icon: "mdi-account-cog",
@ -83,14 +76,18 @@ const options = ref<optionType[]>([
}, },
]); ]);
const getDataNotification = async (index: number) => { const getDataNotification = async (index: number, type: string) => {
// showLoader(); // showLoader();
await http await http
.get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`) .get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`)
.then((res: any) => { .then((res: any) => {
const response = res.data.result.data; const response = res.data.result.data;
totalInbox.value = res.data.result.total;
let list: notiType[] = []; let list: notiType[] = [];
if (type === "DEL") {
totalInbox.value = res.data.result.total;
if (notiList.value.length === 16) {
notiList.value = [];
response.map((e: any) => { response.map((e: any) => {
list.push({ list.push({
id: e.id, id: e.id,
@ -103,9 +100,25 @@ const getDataNotification = async (index: number) => {
}); });
}); });
notiList.value.push(...list); notiList.value.push(...list);
}
} else {
response.map((e: any) => {
list.push({
id: e.id,
sender:
e.createdFullName == "" || e.createdFullName == null
? "เจ้าหน้าที่"[0]
: e.createdFullName[0],
body: e.body ?? "",
timereceive: new Date(e.receiveDate),
});
});
notiList.value.push(...list);
totalInbox.value = res.data.result.total;
}
}) })
.catch((e) => { .catch((e) => {
// messageError($q, e); messageError($q, e);
}) })
.finally(() => { .finally(() => {
// hideLoader(); // hideLoader();
@ -219,7 +232,7 @@ onMounted(async () => {
await fetchroleUser(keycloak.tokenParsed.role); await fetchroleUser(keycloak.tokenParsed.role);
} }
await getDataNotification(1); await getDataNotification(1, "NOMAL");
myEventHandler(null, false); myEventHandler(null, false);
window.addEventListener("resize", (e: any) => { window.addEventListener("resize", (e: any) => {
myEventHandler(e, true); myEventHandler(e, true);
@ -410,32 +423,30 @@ if (keycloak.tokenParsed != null) {
role.value = keycloak.tokenParsed.role; role.value = keycloak.tokenParsed.role;
} }
const deleteData = async (id: string) => { const clickDelete = async (id: string, index: number) => {
console.log("delete=", id); dialogRemove($q, async () => {
showLoader(); showLoader();
await http await http
.delete(config.API.msgId(id)) .delete(config.API.msgId(id))
.then((res) => { .then(() => {
notiList.value.splice(index, 1);
success($q, "ลบข้อมูลสำเร็จ"); success($q, "ลบข้อมูลสำเร็จ");
}) })
.catch((e) => { .catch((e) => {
messageError($q, e); messageError($q, e);
}) })
.finally(async () => { .finally(async () => {
getDataNotification(1); getDataNotification(1, "DEL");
hideLoader(); hideLoader();
}); });
}; });
const clickDelete = (id: string) => {
dialogRemove($q, () => deleteData(id));
}; };
const totalInbox = ref<number>(0); const totalInbox = ref<number>(0);
function onLoad(index: any, done: any) { function onLoad(index: any, done: any) {
if (notiList.value.length < totalInbox.value) { if (notiList.value.length < totalInbox.value) {
setTimeout(() => { setTimeout(() => {
getDataNotification(index + 1); getDataNotification(index + 1, "NOMAL");
done(); done();
}, 2000); }, 2000);
} }
@ -510,8 +521,8 @@ function onLoad(index: any, done: any) {
> >
<q-list <q-list
style="min-width: 300px" style="min-width: 300px"
v-for="n in notiList" v-for="(n, index) in notiList"
:key="n.id" :key="index"
> >
<q-item v-ripple class="mytry q-py-xs" dense> <q-item v-ripple class="mytry q-py-xs" dense>
<q-item-section avatar top style="min-width: 40px"> <q-item-section avatar top style="min-width: 40px">
@ -537,7 +548,7 @@ function onLoad(index: any, done: any) {
dense dense
icon="mdi-close" icon="mdi-close"
class="mybtn q-mx-xs" class="mybtn q-mx-xs"
@click="clickDelete(n.id)" @click="clickDelete(n.id, index)"
></q-btn> ></q-btn>
</q-item> </q-item>
<q-separator color="grey-2" /> <q-separator color="grey-2" />