API ประวัติการใช้งาน

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-12-06 09:48:23 +07:00
parent ab9e9bc941
commit 27bf12fc23
3 changed files with 61 additions and 62 deletions

View file

@ -18,4 +18,12 @@ interface ResApiName {
pathApi: string; pathApi: string;
} }
export type { ResListWebServices, ResApiName }; interface ResApHistory {
apiKey: string;
apiName: string;
createdAt: Date;
id: string;
ipApi: string;
}
export type { ResListWebServices, ResApiName, ResApHistory };

View file

@ -10,13 +10,16 @@ import type {
DataOption, DataOption,
ItemsDropdown, ItemsDropdown,
} from "@/modules/06_webservices/interface/index/Main"; } from "@/modules/06_webservices/interface/index/Main";
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main"; import type {
ResApiName,
ResApHistory,
} from "@/modules/06_webservices/interface/response/Main";
/** use*/ /** use*/
const $q = useQuasar(); const $q = useQuasar();
const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin(); const { showLoader, hideLoader, messageError, date2Thai } = useCounterMixin();
const apiType = ref<string>(""); const apiNameId = ref<string>("");
const dataApiName = ref<DataOption[]>([ const dataApiName = ref<DataOption[]>([
{ {
id: "", id: "",
@ -31,7 +34,7 @@ const startTime = ref<Date | null>(null); // เวลาเริ่มต้
const endTime = ref<Date | null>(null); // const endTime = ref<Date | null>(null); //
// //
const valDropdown = ref<string>(""); const valDropdown = ref<string>("today");
const labelDropdown = ref<string>("วันนี้"); const labelDropdown = ref<string>("วันนี้");
const itemsDropdown = ref<ItemsDropdown[]>([ const itemsDropdown = ref<ItemsDropdown[]>([
{ {
@ -60,24 +63,29 @@ const itemsDropdown = ref<ItemsDropdown[]>([
}, },
]); ]);
const rows = ref<any[]>([]); const rows = ref<ResApHistory[]>([]);
const visibleColumns = ref<String[]>(["name", "date", "request", "IP"]); const visibleColumns = ref<String[]>([
"apiName",
"createdAt",
"apiKey",
"ipApi",
]);
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "name", name: "apiName",
align: "left", align: "left",
label: "API Request", label: "API Request",
sortable: false, sortable: false,
field: "name", field: "apiName",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "date", name: "createdAt",
align: "left", align: "left",
label: "วันที่ร้องขอ", label: "วันที่ร้องขอ",
sortable: true, sortable: true,
field: "date", field: "createdAt",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
format(val, row) { format(val, row) {
@ -85,20 +93,20 @@ const columns = ref<QTableProps["columns"]>([
}, },
}, },
{ {
name: "request", name: "apiKey",
align: "left", align: "left",
label: " คน request", label: " คน request",
sortable: false, sortable: false,
field: "request", field: "apiKey",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
}, },
{ {
name: "IP", name: "ipApi",
align: "left", align: "left",
label: " IP", label: " IP",
sortable: false, sortable: false,
field: "IP", field: "ipApi",
headerStyle: "font-size: 14px", headerStyle: "font-size: 14px",
style: "font-size: 14px", style: "font-size: 14px",
}, },
@ -107,7 +115,7 @@ const columns = ref<QTableProps["columns"]>([
/** ฟังก์ชันเรียกรายการข้อมูล API ที่เข้าถึงได้*/ /** ฟังก์ชันเรียกรายการข้อมูล API ที่เข้าถึงได้*/
async function fetchListApiKeyName() { async function fetchListApiKeyName() {
showLoader(); showLoader();
await http http
.get(config.API.apiKeyMain + "/name") .get(config.API.apiKeyMain + "/name")
.then(async (res) => { .then(async (res) => {
const data = (await res.data?.result) || []; const data = (await res.data?.result) || [];
@ -117,6 +125,8 @@ async function fetchListApiKeyName() {
})); }));
dataApiName.value.push(...optionData); dataApiName.value.push(...optionData);
options.value = dataApiName.value; options.value = dataApiName.value;
await onItemClick(labelDropdown.value, valDropdown.value);
await fetchListLog();
}) })
.catch((err) => { .catch((err) => {
messageError($q, err); messageError($q, err);
@ -127,16 +137,22 @@ async function fetchListApiKeyName() {
} }
async function fetchListLog() { async function fetchListLog() {
const data = [ showLoader();
{ http
name: "API ข้อมูลทะเบียนประวัติข้าราชการ", .post(config.API.apiKeyMain + `/history`, {
date: new Date(), apiNameId: apiNameId.value,
request: "MISConnect", endDate: endDate.value,
IP: "192.168.1.xx", startDate: startDate.value,
}, })
]; .then((res) => {
rows.value = res.data.result;
rows.value = data; })
.catch((err) => {
messageError($q, err);
})
.finally(() => {
hideLoader();
});
} }
function onSelectType() { function onSelectType() {
@ -168,7 +184,7 @@ function filterSelector(val: string, update: Function) {
* @param type ประเภทการคนหาขอม * @param type ประเภทการคนหาขอม
* และคนหาขอมลรายการ Logs ใหม * และคนหาขอมลรายการ Logs ใหม
*/ */
function onItemClick(labal: string, type: string) { async function onItemClick(labal: string, type: string) {
labelDropdown.value = labal; labelDropdown.value = labal;
valDropdown.value = type; valDropdown.value = type;
const setDateRange = (daysAgo: number = 0, endOfDay = false) => { const setDateRange = (daysAgo: number = 0, endOfDay = false) => {
@ -206,7 +222,12 @@ function onItemClick(labal: string, type: string) {
endDate.value = new Date().toISOString(); endDate.value = new Date().toISOString();
} }
type !== "customized" && selectedDate(); if (type !== "customized") {
selectedDate();
} else {
startTime.value = null;
endTime.value = null;
}
} }
/** /**
@ -234,10 +255,11 @@ function selectedDate() {
startDate.value = startDateToday.toISOString(); startDate.value = startDateToday.toISOString();
endDate.value = endDateToday.toISOString(); endDate.value = endDateToday.toISOString();
} }
fetchListLog();
} }
onMounted(async () => { onMounted(async () => {
await fetchListLog();
await fetchListApiKeyName(); await fetchListApiKeyName();
}); });
</script> </script>
@ -277,14 +299,12 @@ onMounted(async () => {
option-value="id" option-value="id"
emit-value emit-value
map-options map-options
v-model="apiType" v-model="apiNameId"
:options="options" :options="options"
label="รายากร Web Services" label="รายากร Web Services"
use-input use-input
hide-selected hide-selected
fill-input fill-input
:clearable="apiType !== ''"
@clear="apiType = ''"
@update:modelValue="onSelectType" @update:modelValue="onSelectType"
@filter="(inputValue: string,doneFn: Function) => filterSelector(inputValue, doneFn )" @filter="(inputValue: string,doneFn: Function) => filterSelector(inputValue, doneFn )"
> >
@ -417,7 +437,7 @@ onMounted(async () => {
</q-tr> </q-tr>
</template> </template>
<template v-slot:body="props"> <template v-slot:body="props">
<q-tr :props="props" class="cursor-pointer"> <q-tr :props="props">
<q-td v-for="col in props.cols" :key="col.name" :props="props"> <q-td v-for="col in props.cols" :key="col.name" :props="props">
<div> <div>
{{ col.value ?? "-" }} {{ col.value ?? "-" }}
@ -425,21 +445,6 @@ onMounted(async () => {
</q-td> </q-td>
</q-tr> </q-tr>
</template> </template>
<!-- <template v-slot:pagination="scope">
งหมด {{ total }} รายการ
<q-pagination
v-model="pagination.page"
active-color="primary"
color="dark"
:max="Number(totalList)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchSalaryList"
></q-pagination>
</template> -->
</d-table> </d-table>
</div> </div>
</div> </div>

View file

@ -1,25 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
/** importComponents*/ /** importComponents*/
import ListView from "@/modules/06_webservices/view/listView.vue"; import ListView from "@/modules/06_webservices/view/listView.vue";
import LogView from "@/modules/06_webservices/view/logView.vue"; import LogView from "@/modules/06_webservices/view/logView.vue";
/** use*/ const tabs = ref<string>("list");
const $q = useQuasar();
const {
dialogRemove,
showLoader,
hideLoader,
messageError,
success,
date2Thai,
} = useCounterMixin();
const tabs = ref<string>("log");
</script> </script>
<template> <template>