From 8d502950864a5769af10e4c12d550795864514e7 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Thu, 18 Jan 2024 11:25:41 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=81=E0=B8=B2=E0=B8=A3=E0=B9=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B8=87=E0=B9=80=E0=B8=95=E0=B8=B7=E0=B8=AD=E0=B8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/interface/index/Main.ts | 10 ++- src/views/HomeView.vue | 118 ++++++++++++++++++++++++++++++------ 2 files changed, 107 insertions(+), 21 deletions(-) diff --git a/src/interface/index/Main.ts b/src/interface/index/Main.ts index dad1f39..0d7d259 100644 --- a/src/interface/index/Main.ts +++ b/src/interface/index/Main.ts @@ -16,7 +16,7 @@ interface notiType { id: string sender: string body: string - timereceive: Date + timereceive: string | null } interface LocationObject { @@ -24,4 +24,10 @@ interface LocationObject { longitude: number } -export type { DataOption, FormRef, notiType, DataDateMonthObject, LocationObject} +export type { + DataOption, + FormRef, + notiType, + DataDateMonthObject, + LocationObject, +} diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index 91decc3..2505a58 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -55,26 +55,46 @@ const notiTrigger = ref(false) const notiList = ref([]) const totalNotiList = ref(0) /** function เรียกข้อมุลแจ้งเตือน */ -async function fetchNotifications() { +async function fetchNotifications(index: number, type: string) { showLoader() await http - .get(config.API.msgNotificate) + .get(config.API.msgNotificate + `?page=${index}&pageSize=${20}`) .then((res) => { const response = res.data.result.data - totalNotiList.value = res.data.result.total const list: notiType[] = [] - 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), + if (type === 'DEL') { + totalNotiList.value = res.data.result.total + console.log(notiList.value.length) + if (notiList.value.length === 14) { + notiList.value = [] + response.map((e: any) => { + list.push({ + id: e.id, + sender: + e.createdFullName == '' || e.createdFullName == null + ? 'เจ้าหน้าที่'[0] + : e.createdFullName[0], + body: e.body ?? '', + timereceive: e.receiveDate ? date2Thai(e.receiveDate) : '-', + }) + }) + 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: e.receiveDate ? date2Thai(e.receiveDate) : '-', + }) }) - }) - notiList.value = list + notiList.value.push(...list) + totalNotiList.value = res.data.result.total + } }) .catch((err) => { messageError($q, err) @@ -88,18 +108,19 @@ async function fetchNotifications() { * function ลบรายการแจ้งเตือน * @param id noti */ -async function onClickDelete(id: string) { +async function onClickDelete(id: string, index: number) { dialogRemove($q, async () => { await http .delete(config.API.msgId(id)) .then(() => { + notiList.value.splice(index, 1) success($q, 'ลบข้อมูลสำเร็จ') }) .catch((e) => { messageError($q, e) }) .finally(async () => { - await fetchNotifications() + fetchNotifications(1, 'DEL') hideLoader() }) }) @@ -300,6 +321,15 @@ function onClickLogout() { }) } +function onLoad(index: any, done: any) { + if (notiList.value.length < totalNotiList.value) { + setTimeout(() => { + fetchNotifications(index + 1, 'NOMAL') + done() + }, 2000) + } +} + // class const getClass = (val: boolean) => { return { @@ -312,7 +342,7 @@ const fullName = ref('') /** Hook*/ onMounted(async () => { await fetchCheckTime() - await fetchNotifications() + await fetchNotifications(1, 'NOMAL') if (keycloak.tokenParsed != null) { fullName.value = keycloak.tokenParsed.name } @@ -370,7 +400,57 @@ onMounted(async () => { - +
+ + + + {{ + item.sender[0] + }} + + + + {{ + item.body + }} + {{ item.timereceive }} + +
+ +
+
+
+ + + + +