267 lines
6.8 KiB
Vue
267 lines
6.8 KiB
Vue
<script setup lang="ts">
|
|
import { onMounted, ref } from "vue";
|
|
import { useQuasar } from "quasar";
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
|
|
/** importType*/
|
|
import type { QTableProps } from "quasar";
|
|
import type { ListWebServices } from "@/modules/06_webservices/interface/index/Main";
|
|
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main";
|
|
|
|
/** importComponents*/
|
|
import DialogApiKey from "@/modules/06_webservices/components/DialogApiKey.vue"; //สร้าง API Key
|
|
import DialogUsability from "@/modules/06_webservices/components/DialogUsability.vue"; //การใช้งาน
|
|
|
|
/** use*/
|
|
const $q = useQuasar();
|
|
const {
|
|
dialogRemove,
|
|
showLoader,
|
|
hideLoader,
|
|
messageError,
|
|
success,
|
|
date2Thai,
|
|
onSearchDataTable,
|
|
} = useCounterMixin();
|
|
|
|
/** Table*/
|
|
const rows = ref<ListWebServices[]>([]); //รายการ webservices
|
|
const rowsMain = ref<ListWebServices[]>([]); //รายการ webservices
|
|
const keyword = ref<string>(""); //คำค้นหา รายการ webservices
|
|
const visibleColumns = ref<string[]>([
|
|
"name",
|
|
"apiNames",
|
|
"amount",
|
|
"createdAt",
|
|
"createdFullName",
|
|
]);
|
|
const columns = ref<QTableProps["columns"]>([
|
|
{
|
|
name: "name",
|
|
align: "left",
|
|
label: "ชื่อ-คำอธิบาย",
|
|
sortable: true,
|
|
field: "name",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
{
|
|
name: "apiNames",
|
|
align: "left",
|
|
label: "API ที่เข้าถึง",
|
|
sortable: true,
|
|
field: "apiNames",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
format(val) {
|
|
return val
|
|
.map((e: ResApiName) => `<div class='q-mt-sm'>- ${e.name}</div>`)
|
|
.join("");
|
|
},
|
|
},
|
|
{
|
|
name: "amount",
|
|
align: "left",
|
|
label: "สถิติ ",
|
|
sortable: true,
|
|
field: "amount",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
{
|
|
name: "createdAt",
|
|
align: "left",
|
|
label: "วันที่สร้าง",
|
|
sortable: true,
|
|
field: "createdAt",
|
|
format(val) {
|
|
return date2Thai(val, false, true);
|
|
},
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
|
|
{
|
|
name: "createdFullName",
|
|
align: "left",
|
|
label: "ผู้ดำเนินการ",
|
|
sortable: true,
|
|
field: "createdFullName",
|
|
headerStyle: "font-size: 14px",
|
|
style: "font-size: 14px",
|
|
},
|
|
]);
|
|
|
|
/** API Key*/
|
|
const modalApiKey = ref<boolean>(false); //popup สร้าง API Key
|
|
|
|
/** usability*/
|
|
const modalUsability = ref<boolean>(false); //popup การใช้งาน
|
|
|
|
/** ฟังก์ชันเรียกข้อมูลรายการ Web services*/
|
|
async function fetchListWebServices() {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.apiKeyMain + "/list")
|
|
.then(async (res) => {
|
|
const data = await res.data.result;
|
|
rows.value = data;
|
|
rowsMain.value = data;
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
/**
|
|
* ฟังก์ชัน ลบข้อมูลรายการ Web services
|
|
* @param id รายการ Web services ที่ต้องการลบ
|
|
* เมื่อสำเร็จจะเรียกฟังก์ชัน 'fetchListWebServices' มาเรียกข้อมูลรายการ web servcice ใหม่
|
|
*/
|
|
function onDeleteData(id: string) {
|
|
dialogRemove($q, () => {
|
|
showLoader();
|
|
http
|
|
.delete(config.API.apiKeyMain + `/${id}`)
|
|
.then(async () => {
|
|
// เรียกข้อมูลรายการ web servcice ใหม่
|
|
await fetchListWebServices();
|
|
success($q, "ลบข้อมูลสำเร็จ");
|
|
})
|
|
.catch((err) => {
|
|
messageError($q, err);
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
});
|
|
}
|
|
|
|
function serchDataTable() {
|
|
rows.value = onSearchDataTable(
|
|
keyword.value,
|
|
rowsMain.value,
|
|
columns.value ? columns.value : []
|
|
);
|
|
}
|
|
|
|
/** hook เมื่อเรียก Components จะเรียกฟังก์ชัน 'fetchListWebServices' เรียกข้อมูลรายการ webservices*/
|
|
onMounted(() => {
|
|
fetchListWebServices();
|
|
});
|
|
</script>
|
|
|
|
<template>
|
|
<div class="row items-center">
|
|
<q-space />
|
|
<q-btn
|
|
flat
|
|
color="public"
|
|
label="วิธีการใช้งาน"
|
|
@click.pervent="modalUsability = true"
|
|
/>
|
|
</div>
|
|
|
|
<div class="items-center col-12 row q-col-gutter-sm">
|
|
<q-btn
|
|
class="q-ml-sm"
|
|
flat
|
|
round
|
|
dense
|
|
color="primary"
|
|
icon="add"
|
|
@click.pervent="modalApiKey = true"
|
|
>
|
|
<q-tooltip>สร้าง API Key </q-tooltip>
|
|
</q-btn>
|
|
<q-space />
|
|
<q-input
|
|
borderless
|
|
dense
|
|
outlined
|
|
v-model="keyword"
|
|
placeholder="ค้นหา"
|
|
@keydown.enter.prevent="serchDataTable"
|
|
>
|
|
<template v-slot:append>
|
|
<q-icon name="search" />
|
|
</template>
|
|
</q-input>
|
|
<q-select
|
|
v-model="visibleColumns"
|
|
multiple
|
|
outlined
|
|
dense
|
|
options-dense
|
|
:display-value="$q.lang.table.columns"
|
|
emit-value
|
|
map-options
|
|
:options="columns"
|
|
option-value="name"
|
|
style="min-width: 140px"
|
|
/>
|
|
</div>
|
|
|
|
<!-- Table -->
|
|
<div class="col-12 q-pt-sm">
|
|
<d-table
|
|
ref="table"
|
|
:columns="columns"
|
|
:rows="rows"
|
|
row-key="id"
|
|
flat
|
|
bordered
|
|
:paging="true"
|
|
dense
|
|
:rows-per-page-options="[10, 25, 50, 100]"
|
|
:visible-columns="visibleColumns"
|
|
>
|
|
<template v-slot:header="props">
|
|
<q-tr :props="props">
|
|
<q-th auto-width />
|
|
<q-th v-for="col in props.cols" :key="col.name" :props="props">
|
|
<span class="text-weight-medium">{{ col.label }}</span>
|
|
</q-th>
|
|
</q-tr>
|
|
</template>
|
|
<template v-slot:body="props">
|
|
<q-tr :props="props">
|
|
<q-td auto-width>
|
|
<q-btn
|
|
dense
|
|
flat
|
|
round
|
|
color="red"
|
|
@click="onDeleteData(props.row.id)"
|
|
icon="delete"
|
|
>
|
|
<q-tooltip>ลบข้อมูล</q-tooltip>
|
|
</q-btn></q-td
|
|
>
|
|
<q-td v-for="col in props.cols" :key="col.name" :props="props">
|
|
<div v-html="col.value ? col.value : '-'"></div>
|
|
|
|
<div></div>
|
|
</q-td>
|
|
</q-tr>
|
|
</template>
|
|
</d-table>
|
|
</div>
|
|
|
|
<!-- สร้าง API Key -->
|
|
<DialogApiKey
|
|
v-model:modal="modalApiKey"
|
|
:fetch-data="fetchListWebServices"
|
|
/>
|
|
|
|
<!-- การใช้งาน -->
|
|
<DialogUsability v-model:modal="modalUsability" />
|
|
</template>
|
|
|
|
<style scoped></style>
|