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

View file

@ -35,6 +35,6 @@ interface QueryProfile {
searchField: string;
page: 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 () => {
await storeData.fetchLog({
size: size.value,
systemName: systemName.value ?? undefined,
date: date.value[0],
});
// await storeData.fetchLog({
// size: size.value,
// systemName: systemName.value ?? undefined,
// date: date.value[0],
// });
if (route.query.system) {
const a = menuList.value.find((v) => {
if (v.path.includes(route.fullPath)) {