update จัดการ web services

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-08-13 14:28:58 +07:00
parent a5f27c342b
commit daec5d06ec
4 changed files with 392 additions and 111 deletions

View file

@ -1,5 +1,5 @@
<script setup lang="ts">
import { onMounted, ref, toRefs } from "vue";
import { onMounted, ref, toRefs, watch } from "vue";
import { useQuasar } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
@ -9,9 +9,14 @@ import config from "@/app.config";
/** importType*/
import type { QTableProps } from "quasar";
import type { DataOption } from "@/modules/06_webservices/interface/index/Main";
import type { ListWebServices } from "@/modules/06_webservices/interface/index/Main";
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main";
import type {
DataOption,
Pagination,
} from "@/modules/06_webservices/interface/index/Main";
import type {
ListSystems,
ListApiManages,
} from "@/modules/06_webservices/interface/response/Main";
/** importComponents*/
import DialogApi from "@/modules/06_webservices/components/DialogApi.vue";
@ -33,9 +38,12 @@ const systemOptions = ref<DataOption[]>(systemList.value);
/** Table*/
const page = ref<number>(1); //
const pageSize = ref<number>(10); //
const rows = ref<any[]>([]); // webservices
const rows = ref<ListApiManages[]>([]); // webservices
const total = ref<number>(0); //
const maxPage = ref<number>(1); //
const keyword = ref<string>(""); // webservices
const systemfilter = ref<string>("all"); //
const isActive = ref<boolean>(true); //
const visibleColumns = ref<string[]>([
"system",
"name",
@ -99,12 +107,13 @@ const modalDialog = ref<boolean>(false); //ตัวแปรเปิดปิ
const isEditData = ref<boolean>(false); //
const apiId = ref<string>(""); // id api
/** ฟังก์ชันดึงข้อมูลรายการระบบ */
async function fetchSystemData() {
if (systemList.value.length > 1) return; //
try {
const res = await http.get(`${config.API.apiManage}systems`);
const data = res.data.result;
const systemData = data.map((item: any) => ({
const systemData = data.map((item: ListSystems) => ({
id: item.code,
name: item.name,
}));
@ -114,6 +123,7 @@ async function fetchSystemData() {
}
}
/** ฟังก์ชันดึงข้อมูลรายการ API */
async function fetchData() {
try {
const queryParams = {
@ -121,18 +131,25 @@ async function fetchData() {
pageSize: pageSize.value,
keyword: keyword.value,
systems: systemfilter.value === "all" ? "" : systemfilter.value,
isActive: isActive.value,
};
const res = await http.get(`${config.API.apiManage}lists`, {
params: queryParams,
});
const result = res.data.result;
total.value = result.total;
maxPage.value = Math.ceil(total.value / pageSize.value);
rows.value = result.data;
} catch (error) {
messageError(error);
}
}
/**
* งกนลบขอมลรายการ API
* @param id ID ของ API องการลบ
*/
function onDeleteData(id: string) {
dialogRemove($q, async () => {
try {
@ -148,19 +165,24 @@ function onDeleteData(id: string) {
});
}
/**
* งกนแกไขขอมลรายการ API
* @param id ID ของ API องการแกไข
*/
function onEditData(id: string) {
isEditData.value = true;
modalDialog.value = true;
apiId.value = id; // id api
}
/** ฟังก์ชันค้นหาข้อมูลในตารางใหม่ */
function onSearchDataTable() {
page.value = 1; // 1
fetchData();
}
/**
* function นหาคำใน select
* งกนหาคำใน select
* @param val คำคนหา
* @param update function
*/
@ -173,6 +195,23 @@ function filterSelector(val: string, update: Function) {
});
}
/**
* งกนอปเดท paging
* @param initialPagination อม pagination
*/
async function updatePagination(initialPagination: Pagination) {
pageSize.value = initialPagination.rowsPerPage;
}
/** function callback เมื่อมีการเปลี่ยนหน้า*/
watch(
() => pageSize.value,
() => {
onSearchDataTable();
}
);
/** ทำงานเมื่อ component ถูก mount */
onMounted(async () => {
try {
showLoader();
@ -232,13 +271,20 @@ onMounted(async () => {
<q-space />
<div class="row q-col-gutter-sm col-xs-12 col-sm-auto">
<div class="col-xs-12 col-sm-auto">
<q-toggle
v-model="isActive"
label="แสดงเฉพาะที่ใช้งาน"
@update:model-value="onSearchDataTable"
/>
</div>
<div class="col-xs-12 col-sm-auto">
<q-input
borderless
dense
outlined
v-model="keyword"
placeholder="ค้นหา"
placeholder="ค้นหาชื่อ API"
@keydown.enter.prevent="onSearchDataTable"
>
<template v-slot:append>
@ -277,6 +323,7 @@ onMounted(async () => {
dense
:rows-per-page-options="[10, 25, 50, 100]"
:visible-columns="visibleColumns"
@update:pagination="updatePagination"
>
<template v-slot:header="props">
<q-tr :props="props">
@ -317,6 +364,21 @@ onMounted(async () => {
</q-td>
</q-tr>
</template>
<template v-slot:pagination="scope">
งหมด {{ total }} รายการ
<q-pagination
v-model="page"
active-color="primary"
color="dark"
:max="Number(maxPage)"
size="sm"
boundary-links
direction-links
:max-pages="5"
@update:model-value="fetchData"
></q-pagination>
</template>
</d-table>
</div>