diff --git a/src/modules/03_logs/components/LogTable.vue b/src/modules/03_logs/components/LogTable.vue index fa07ab3a..1bd52fa0 100644 --- a/src/modules/03_logs/components/LogTable.vue +++ b/src/modules/03_logs/components/LogTable.vue @@ -109,11 +109,11 @@ const columns = ref([ }, ]); -const startTime = ref(); +const startTime = ref(null); +const endTime = ref(null); const startDate = ref(""); -const endTime = ref(); -const sortTime = ref<"desc" | "asc">("desc"); const endDate = ref(""); +const sortTime = ref<"desc" | "asc">("desc"); const openDialog = ref(false); const currentlogData = ref>(); @@ -131,6 +131,39 @@ const pagination = ref({ rowsPerPage: 0, }); +const labelDropdown = ref("วันนี้"); +const valDropdown = ref(""); +const searchStatus = ref(""); + +const itemsDropdown = ref([ + { + labal: "วันนี้", + val: "today", + }, + { + labal: "เมื่อวาน", + val: "yesterday", + }, + { + labal: "ย้อนหลัง 24 ชั่วโมง", + val: "past24hours", + }, + { + labal: "ย้อนหลัง 7 วัน", + val: "past7days", + }, + { + labal: "ย้อนหลัง 30 วัน", + val: "past30days", + }, + { + labal: "กำหนดเอง", + val: "customized", + }, +]); + +const statusOpt = ref(["info", "warning", "error"]); + const visibleColumns = ref([ "startTimeStamp", "username", @@ -146,6 +179,7 @@ const visibleColumns = ref([ function handleScroll() { let scrollFlag = false; + return async (e: Event) => { if (scrollFlag) return; @@ -179,23 +213,34 @@ function handleScroll() { const infiniteScroll = handleScroll(); function selectedDate() { - startDate.value = date.value[0].toISOString(); - endDate.value = date.value[1].toISOString(); + if (!startDate.value) { + const startDateToday = new Date(); + startDateToday.setHours(0, 0, 0, 0); - if (!!startTime.value) { - replaceTimeInISOString(startDate.value, startTime.value, "start"); - } else { - const date = new Date(startDate.value); - date.setHours(0, 0, 0, 0); - startDate.value = date.toISOString(); - } - if (!!endTime.value) { - replaceTimeInISOString(endDate.value, endTime.value, "end"); - } else { - const date = new Date(endDate.value); - date.setHours(23, 59, 59, 999); - endDate.value = date.toISOString(); + // ตั้งค่า endDate เป็นเวลา 23:59:59 ของวันนี้ + const endDateToday = new Date(); + endDateToday.setHours(23, 59, 59, 999); + + startDate.value = startDateToday.toISOString(); + endDate.value = endDateToday.toISOString(); } + // startDate.value = date.value[0].toISOString(); + // endDate.value = date.value[1].toISOString(); + + // if (!!startTime.value) { + // replaceTimeInISOString(startDate.value, startTime.value, "start"); + // } else { + // const date = new Date(startDate.value); + // date.setHours(0, 0, 0, 0); + // startDate.value = date.toISOString(); + // } + // if (!!endTime.value) { + // replaceTimeInISOString(endDate.value, endTime.value, "end"); + // } else { + // const date = new Date(endDate.value); + // date.setHours(23, 59, 59, 999); + // endDate.value = date.toISOString(); + // } logData.value = []; searchAfter.value = undefined; @@ -206,6 +251,7 @@ function selectedDate() { systemName: systemName.value ?? undefined, searchAfter: searchAfter.value ?? undefined, sort: sortTime.value, + searchStatus: searchStatus.value ?? undefined, // date: new Date(startDate.value), startDate: new Date(startDate.value), endDate: new Date(endDate.value), @@ -260,88 +306,112 @@ function dateThaiRange(val: [Date, Date]) { } } +function onItemClick(labal: string, type: string) { + labelDropdown.value = labal; + valDropdown.value = type; + + if (type === "today") { + // ตั้งค่า startDateToday เป็นเวลา 23:59:59 ของวันนี้ + const startDateToday = new Date(); + startDateToday.setHours(0, 0, 0, 0); + + // ตั้งค่า endDate เป็นเวลา 23:59:59 ของวันนี้ + const endDateToday = new Date(); + endDateToday.setHours(23, 59, 59, 999); + + startDate.value = startDateToday.toISOString(); + endDate.value = endDateToday.toISOString(); + + selectedDate(); + } else if (type === "yesterday") { + const endDateNow = new Date(); // เวลาปัจจุบัน + + // ตั้งค่า endDate เป็นเวลา 23:59:59 ของวันก่อนหน้า + endDateNow.setDate(endDateNow.getDate() - 1); + endDateNow.setHours(23, 59, 59, 999); + + // ตั้งค่า startDate เป็นเวลา 00:00:00 ของวันก่อนหน้า + const startDateYesterday = new Date(endDateNow); + startDateYesterday.setHours(0, 0, 0, 0); + + startDate.value = startDateYesterday.toISOString(); + endDate.value = endDateNow.toISOString(); + + selectedDate(); + } else if (type === "past24hours") { + // ตั้งค่า startDatePast เป็นเวลาย้อนหลัง 24 hours + const startDatePast = new Date(); + startDatePast.setHours(startDatePast.getHours() - 24); + + startDate.value = startDatePast.toISOString(); + endDate.value = new Date().toISOString(); + + selectedDate(); + } else if (type === "past7days") { + // ตั้งค่า startDatePast เป็นเวลาย้อนหลัง 7 วัน + const startDatePast = new Date(); + startDatePast.setDate(startDatePast.getDate() - 7); + + startDate.value = startDatePast.toISOString(); + endDate.value = new Date().toISOString(); + + selectedDate(); + } else if (type === "past30days") { + // ตั้งค่า startDatePast เป็นเวลาย้อนหลัง 30 วัน + const startDatePast = new Date(); + startDatePast.setDate(startDatePast.getDate() - 30); + + startDate.value = startDatePast.toISOString(); + endDate.value = new Date().toISOString(); + + selectedDate(); + } + + startTime.value = null; + endTime.value = null; +} + +function updateDate() { + if (startTime.value && endTime.value) { + startDate.value = startTime.value.toISOString(); + endDate.value = endTime.value.toISOString(); + + selectedDate(); + } +} + onMounted(() => { systemName.value = route.query.system as string; - startDate.value = date.value[0].toISOString(); - endDate.value = date.value[1].toISOString(); + // startDate.value = date.value[0].toISOString(); + // endDate.value = date.value[1].toISOString(); }); + + + + { /> - -
-
- +
+ - - + + + + + + + +
+
+ + + + + + +
+
+ +
+ + + - -
+
+ {{ col.value === "" || col.value === null ? "-" : col.value }} + {{ col.value }} +
+ + + +
@@ -714,8 +902,12 @@ onMounted(() => { - diff --git a/src/modules/03_logs/stores/main.ts b/src/modules/03_logs/stores/main.ts index 1d743ee5..1b423b95 100644 --- a/src/modules/03_logs/stores/main.ts +++ b/src/modules/03_logs/stores/main.ts @@ -35,6 +35,7 @@ export const useDataStore = defineStore("logStore", () => { sort?: string; startDate?: Date; endDate?: Date; + searchStatus?: string; }, isBottom?: boolean ) {