Refactoring code module 03_logs

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-09 15:28:53 +07:00
parent c11ff006eb
commit 2e9bbe3dd1
5 changed files with 115 additions and 113 deletions

View file

@ -6,16 +6,40 @@ import { useDataStore } from "@/modules/03_logs/stores/main";
import { storeToRefs } from "pinia";
import { useRoute } from "vue-router";
import type {
Pagination,
ItemsDropdown,
} from "@/modules/03_logs/interface/index/Main";
import DialogDataDiff from "@/modules/03_logs/components/DialogDataDiff.vue";
const route = useRoute();
import type { ResLog } from "@/modules/03_logs/interface/response/Main";
/** importStore*/
/** use*/
const storeData = useDataStore();
const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
const { logData, size, searchAfter, systemName } = storeToRefs(storeData);
const { date2Thai } = useCounterMixin();
const startTime = ref<Date | null>(null); //
const endTime = ref<Date | null>(null); //
const startDate = ref<string>(""); //
const endDate = ref<string>(""); //
const sortTime = ref<"desc" | "asc">("desc");
const openDialog = ref<boolean>(false);
const currentlogData =
ref<Omit<ResLog, "endTimeStamp" | "tId" | "processTime" | "systemName">>();
const currentDataDiff = ref<{
before: string;
after: string;
}>({
before: "",
after: "",
});
//table
const inputSearch = defineModel<string>("inputSearch"); //
const columns = ref<QTableProps["columns"]>([
{
name: "startTimeStamp",
@ -108,25 +132,19 @@ const columns = ref<QTableProps["columns"]>([
style: "font-size: 14px",
},
]);
const startTime = ref<Date | null>(null);
const endTime = ref<Date | null>(null);
const startDate = ref<string>("");
const endDate = ref<string>("");
const sortTime = ref<"desc" | "asc">("desc");
const openDialog = ref<boolean>(false);
const currentlogData =
ref<Omit<ResLog, "endTimeStamp" | "tId" | "processTime" | "systemName">>();
const currentDataDiff = ref<{
before: string;
after: string;
}>({
before: "",
after: "",
});
const inputSearch = defineModel<string>("inputSearch");
const pagination = ref({
const visibleColumns = ref<string[]>([
"startTimeStamp",
"username",
"host",
"endpoint",
"method",
"responseCode",
"logType",
"responseDescription",
"sequence",
"dataDiff",
]);
const pagination = ref<Pagination>({
page: 1,
rowsPerPage: 0,
});
@ -135,7 +153,8 @@ const labelDropdown = ref<string>("วันนี้");
const valDropdown = ref<string>("");
const searchStatus = ref<string>("");
const itemsDropdown = ref<any[]>([
//
const itemsDropdown = ref<ItemsDropdown[]>([
{
labal: "วันนี้",
val: "today",
@ -162,21 +181,12 @@ const itemsDropdown = ref<any[]>([
},
]);
const statusOpt = ref<any[]>(["info", "warning", "error"]);
const visibleColumns = ref<string[]>([
"startTimeStamp",
"username",
"host",
"endpoint",
"method",
"responseCode",
"logType",
"responseDescription",
"sequence",
"dataDiff",
]);
const statusOpt = ref<string[]>(["info", "warning", "error"]);
/**
* scroll และโหลดขอมลรายการ Logs เพ
*/
const infiniteScroll = handleScroll();
function handleScroll() {
let scrollFlag = false;
@ -198,7 +208,6 @@ function handleScroll() {
systemName: systemName.value ?? undefined,
searchAfter: searchAfter.value ?? undefined,
sort: sortTime.value,
// date: new Date(startDate.value),
startDate: new Date(startDate.value) ?? undefined,
endDate: new Date(endDate.value) ?? undefined,
},
@ -210,8 +219,9 @@ function handleScroll() {
};
}
const infiniteScroll = handleScroll();
/**
* นหาขอมลรายการ Logs
*/
function selectedDate() {
if (!startDate.value) {
const startDateToday = new Date();
@ -224,23 +234,6 @@ function selectedDate() {
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;
@ -252,7 +245,6 @@ function selectedDate() {
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,7 +252,12 @@ function selectedDate() {
);
}
function classColorMethod(val: any) {
/**
* แปลงสตาม method
* @param val method
* @returns าส
*/
function classColorMethod(val: string) {
switch (val) {
case "GET":
return "blue";
@ -278,6 +275,13 @@ function classColorMethod(val: any) {
}
}
/**
* เลอกประเภทการคนหาขอม
* @param labal อประเภทการคนหาขอม
* @param type ประเภทการคนหาขอม
*
* และคนหาขอมลรายการ Logs ใหม
*/
function onItemClick(labal: string, type: string) {
labelDropdown.value = labal;
valDropdown.value = type;
@ -295,13 +299,15 @@ function onItemClick(labal: string, type: string) {
};
if (type === "today") {
//
startDate.value = setDateRange(0);
endDate.value = setDateRange(0, true);
} else if (type === "yesterday") {
//
startDate.value = setDateRange(1);
endDate.value = setDateRange(1, true);
} else if (type === "past24hours") {
// startDate 24
// 24
const startDatePast24Hours = new Date();
startDatePast24Hours.setHours(startDatePast24Hours.getHours() - 24);
startDate.value = startDatePast24Hours.toISOString();
@ -309,6 +315,7 @@ function onItemClick(labal: string, type: string) {
// endDate
endDate.value = new Date().toISOString();
} else if (["past7days", "past30days"].includes(type)) {
// 7 30
const days = { past7days: 7, past30days: 30 }[type];
startDate.value = setDateRange(days);
endDate.value = new Date().toISOString();
@ -320,11 +327,15 @@ function onItemClick(labal: string, type: string) {
endTime.value = null;
}
/**
* ปเดทวนทองการคนหาขอมลรายการ Logs
*
* และคนหาขอมลรายการ Logs ใหม
*/
function updateDate() {
if (startTime.value && endTime.value) {
startDate.value = startTime.value.toISOString();
endDate.value = endTime.value.toISOString();
selectedDate();
}
}
@ -611,7 +622,7 @@ onMounted(() => {
</div>
<div v-else-if="col.name === 'method'">
<q-badge
:text-color="classColorMethod(col.value)"
:text-color="classColorMethod(col.value as string)"
style="background-color: #f0ecec"
>{{ col.value ?? "-" }}</q-badge
>
@ -742,7 +753,7 @@ onMounted(() => {
</div>
<div class="self-center" v-if="key === 'method'">
<q-badge
:text-color="classColorMethod(item)"
:text-color="classColorMethod(item as string)"
style="background-color: #f0ecec"
>
{{ item ?? "-" }}