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

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2023-11-28 13:36:08 +07:00
parent 4ff1334b32
commit 23314ca3a6
6 changed files with 115 additions and 17 deletions

View file

@ -9,6 +9,7 @@ import config from '@/app.config'
// import Type
import type { FormRef } from '@/interface/response/checkin'
import type { Noti } from '@/interface/response/Main'
import type { notiType } from '@/interface/index/Main'
// import components
@ -19,7 +20,7 @@ import MapCheck from '@/components/MapCheckin.vue'
import { useCounterMixin } from '@/stores/mixin'
const mixin = useCounterMixin()
const { date2Thai, showLoader, hideLoader, messageError } = mixin
const { date2Thai, showLoader, hideLoader, messageError, dialogRemove } = mixin
const router = useRouter()
const $q = useQuasar()
@ -37,13 +38,65 @@ async function fetchCheckTime() {
checkInId.value = data.checkInId ? data.checkInId : ''
})
.catch((err) => {
console.log(err)
messageError($q, err)
})
.finally(() => {
hideLoader()
})
}
const notiTrigger = ref<boolean>(false)
const notiList = ref<notiType[]>([])
/** function เรียกข้อมุลแจ้งเตือน */
async function fetchNotifications() {
showLoader()
await http
.get(config.API.msgNotificate)
.then((res) => {
const response = res.data.result
const list: notiType[] = []
response.map((e: Noti) => {
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 = list
})
.catch((err) => {
messageError($q, err)
})
.finally(() => {
hideLoader()
})
}
/**
* function ลบรายการแจงเตอน
* @param id noti
*/
async function onClickDelete(id: string) {
dialogRemove($q, async () => {
await http
.delete(config.API.msgId(id))
.then(() => {
success($q, 'ลบข้อมูลสำเร็จ')
})
.catch((e) => {
messageError($q, e)
})
.finally(async () => {
await fetchNotifications()
hideLoader()
})
})
}
/** ref อัพเดทเวลา*/
const dateNow = ref<Date>(new Date())
const Thai = ref<Date>(dateNow.value)
@ -225,16 +278,6 @@ async function onClickConfirm() {
dialogTime.value = false
}
const notiTrigger = ref<boolean>(false)
const notiList = ref<notiType[]>([
{
id: '1',
sender: 'ท',
body: 'ลงเวลา',
timereceive: new Date(),
},
])
// class
const getClass = (val: boolean) => {
return {
@ -245,6 +288,7 @@ const getClass = (val: boolean) => {
/** Hook*/
onMounted(async () => {
await fetchCheckTime()
await fetchNotifications()
updateClock()
})
@ -327,6 +371,7 @@ onMounted(async () => {
dense
icon="mdi-close"
class="mybtn q-mx-xs"
@click="onClickDelete(n.id)"
></q-btn>
</q-item>
<q-separator color="grey-2" />