web services
This commit is contained in:
parent
c0c5aab386
commit
bc80b24cf5
4 changed files with 755 additions and 243 deletions
273
src/modules/06_webservices/view/listView.vue
Normal file
273
src/modules/06_webservices/view/listView.vue
Normal file
|
|
@ -0,0 +1,273 @@
|
|||
<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,
|
||||
} = useCounterMixin();
|
||||
|
||||
/** Table*/
|
||||
const rows = 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;
|
||||
})
|
||||
.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();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/** hook เมื่อเรียก Components จะเรียกฟังก์ชัน 'fetchListWebServices' เรียกข้อมูลรายการ webservices*/
|
||||
onMounted(() => {
|
||||
fetchListWebServices();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="row items-center">
|
||||
<!-- <div class="toptitle text-dark row items-center q-py-xs">
|
||||
รายการ web services
|
||||
</div> -->
|
||||
<q-space />
|
||||
<q-btn
|
||||
flat
|
||||
color="public"
|
||||
label="วิธีการใช้งาน"
|
||||
@click.pervent="modalUsability = true"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<!-- <q-card flast bordered class="q-pa-md"> -->
|
||||
<!-- toolbar -->
|
||||
<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
|
||||
clearable
|
||||
v-model="keyword"
|
||||
placeholder="ค้นหา"
|
||||
@clear="keyword = ''"
|
||||
>
|
||||
<template v-slot:append v-if="keyword === ''">
|
||||
<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"
|
||||
:filter="keyword"
|
||||
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-if="col.name === 'apiNames'">
|
||||
<q-list dense>
|
||||
<q-item v-for="(item, key) in col.value">
|
||||
<q-item-section>- {{ item.name }}</q-item-section>
|
||||
</q-item>
|
||||
</q-list>
|
||||
</div> -->
|
||||
<div v-html="col.value ? col.value : '-'"></div>
|
||||
|
||||
<div>
|
||||
<!-- {{ col.value ? col.value : "-" }} -->
|
||||
</div>
|
||||
</q-td>
|
||||
</q-tr>
|
||||
</template>
|
||||
</d-table>
|
||||
</div>
|
||||
<!-- </q-card> -->
|
||||
|
||||
<!-- สร้าง API Key -->
|
||||
<DialogApiKey
|
||||
v-model:modal="modalApiKey"
|
||||
:fetch-data="fetchListWebServices"
|
||||
/>
|
||||
|
||||
<!-- การใช้งาน -->
|
||||
<DialogUsability v-model:modal="modalUsability" />
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
Loading…
Add table
Add a link
Reference in a new issue