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

View file

@ -1,5 +1,11 @@
interface Pagination { interface Pagination {
page: number;
rowsPerPage: number; rowsPerPage: number;
} }
export type { Pagination }; interface ItemsDropdown {
labal: string;
val: string;
}
export type { Pagination, ItemsDropdown };

View file

@ -1,8 +1,8 @@
const ListsPage = () => import("@/modules/03_logs/views/lists.vue"); const ListsPage = () => import("@/modules/03_logs/views/mainView.vue");
export default [ export default [
{ {
path: "/lists", path: "/logs",
name: "viewLogs", name: "viewLogs",
component: ListsPage, component: ListsPage,
meta: { meta: {

View file

@ -1,117 +1,102 @@
<script setup lang="ts"> <script setup lang="ts">
/** importType*/
/** importComponents*/
import CardComponents from "@/modules/03_logs/components/CardComponents.vue";
import { useCounterMixin } from "@/stores/mixin";
import LogTable from "@/modules/03_logs/components/LogTable.vue";
import { useRoute } from "vue-router";
import http from "@/plugins/http";
import { useQuasar } from "quasar";
import config from "@/app.config";
import { ref, onMounted } from "vue"; import { ref, onMounted } from "vue";
import { useDataStore } from "@/modules/03_logs/stores/main"; import { useQuasar } from "quasar";
import { storeToRefs } from "pinia"; import { storeToRefs } from "pinia";
/** importStore*/ import { useRoute } from "vue-router";
const storeData = useDataStore(); import { useDataStore } from "@/modules/03_logs/stores/main";
const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
const route = useRoute();
/** use*/
const title = ref<string>("");
/** importComponents*/
import CardComponents from "@/modules/03_logs/components/CardComponents.vue"; // card
import LogTable from "@/modules/03_logs/components/LogTable.vue"; // Table
/** use*/
const route = useRoute();
const $q = useQuasar(); const $q = useQuasar();
const storeData = useDataStore();
const { size, systemName, date } = storeToRefs(storeData);
const title = ref<string>(""); //
//
const menuList = ref<{ icon: string; label: string; path: string }[]>([ const menuList = ref<{ icon: string; label: string; path: string }[]>([
{ {
icon: "mdi-file-account-outline", icon: "mdi-file-account-outline",
label: "ระบบทะเบียนประวัติ", label: "ระบบทะเบียนประวัติ",
path: "/lists?system=registry", path: "/logs?system=registry",
}, },
{ {
icon: "mdi-account-group", icon: "mdi-account-group",
label: "ระบบโครงสร้างหน่วยงานและกรอบอัตรากำลัง", label: "ระบบโครงสร้างหน่วยงานและกรอบอัตรากำลัง",
path: "/lists?system=organization", path: "/logs?system=organization",
}, },
{ {
icon: "mdi-calendar", icon: "mdi-calendar",
label: "ระบบบันทึกเวลาปฏิบัติงานและการลา", label: "ระบบบันทึกเวลาปฏิบัติงานและการลา",
path: "/lists?system=leave", path: "/logs?system=leave",
}, },
{ {
icon: "mdi-magnify", icon: "mdi-magnify",
label: "ระบบการสรรหาบุคคล", label: "ระบบการสรรหาบุคคล",
path: "/lists?system=recruiting", path: "/logs?system=recruiting",
}, },
{ {
icon: "mdi-account-check-outline", icon: "mdi-account-check-outline",
label: "ระบบการประเมินบุคคล", label: "ระบบการประเมินบุคคล",
path: "/lists?system=evaluation", path: "/logs?system=evaluation",
}, },
{ {
icon: "mdi-account-cancel-outline", icon: "mdi-account-cancel-outline",
label: "ระบบพ้นจากราชการ", label: "ระบบพ้นจากราชการ",
path: "/lists?system=retirement", path: "/logs?system=retirement",
}, },
{ {
icon: "mdi-cash", icon: "mdi-cash",
label: "ระบบการเลื่อนเงินเดือน/ค่าจ้าง", label: "ระบบการเลื่อนเงินเดือน/ค่าจ้าง",
path: "/lists?system=salary", path: "/logs?system=salary",
}, },
{ {
icon: "mdi-account-check-outline", icon: "mdi-account-check-outline",
label: "ระบบการบรรจุ แต่งตั้ง ย้าย โอน", label: "ระบบการบรรจุ แต่งตั้ง ย้าย โอน",
path: "/lists?system=placement", path: "/logs?system=placement",
}, },
{ {
icon: "mdi-account-convert", icon: "mdi-account-convert",
label: "ระบบทดลองปฏิบัติหน้าที่ราชการ", label: "ระบบทดลองปฏิบัติหน้าที่ราชการ",
path: "/lists?system=probation", path: "/logs?system=probation",
}, },
{ {
icon: "mdi-account-star", icon: "mdi-account-star",
label: "ระบบการประเมินผลการปฏิบัติราชการระดับบุคคล", label: "ระบบการประเมินผลการปฏิบัติราชการระดับบุคคล",
path: "/lists?system=KPI", path: "/logs?system=KPI",
}, },
{ {
icon: "mdi-briefcase-account", icon: "mdi-briefcase-account",
label: "ระบบการพัฒนาบุคลากร /การศึกษาต่อ", label: "ระบบการพัฒนาบุคลากร /การศึกษาต่อ",
path: "/lists?system=development", path: "/logs?system=development",
}, },
{ {
icon: "mdi-medal-outline", icon: "mdi-medal-outline",
label: "ระบบงานเครื่องราชอิสริยาภรณ์", label: "ระบบงานเครื่องราชอิสริยาภรณ์",
path: "/lists?system=insignia", path: "/logs?system=insignia",
}, },
// {
// icon: "mdi-monitor-dashboard",
// label: " Dashboard",
// path: "/lists?system=report",
// },
{ {
icon: "mdi-scale-balance", icon: "mdi-scale-balance",
label: "ระบบดำเนินการทางวินัย", label: "ระบบดำเนินการทางวินัย",
path: "/lists?system=discipline", path: "/logs?system=discipline",
}, },
// {
// icon: "mdi-briefcase-account",
// label: "",
// path: "/lists?system=owner",
// },
{ {
icon: "mdi-account-settings-outline", icon: "mdi-account-settings-outline",
label: "ระบบข้อมูลหลัก", label: "ระบบข้อมูลหลัก",
path: "/lists?system=master", path: "/logs?system=master",
}, },
{ {
icon: "mdi-account-child-circle", icon: "mdi-account-child-circle",
label: "ระบบ Admin", label: "ระบบ Admin",
path: "/lists?system=admin", path: "/logs?system=admin",
}, },
// {
// icon: "mdi-shield-key",
// label: " Single Sign-On",
// path: "/lists?system=sso",
// },
]); ]);
onMounted(async () => { onMounted(async () => {
@ -140,7 +125,7 @@ onMounted(async () => {
color="primary" color="primary"
icon="mdi-arrow-left" icon="mdi-arrow-left"
dense dense
to="lists" to="logs"
> >
</q-btn> </q-btn>
<div class="row items-center"> <div class="row items-center">