fix bug list log

This commit is contained in:
Warunee Tamkoo 2024-10-24 12:58:54 +07:00
parent 97d1323437
commit 70524922e2
3 changed files with 63 additions and 39 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { cloneVNode, onMounted, ref, reactive } from "vue"; import { cloneVNode, onMounted, ref, reactive, onBeforeMount } from "vue";
import { useQuasar, type QTableProps } from "quasar"; import { useQuasar, type QTableProps } from "quasar";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
@ -25,7 +25,7 @@ import type { ResLog } from "@/modules/03_logs/interface/response/Main";
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
const storeData = useDataStore(); const storeData = useDataStore();
const { logData, size, searchAfter, systemName } = storeToRefs(storeData); const { logData, size, searchAfter, systemName, date } = storeToRefs(storeData);
const { date2Thai, messageError, hideLoader } = useCounterMixin(); const { date2Thai, messageError, hideLoader } = useCounterMixin();
const startTime = ref<Date | null>(null); // const startTime = ref<Date | null>(null); //
@ -192,31 +192,27 @@ const statusOpt = ref<string[]>(["info", "warning", "error"]);
const filter = ref<string>(""); // const filter = ref<string>(""); //
const nodeTree = ref<DataTree[]>([]); // const nodeTree = ref<DataTree[]>([]); //
const expanded = ref<Array<string>>([]); // const expanded = ref<Array<string>>([]); //
const orgId = ref<string>(""); // id
const qureyBody = reactive<QueryProfile>({ const qureyBody = reactive<QueryProfile>({
searchKeyword: "", // searchKeyword: "", //
searchField: "fullName", // field searchField: "fullName", // field
page: 1, // page: 1, //
pageSize: 10, // pageSize: 10, //
id: null, // rootId: undefined, //
}); });
/** /**
* งกนเลอกหนวยงาน * งกนเลอกหนวยงาน
* @param id หนวยงานทเลอก * @param id หนวยงานทเลอก
* *
* กำหนดคาของ qureyBody ใหเปนค defult และกำหนดคาของ qureyBody.id เปนหนวยงานทเลอก * กำหนดคาของ qureyBody ใหเปนค defult และกำหนดคาของ qureyBody.rootId เปนหนวยงานทเลอก
* และดงขอมลรายชอคนททธดการโครงสรางในหนวยงานทเลอก * และดงขอมลรายชอคนททธดการโครงสรางในหนวยงานทเลอก
*/ */
async function selectedOrg(id: string) { async function selectedOrg(id: string) {
orgId.value = id; qureyBody.rootId = id;
qureyBody.id = id;
qureyBody.searchKeyword = "";
qureyBody.searchField = "fullName";
qureyBody.page = 1; qureyBody.page = 1;
await storeData.fetchLog( await storeData.fetchLog(
{ {
rootId: qureyBody.id ?? undefined, rootId: qureyBody.rootId ?? undefined,
size: size.value ?? undefined, size: size.value ?? undefined,
search: inputSearch.value ?? undefined, search: inputSearch.value ?? undefined,
systemName: systemName.value ?? undefined, systemName: systemName.value ?? undefined,
@ -230,28 +226,51 @@ async function selectedOrg(id: string) {
} }
/** /**
* งกนดงขอมลโครงสราง * งชนสำหรบดงไอดโครงสรางปจจ
*
* เกบขอมลโครงสรางไวใน nodeTree
*/ */
async function fatchOrg() { async function fetchOrganizationActive() {
await http await http
.get(config.API.permissionOrg) .get(config.API.activeOrganization)
.then(async (res) => { .then(async (res) => {
const data = await res.data.result; const data = res.data.result;
nodeTree.value = data; if (data) {
await fatchOrg(data.activeId);
}
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
});
}
/**
* งกนดงขอมลโครงสรางเกบขอมลโครงสรางไวใน nodeTree
* revision id ของโครงสราง
*/
async function fatchOrg(id: string) {
await http
.get(config.API.orgByid(id))
.then(async (res) => {
const data = await res.data.result;
nodeTree.value = data;
searchAfter.value = undefined;
if (data.length === 1) {
selectedOrg(data[0].orgTreeId);
} else {
await storeData.fetchLog({
size: size.value,
systemName: systemName.value ?? undefined,
date: date.value[0],
});
}
})
.catch((err) => {
messageError($q, err);
hideLoader(); hideLoader();
}) })
.finally(() => {}); .finally(() => {});
} }
/** /*** scroll และโหลดข้อมูลรายการ Logs เพิ่ม */
* scroll และโหลดขอมลรายการ Logs เพ
*/
const infiniteScroll = handleScroll(); const infiniteScroll = handleScroll();
function handleScroll() { function handleScroll() {
let scrollFlag = false; let scrollFlag = false;
@ -269,6 +288,7 @@ function handleScroll() {
scrollFlag = true; scrollFlag = true;
await storeData.fetchLog( await storeData.fetchLog(
{ {
rootId: qureyBody.rootId ?? undefined,
size: size.value ?? undefined, size: size.value ?? undefined,
search: inputSearch.value ?? undefined, search: inputSearch.value ?? undefined,
systemName: systemName.value ?? undefined, systemName: systemName.value ?? undefined,
@ -285,9 +305,7 @@ function handleScroll() {
}; };
} }
/** /** ฟังก์ชั่นดึงข้อมูลรายการ Logs ตามเงื่อนไข */
* นหาขอมลรายการ Logs
*/
function selectedDate() { function selectedDate() {
if (!startDate.value) { if (!startDate.value) {
const startDateToday = new Date(); const startDateToday = new Date();
@ -305,6 +323,7 @@ function selectedDate() {
searchAfter.value = undefined; searchAfter.value = undefined;
storeData.fetchLog( storeData.fetchLog(
{ {
rootId: qureyBody.rootId ?? undefined,
size: size.value ?? undefined, size: size.value ?? undefined,
search: inputSearch.value ?? undefined, search: inputSearch.value ?? undefined,
systemName: systemName.value ?? undefined, systemName: systemName.value ?? undefined,
@ -406,8 +425,11 @@ function updateDate() {
} }
} }
onMounted(() => { onBeforeMount(async () => {
fatchOrg(); await fetchOrganizationActive(); //
});
onMounted(async () => {
systemName.value = route.query.system as string; systemName.value = route.query.system as string;
const date = new Date(); const date = new Date();
date.setHours(0, 0, 0, 0); // 00:00:00.000 date.setHours(0, 0, 0, 0); // 00:00:00.000
@ -420,7 +442,7 @@ onMounted(() => {
<template> <template>
<div class="bg-white q-pa-md"> <div class="bg-white q-pa-md">
<div class="row q-col-gutter-sm"> <div class="row q-col-gutter-sm">
<div class="col-4"> <div class="col-md-3">
<div class="q-mb-sm"> <div class="q-mb-sm">
<q-input dense outlined v-model="filter" label="ค้นหา"> <q-input dense outlined v-model="filter" label="ค้นหา">
<template v-slot:append> <template v-slot:append>
@ -450,9 +472,9 @@ onMounted(() => {
<q-item <q-item
clickable clickable
class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list" class="row col-12 items-center text-dark q-py-xs q-pl-sm rounded-borders my-list"
:active="orgId == prop.node.id" :active="qureyBody.rootId == prop.node.orgTreeId"
active-class="my-list-link text-primary text-weight-medium" active-class="my-list-link text-primary text-weight-medium"
@click.stop="selectedOrg(prop.node.id)" @click.stop="selectedOrg(prop.node.orgTreeId)"
> >
<div> <div>
<div class="text-weight-medium"> <div class="text-weight-medium">
@ -476,9 +498,10 @@ onMounted(() => {
</q-tree> </q-tree>
</div> </div>
</div> </div>
<div class="col-8">
<div class="row no-wrap"> <div class="col-md-9">
<div class="row col-7 q-col-gutter-md"> <div class="row">
<div class="q-col-gutter-xs">
<div> <div>
<q-btn-dropdown outline color="grey-5"> <q-btn-dropdown outline color="grey-5">
<template v-slot:label> <template v-slot:label>
@ -505,7 +528,7 @@ onMounted(() => {
<q-space /> <q-space />
<div <div
class="items-center justify-end q-gutter-md col-5" class="items-center justify-end q-gutter-xs"
style="display: flex" style="display: flex"
> >
<!-- นหาขอความใน table --> <!-- นหาขอความใน table -->
@ -517,6 +540,7 @@ onMounted(() => {
ref="filterRef" ref="filterRef"
@update:model-value=" @update:model-value="
storeData.fetchLog({ storeData.fetchLog({
rootId: qureyBody.rootId ?? undefined,
size: size ?? undefined, size: size ?? undefined,
search: inputSearch ?? undefined, search: inputSearch ?? undefined,
systemName: systemName ?? undefined, systemName: systemName ?? undefined,

View file

@ -35,6 +35,6 @@ interface QueryProfile {
searchField: string; searchField: string;
page: number; page: number;
pageSize: number; pageSize: number;
id: string | null; rootId: string | undefined;
} }
export type { Pagination, ItemsDropdown,DataTree,QueryProfile }; export type { Pagination, ItemsDropdown, DataTree, QueryProfile };

View file

@ -100,11 +100,11 @@ const menuList = ref<{ icon: string; label: string; path: string }[]>([
]); ]);
onMounted(async () => { onMounted(async () => {
await storeData.fetchLog({ // await storeData.fetchLog({
size: size.value, // size: size.value,
systemName: systemName.value ?? undefined, // systemName: systemName.value ?? undefined,
date: date.value[0], // date: date.value[0],
}); // });
if (route.query.system) { if (route.query.system) {
const a = menuList.value.find((v) => { const a = menuList.value.find((v) => {
if (v.path.includes(route.fullPath)) { if (v.path.includes(route.fullPath)) {