จักการ API
This commit is contained in:
parent
45945de06f
commit
07dceb0f45
5 changed files with 649 additions and 150 deletions
|
|
@ -1,7 +1,9 @@
|
||||||
import env from "../index";
|
import env from "../index";
|
||||||
|
|
||||||
const apiKey = `${env.API_URI}/org/apiKey`;
|
const apiKey = `${env.API_URI}/org/apiKey`;
|
||||||
|
const apiManage = `${env.API_URI}/org/api-manage/`;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
apiKeyMain: apiKey,
|
apiKeyMain: apiKey,
|
||||||
|
apiManage: apiManage,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
420
src/modules/06_webservices/components/DialogApi.vue
Normal file
420
src/modules/06_webservices/components/DialogApi.vue
Normal file
|
|
@ -0,0 +1,420 @@
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, reactive, ref, toRefs, watch } from "vue";
|
||||||
|
import { useQuasar } from "quasar";
|
||||||
|
|
||||||
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
import { useDataStoreManage } from "@/modules/06_webservices/stores/manage";
|
||||||
|
|
||||||
|
import type { DataOption } from "@/modules/06_webservices/interface/index/Main";
|
||||||
|
|
||||||
|
/** importComponents*/
|
||||||
|
import DialogHeader from "@/components/DialogHeader.vue";
|
||||||
|
import http from "@/plugins/http";
|
||||||
|
import config from "@/app.config";
|
||||||
|
|
||||||
|
const $q = useQuasar();
|
||||||
|
const { systemList, methodOptions } = toRefs(useDataStoreManage());
|
||||||
|
const {
|
||||||
|
showLoader,
|
||||||
|
hideLoader,
|
||||||
|
dialogConfirm,
|
||||||
|
success,
|
||||||
|
dialogMessageNotify,
|
||||||
|
messageError,
|
||||||
|
} = useCounterMixin();
|
||||||
|
|
||||||
|
const modal = defineModel<boolean>("modal", { required: true });
|
||||||
|
const isEdit = defineModel<boolean>("isEdit", { default: false });
|
||||||
|
const apiId = defineModel<string>("apiId", { default: "" });
|
||||||
|
|
||||||
|
const props = defineProps({
|
||||||
|
fetchData: {
|
||||||
|
type: Function,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const titleName = computed(() => {
|
||||||
|
return isEdit.value ? "แก้ไข API" : "เพิ่ม API";
|
||||||
|
});
|
||||||
|
|
||||||
|
const options = computed<DataOption[]>(() => {
|
||||||
|
return systemList.value.filter((e) => e.id !== "all") ?? [];
|
||||||
|
});
|
||||||
|
|
||||||
|
const mainFields = computed(() => {
|
||||||
|
return availableFields.value.filter((field) => field.isMain === true);
|
||||||
|
});
|
||||||
|
|
||||||
|
const systemOptions = ref<DataOption[]>(options.value); // Default to first option
|
||||||
|
|
||||||
|
const apiPath = ref<string>("");
|
||||||
|
|
||||||
|
// Form data
|
||||||
|
const formData = reactive({
|
||||||
|
name: "",
|
||||||
|
methodApi: "GET",
|
||||||
|
system: "",
|
||||||
|
isActive: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
// เพิ่ม state สำหรับเก็บ fields และ attributes ที่เลือก
|
||||||
|
const availableFields = ref<any[]>([]);
|
||||||
|
const selectedAttributes = ref<Record<string, Record<string, boolean>>>({});
|
||||||
|
const loading = ref(false);
|
||||||
|
const validationErrors = ref<string[]>([]);
|
||||||
|
|
||||||
|
async function fetchData(system: string) {
|
||||||
|
availableFields.value = [];
|
||||||
|
loading.value = true;
|
||||||
|
try {
|
||||||
|
const res = await http.get(`${config.API.apiManage}${system}/fields`);
|
||||||
|
availableFields.value = res.data.result || [];
|
||||||
|
|
||||||
|
// Reset selected attributes เมื่อเปลี่ยน system
|
||||||
|
selectedAttributes.value = {};
|
||||||
|
|
||||||
|
// แยกแต่ละหัวข้อและ properties
|
||||||
|
availableFields.value.forEach((field) => {
|
||||||
|
// สร้าง group สำหรับแต่ละ field (หัวข้อ)
|
||||||
|
selectedAttributes.value[field.tb] = {};
|
||||||
|
|
||||||
|
if (field.propertys && field.propertys.length > 0) {
|
||||||
|
field.propertys.forEach((prop: any) => {
|
||||||
|
// เก็บ properties ในแต่ละ group
|
||||||
|
selectedAttributes.value[field.tb][prop.propertyName] = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching fields:", error);
|
||||||
|
availableFields.value = [];
|
||||||
|
} finally {
|
||||||
|
loading.value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchDataId(id: string) {
|
||||||
|
try {
|
||||||
|
const res = await http.get(`${config.API.apiManage}${id}`);
|
||||||
|
const data = res.data.result;
|
||||||
|
|
||||||
|
formData.name = data.name;
|
||||||
|
formData.methodApi = data.methodApi;
|
||||||
|
formData.system = data.system;
|
||||||
|
formData.isActive = data.isActive;
|
||||||
|
apiPath.value = data.pathApi;
|
||||||
|
|
||||||
|
// ดึง fields และ attributes ที่เกี่ยวข้อง
|
||||||
|
await fetchData(data.system);
|
||||||
|
|
||||||
|
console.log(data.apiAttributes);
|
||||||
|
|
||||||
|
// กำหนดค่า selectedAttributes ตามข้อมูลที่ดึงมา
|
||||||
|
if (data.apiAttributes?.length > 0) {
|
||||||
|
data.apiAttributes.forEach(
|
||||||
|
({ tbName, propertyKey }: { tbName: string; propertyKey: string }) => {
|
||||||
|
if (selectedAttributes.value[tbName]?.[propertyKey] !== undefined) {
|
||||||
|
selectedAttributes.value[tbName][propertyKey] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching API by ID:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
async function onSelectSystem(value: string) {
|
||||||
|
await fetchData(value);
|
||||||
|
console.log("value", value);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ฟังก์ชันตรวจสอบ validation
|
||||||
|
function validateSelection(): boolean {
|
||||||
|
validationErrors.value = [];
|
||||||
|
|
||||||
|
// ตรวจสอบหัวข้อที่เป็น isMain: true
|
||||||
|
mainFields.value.forEach((field) => {
|
||||||
|
const selectedPropsCount = Object.keys(
|
||||||
|
selectedAttributes.value[field.tb] || {}
|
||||||
|
).filter(
|
||||||
|
(propKey) => selectedAttributes.value[field.tb][propKey] === true
|
||||||
|
).length;
|
||||||
|
|
||||||
|
if (selectedPropsCount === 0) {
|
||||||
|
validationErrors.value.push(
|
||||||
|
`จำเป็นต้องเลือกข้อมูลในหมวด "${field.description}" อย่างน้อย 1 รายการ`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return validationErrors.value.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onSubmit() {
|
||||||
|
if (!validateSelection()) {
|
||||||
|
validationErrors.value.forEach((error) => {
|
||||||
|
dialogMessageNotify($q, error);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
dialogConfirm($q, async () => {
|
||||||
|
showLoader();
|
||||||
|
// สร้าง apiAttributes array
|
||||||
|
const apiAttributes: Array<{
|
||||||
|
tbName: string;
|
||||||
|
propertyKey: string[];
|
||||||
|
}> = [];
|
||||||
|
|
||||||
|
// วนลูปผ่าน selectedAttributes เพื่อสร้าง apiAttributes
|
||||||
|
Object.keys(selectedAttributes.value).forEach((fieldKey) => {
|
||||||
|
const selectedProps: string[] = [];
|
||||||
|
|
||||||
|
// เก็บเฉพาะ property ที่เลือก (true)
|
||||||
|
Object.keys(selectedAttributes.value[fieldKey]).forEach((propKey) => {
|
||||||
|
if (selectedAttributes.value[fieldKey][propKey]) {
|
||||||
|
selectedProps.push(propKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// ถ้ามี property ที่เลือก ให้เพิ่มเข้า apiAttributes
|
||||||
|
if (selectedProps.length > 0) {
|
||||||
|
apiAttributes.push({
|
||||||
|
tbName: fieldKey,
|
||||||
|
propertyKey: selectedProps,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// สร้างข้อมูลสำหรับส่งไป API
|
||||||
|
const payload = {
|
||||||
|
...formData,
|
||||||
|
apiAttributes: apiAttributes,
|
||||||
|
};
|
||||||
|
|
||||||
|
const method = isEdit.value ? http.put : http.post;
|
||||||
|
const pathAPI = isEdit.value
|
||||||
|
? `${config.API.apiManage}${apiId.value}`
|
||||||
|
: config.API.apiManage;
|
||||||
|
try {
|
||||||
|
await method(pathAPI, payload);
|
||||||
|
await props.fetchData(); // เรียกใช้ฟังก์ชัน fetchData ที่ส่งมาจาก parent component
|
||||||
|
success($q, "บันทึกข้อมูลสำเร็จ");
|
||||||
|
onCloseDialog();
|
||||||
|
} catch (error) {
|
||||||
|
messageError($q, error);
|
||||||
|
return;
|
||||||
|
} finally {
|
||||||
|
hideLoader();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function ค้นหาคำใน select
|
||||||
|
* @param val คำค้นหา
|
||||||
|
* @param update function
|
||||||
|
*/
|
||||||
|
function filterSelector(val: string, update: Function) {
|
||||||
|
update(() => {
|
||||||
|
const newVal = val.toLowerCase();
|
||||||
|
systemOptions.value = options.value.filter(
|
||||||
|
(v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onCloseDialog() {
|
||||||
|
modal.value = false;
|
||||||
|
formData.name = "";
|
||||||
|
formData.methodApi = "GET";
|
||||||
|
formData.system = "";
|
||||||
|
formData.isActive = false;
|
||||||
|
apiPath.value = "";
|
||||||
|
availableFields.value = [];
|
||||||
|
selectedAttributes.value = {};
|
||||||
|
validationErrors.value = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(modal, (newVal) => {
|
||||||
|
if (newVal && isEdit.value) {
|
||||||
|
systemOptions.value = options.value; // รีเซ็ตตัวเลือกเมื่อเปิด dialog
|
||||||
|
fetchDataId(apiId.value);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<q-dialog v-model="modal" full-height>
|
||||||
|
<q-card style="min-width: 90%">
|
||||||
|
<q-form
|
||||||
|
class="column full-height"
|
||||||
|
greedy
|
||||||
|
@submit.prevent
|
||||||
|
@validation-success="onSubmit"
|
||||||
|
>
|
||||||
|
<DialogHeader :tittle="titleName" :close="onCloseDialog" />
|
||||||
|
|
||||||
|
<q-separator />
|
||||||
|
|
||||||
|
<q-card-section class="col q-pt-none scroll">
|
||||||
|
<div class="q-pa-md">
|
||||||
|
<div class="row q-col-gutter-md q-mb-lg">
|
||||||
|
<div class="col-12 col-md-4">
|
||||||
|
<q-input
|
||||||
|
v-model="formData.name"
|
||||||
|
label="API Name"
|
||||||
|
outlined
|
||||||
|
dense
|
||||||
|
hide-bottom-space
|
||||||
|
lazy-rules
|
||||||
|
:rules="[(val:string) => !!val || 'กรุณากรอก API Name']"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-4">
|
||||||
|
<q-select
|
||||||
|
v-model="formData.methodApi"
|
||||||
|
label="Method"
|
||||||
|
:options="methodOptions"
|
||||||
|
outlined
|
||||||
|
dense
|
||||||
|
hide-bottom-space
|
||||||
|
disable
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div class="col-12 col-md-4">
|
||||||
|
<q-input
|
||||||
|
v-model="apiPath"
|
||||||
|
outlined
|
||||||
|
dense
|
||||||
|
hide-bottom-space
|
||||||
|
placeholder="Auto generate"
|
||||||
|
disable
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- System Selection -->
|
||||||
|
<div class="row q-mb-lg">
|
||||||
|
<div class="col-12 col-md-4">
|
||||||
|
<div class="text-subtitle2 q-mb-sm">เลือกระบบข้อมูล</div>
|
||||||
|
<q-select
|
||||||
|
dense
|
||||||
|
hide-bottom-space
|
||||||
|
outlined
|
||||||
|
option-label="name"
|
||||||
|
option-value="id"
|
||||||
|
emit-value
|
||||||
|
map-options
|
||||||
|
v-model="formData.system"
|
||||||
|
:options="systemOptions"
|
||||||
|
use-input
|
||||||
|
hide-selected
|
||||||
|
fill-input
|
||||||
|
lazy-rules
|
||||||
|
:rules="[(val:string) => !!val || 'กรุณาเลือกระบบข้อมูล']"
|
||||||
|
@update:model-value="onSelectSystem"
|
||||||
|
@filter="(inputValue: string,doneFn: Function) => filterSelector(inputValue, doneFn )"
|
||||||
|
>
|
||||||
|
<template v-slot:no-option>
|
||||||
|
<q-item>
|
||||||
|
<q-item-section class="text-grey">
|
||||||
|
ไม่มีข้อมูล
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Attributes Section -->
|
||||||
|
<div
|
||||||
|
class="q-mb-lg"
|
||||||
|
v-if="formData.system !== '' && availableFields.length > 0"
|
||||||
|
>
|
||||||
|
<div class="text-subtitle2 q-mb-md">
|
||||||
|
Attribute ที่ต้องการให้มีการเชื่อมโยงข้อมูลแบบที่
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="row q-col-gutter-md">
|
||||||
|
<!-- Loop through available fields -->
|
||||||
|
<div
|
||||||
|
v-for="field in availableFields"
|
||||||
|
:key="field.tb"
|
||||||
|
class="col-xs-6 col-md-3"
|
||||||
|
>
|
||||||
|
<!-- หัวข้อหมวดหมู่ - ไม่สามารถเลือกได้ -->
|
||||||
|
<div class="text-subtitle1 border-bottom">
|
||||||
|
{{ field.description }}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Properties ที่สามารถเลือกได้ -->
|
||||||
|
|
||||||
|
<div
|
||||||
|
v-if="field.propertys && field.propertys.length > 0"
|
||||||
|
v-for="property in field.propertys"
|
||||||
|
:key="property.propertyName"
|
||||||
|
>
|
||||||
|
<q-item tag="label" v-ripple>
|
||||||
|
<q-item-section avatar>
|
||||||
|
<q-checkbox
|
||||||
|
v-model="
|
||||||
|
selectedAttributes[field.tb][property.propertyName]
|
||||||
|
"
|
||||||
|
/>
|
||||||
|
</q-item-section>
|
||||||
|
<q-item-section>
|
||||||
|
<q-item-label>{{ property.comment }}</q-item-label>
|
||||||
|
<q-item-label caption>
|
||||||
|
{{ property.propertyName }} ({{ property.type }})
|
||||||
|
</q-item-label>
|
||||||
|
</q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- ถ้าไม่มี properties แสดงข้อความว่าง -->
|
||||||
|
<div v-else class="q-ml-md text-grey-6 text-caption q-mb-sm">
|
||||||
|
ไม่มี attributes ย่อยสำหรับหมวดนี้
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Loading state -->
|
||||||
|
<div v-else-if="loading" class="text-center q-pa-md">
|
||||||
|
<q-spinner-dots size="40px" color="primary" />
|
||||||
|
<div class="q-mt-sm">กำลังโหลดข้อมูล...</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Empty state -->
|
||||||
|
<div
|
||||||
|
v-else-if="
|
||||||
|
formData.system !== '' &&
|
||||||
|
availableFields.length === 0 &&
|
||||||
|
!loading
|
||||||
|
"
|
||||||
|
class="text-center q-pa-md"
|
||||||
|
>
|
||||||
|
<q-icon name="info" size="40px" color="grey" />
|
||||||
|
<div class="q-mt-sm text-grey">
|
||||||
|
ไม่มีข้อมูล Attributes สำหรับระบบนี้
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-separator />
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn unelevated label="บันทึก" color="public" type="submit" />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-form>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.scroll {
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
14
src/modules/06_webservices/stores/manage.ts
Normal file
14
src/modules/06_webservices/stores/manage.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
import { defineStore } from "pinia";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
|
import type { DataOption } from "@/modules/06_webservices/interface/index/Main";
|
||||||
|
|
||||||
|
export const useDataStoreManage = defineStore("webservicesManage", () => {
|
||||||
|
const systemList = ref<DataOption[]>([{ id: "all", name: "ระบบทั้งหมด" }]);
|
||||||
|
const methodOptions = ["GET", "POST", "PUT", "DELETE"];
|
||||||
|
|
||||||
|
return {
|
||||||
|
systemList,
|
||||||
|
methodOptions,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
@ -36,8 +36,7 @@ const tabs = ref<string>("list");
|
||||||
<q-tab-panel name="list"> <ListView /> </q-tab-panel>
|
<q-tab-panel name="list"> <ListView /> </q-tab-panel>
|
||||||
<q-tab-panel name="log"> <LogView /> </q-tab-panel>
|
<q-tab-panel name="log"> <LogView /> </q-tab-panel>
|
||||||
<q-tab-panel name="manage">
|
<q-tab-panel name="manage">
|
||||||
<div style="min-height: 50em"></div>
|
<ManageWebServices />
|
||||||
<!-- <ManageWebServices /> -->
|
|
||||||
</q-tab-panel>
|
</q-tab-panel>
|
||||||
</q-tab-panels>
|
</q-tab-panels>
|
||||||
</q-card>
|
</q-card>
|
||||||
|
|
|
||||||
|
|
@ -1,22 +1,24 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted, ref } from "vue";
|
import { onMounted, ref, toRefs } from "vue";
|
||||||
import { useQuasar } from "quasar";
|
import { useQuasar } from "quasar";
|
||||||
|
|
||||||
import { useCounterMixin } from "@/stores/mixin";
|
import { useCounterMixin } from "@/stores/mixin";
|
||||||
|
import { useDataStoreManage } from "@/modules/06_webservices/stores/manage";
|
||||||
import http from "@/plugins/http";
|
import http from "@/plugins/http";
|
||||||
import config from "@/app.config";
|
import config from "@/app.config";
|
||||||
|
|
||||||
/** importType*/
|
/** importType*/
|
||||||
import type { QTableProps } from "quasar";
|
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 { ListWebServices } from "@/modules/06_webservices/interface/index/Main";
|
||||||
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main";
|
import type { ResApiName } from "@/modules/06_webservices/interface/response/Main";
|
||||||
|
|
||||||
/** importComponents*/
|
/** importComponents*/
|
||||||
import DialogApiKey from "@/modules/06_webservices/components/DialogApiKey.vue"; //สร้าง API Key
|
import DialogApi from "@/modules/06_webservices/components/DialogApi.vue";
|
||||||
import DialogUsability from "@/modules/06_webservices/components/DialogUsability.vue"; //การใช้งาน
|
|
||||||
|
|
||||||
/** use*/
|
/** use*/
|
||||||
const $q = useQuasar();
|
const $q = useQuasar();
|
||||||
|
const { systemList } = toRefs(useDataStoreManage());
|
||||||
const {
|
const {
|
||||||
dialogRemove,
|
dialogRemove,
|
||||||
showLoader,
|
showLoader,
|
||||||
|
|
@ -24,188 +26,242 @@ const {
|
||||||
messageError,
|
messageError,
|
||||||
success,
|
success,
|
||||||
date2Thai,
|
date2Thai,
|
||||||
onSearchDataTable,
|
|
||||||
} = useCounterMixin();
|
} = useCounterMixin();
|
||||||
|
|
||||||
|
const systemOptions = ref<DataOption[]>(systemList.value);
|
||||||
|
|
||||||
/** Table*/
|
/** Table*/
|
||||||
const rows = ref<ListWebServices[]>([]); //รายการ webservices
|
const page = ref<number>(1); //หน้า
|
||||||
const rowsMain = ref<ListWebServices[]>([]); //รายการ webservices
|
const pageSize = ref<number>(10); //จำนวนรายการต่อหน้า
|
||||||
|
const rows = ref<any[]>([]); //รายการ webservices
|
||||||
const keyword = ref<string>(""); //คำค้นหา รายการ webservices
|
const keyword = ref<string>(""); //คำค้นหา รายการ webservices
|
||||||
|
const systemfilter = ref<string>("all"); //ตัวกรองระบบ
|
||||||
const visibleColumns = ref<string[]>([
|
const visibleColumns = ref<string[]>([
|
||||||
|
"system",
|
||||||
"name",
|
"name",
|
||||||
"apiNames",
|
"methodApi",
|
||||||
"amount",
|
"pathApi",
|
||||||
"createdAt",
|
"lastUpdatedAt",
|
||||||
"createdFullName",
|
|
||||||
]);
|
]);
|
||||||
const columns = ref<QTableProps["columns"]>([
|
const columns = ref<QTableProps["columns"]>([
|
||||||
|
{
|
||||||
|
name: "system",
|
||||||
|
align: "left",
|
||||||
|
label: "System",
|
||||||
|
sortable: true,
|
||||||
|
field: "system",
|
||||||
|
headerStyle: "font-size: 14px",
|
||||||
|
style: "font-size: 14px",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
name: "name",
|
name: "name",
|
||||||
align: "left",
|
align: "left",
|
||||||
label: "ชื่อ-คำอธิบาย",
|
label: "API Name",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: "name",
|
field: "name",
|
||||||
headerStyle: "font-size: 14px",
|
headerStyle: "font-size: 14px",
|
||||||
style: "font-size: 14px",
|
style: "font-size: 14px",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "apiNames",
|
name: "methodApi",
|
||||||
align: "left",
|
align: "left",
|
||||||
label: "API ที่เข้าถึง",
|
label: "Method",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: "apiNames",
|
field: "methodApi",
|
||||||
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",
|
headerStyle: "font-size: 14px",
|
||||||
style: "font-size: 14px",
|
style: "font-size: 14px",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "createdAt",
|
name: "pathApi",
|
||||||
align: "left",
|
align: "left",
|
||||||
label: "วันที่สร้าง",
|
label: "API Path",
|
||||||
sortable: true,
|
sortable: true,
|
||||||
field: "createdAt",
|
field: "pathApi",
|
||||||
|
headerStyle: "font-size: 14px",
|
||||||
|
style: "font-size: 14px",
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "lastUpdatedAt",
|
||||||
|
align: "left",
|
||||||
|
label: "updatedAt",
|
||||||
|
sortable: true,
|
||||||
|
field: "lastUpdatedAt",
|
||||||
|
headerStyle: "font-size: 14px",
|
||||||
|
style: "font-size: 14px",
|
||||||
format(val) {
|
format(val) {
|
||||||
return date2Thai(val, false, true);
|
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 modalDialog = ref<boolean>(false); //ตัวแปรเปิดปิด dialog
|
||||||
const modalApiKey = ref<boolean>(false); //popup สร้าง API Key
|
const isEditData = ref<boolean>(false); //ตัวแปรเช็คว่าเป็นการแก้ไขข้อมูลหรือไม่
|
||||||
|
const apiId = ref<string>(""); //ตัวแปรเก็บ id ของ api ที่จะแก้ไข
|
||||||
|
|
||||||
/** usability*/
|
async function fetchSystemData() {
|
||||||
const modalUsability = ref<boolean>(false); //popup การใช้งาน
|
if (systemList.value.length > 1) return; // ถ้ามีข้อมูลแล้วไม่ต้องดึงใหม่
|
||||||
|
try {
|
||||||
/** ฟังก์ชันเรียกข้อมูลรายการ Web services*/
|
const res = await http.get(`${config.API.apiManage}systems`);
|
||||||
async function fetchListWebServices() {
|
const data = res.data.result;
|
||||||
showLoader();
|
const systemData = data.map((item: any) => ({
|
||||||
await http
|
id: item.code,
|
||||||
.get(config.API.apiKeyMain + "/list")
|
name: item.name,
|
||||||
.then(async (res) => {
|
}));
|
||||||
const data = await res.data.result;
|
systemList.value.push(...systemData);
|
||||||
rows.value = data;
|
} catch (error) {
|
||||||
rowsMain.value = data;
|
messageError(error);
|
||||||
})
|
}
|
||||||
.catch((err) => {
|
}
|
||||||
messageError($q, err);
|
|
||||||
})
|
async function fetchData() {
|
||||||
.finally(() => {
|
try {
|
||||||
hideLoader();
|
const queryParams = {
|
||||||
});
|
page: page.value,
|
||||||
|
pageSize: pageSize.value,
|
||||||
|
keyword: keyword.value,
|
||||||
|
systems: systemfilter.value === "all" ? "" : systemfilter.value,
|
||||||
|
};
|
||||||
|
|
||||||
|
const res = await http.get(`${config.API.apiManage}lists`, {
|
||||||
|
params: queryParams,
|
||||||
|
});
|
||||||
|
const result = res.data.result;
|
||||||
|
rows.value = result.data;
|
||||||
|
} catch (error) {
|
||||||
|
messageError(error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ฟังก์ชัน ลบข้อมูลรายการ Web services
|
|
||||||
* @param id รายการ Web services ที่ต้องการลบ
|
|
||||||
* เมื่อสำเร็จจะเรียกฟังก์ชัน 'fetchListWebServices' มาเรียกข้อมูลรายการ web servcice ใหม่
|
|
||||||
*/
|
|
||||||
function onDeleteData(id: string) {
|
function onDeleteData(id: string) {
|
||||||
dialogRemove($q, () => {
|
dialogRemove($q, async () => {
|
||||||
showLoader();
|
try {
|
||||||
http
|
showLoader();
|
||||||
.delete(config.API.apiKeyMain + `/${id}`)
|
await http.delete(`${config.API.apiManage}${id}`);
|
||||||
.then(async () => {
|
await fetchData();
|
||||||
// เรียกข้อมูลรายการ web servcice ใหม่
|
success($q, "ลบข้อมูลสำเร็จ");
|
||||||
await fetchListWebServices();
|
} catch (error) {
|
||||||
success($q, "ลบข้อมูลสำเร็จ");
|
messageError($q, error);
|
||||||
})
|
} finally {
|
||||||
.catch((err) => {
|
hideLoader();
|
||||||
messageError($q, err);
|
}
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
hideLoader();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function serchDataTable() {
|
function onEditData(id: string) {
|
||||||
rows.value = onSearchDataTable(
|
isEditData.value = true;
|
||||||
keyword.value,
|
modalDialog.value = true;
|
||||||
rowsMain.value,
|
apiId.value = id; // เก็บ id ของ api ที่จะแก้ไข
|
||||||
columns.value ? columns.value : []
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** hook เมื่อเรียก Components จะเรียกฟังก์ชัน 'fetchListWebServices' เรียกข้อมูลรายการ webservices*/
|
function onSearchDataTable() {
|
||||||
onMounted(() => {
|
page.value = 1; // รีเซ็ตหน้าเป็น 1 เมื่อค้นหาใหม่
|
||||||
fetchListWebServices();
|
fetchData();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* function ค้นหาคำใน select
|
||||||
|
* @param val คำค้นหา
|
||||||
|
* @param update function
|
||||||
|
*/
|
||||||
|
function filterSelector(val: string, update: Function) {
|
||||||
|
update(() => {
|
||||||
|
const newVal = val.toLowerCase();
|
||||||
|
systemOptions.value = systemList.value.filter(
|
||||||
|
(v: DataOption) => v.name.toLowerCase().indexOf(newVal) > -1
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
try {
|
||||||
|
showLoader();
|
||||||
|
await fetchSystemData();
|
||||||
|
await fetchData();
|
||||||
|
} catch (error) {
|
||||||
|
messageError(error);
|
||||||
|
} finally {
|
||||||
|
hideLoader();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<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">
|
<div class="items-center col-12 row q-col-gutter-sm">
|
||||||
<q-btn
|
<div class="items-center row q-col-gutter-sm col-xs-12 col-sm-auto">
|
||||||
class="q-ml-sm"
|
<div class="col-xs-12 col-sm-auto">
|
||||||
flat
|
<q-select
|
||||||
round
|
dense
|
||||||
dense
|
hide-bottom-space
|
||||||
color="primary"
|
outlined
|
||||||
icon="add"
|
option-label="name"
|
||||||
@click.pervent="modalApiKey = true"
|
option-value="id"
|
||||||
>
|
emit-value
|
||||||
<q-tooltip>สร้าง API Key </q-tooltip>
|
map-options
|
||||||
</q-btn>
|
v-model="systemfilter"
|
||||||
|
:options="systemOptions"
|
||||||
|
label="ระบบ"
|
||||||
|
use-input
|
||||||
|
hide-selected
|
||||||
|
fill-input
|
||||||
|
:clearable="systemfilter !== 'all'"
|
||||||
|
@clear="systemfilter = 'all'"
|
||||||
|
@filter="(inputValue: string,doneFn: Function) => filterSelector(inputValue, doneFn )"
|
||||||
|
@update:model-value="onSearchDataTable"
|
||||||
|
>
|
||||||
|
<template v-slot:no-option>
|
||||||
|
<q-item>
|
||||||
|
<q-item-section class="text-grey"> ไม่มีข้อมูล </q-item-section>
|
||||||
|
</q-item>
|
||||||
|
</template>
|
||||||
|
</q-select>
|
||||||
|
</div>
|
||||||
|
<div class="col-xs-12 col-sm-auto">
|
||||||
|
<q-btn
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
dense
|
||||||
|
color="primary"
|
||||||
|
icon="add"
|
||||||
|
@click="(modalDialog = true), (isEditData = false)"
|
||||||
|
>
|
||||||
|
<q-tooltip>สร้าง API Key </q-tooltip>
|
||||||
|
</q-btn>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<q-space />
|
<q-space />
|
||||||
<q-input
|
<div class="row q-col-gutter-sm col-xs-12 col-sm-auto">
|
||||||
borderless
|
<div class="col-xs-12 col-sm-auto">
|
||||||
dense
|
<q-input
|
||||||
outlined
|
borderless
|
||||||
v-model="keyword"
|
dense
|
||||||
placeholder="ค้นหา"
|
outlined
|
||||||
@keydown.enter.prevent="serchDataTable"
|
v-model="keyword"
|
||||||
>
|
placeholder="ค้นหา"
|
||||||
<template v-slot:append>
|
@keydown.enter.prevent="onSearchDataTable"
|
||||||
<q-icon name="search" />
|
>
|
||||||
</template>
|
<template v-slot:append>
|
||||||
</q-input>
|
<q-icon name="search" />
|
||||||
<q-select
|
</template>
|
||||||
v-model="visibleColumns"
|
</q-input>
|
||||||
multiple
|
</div>
|
||||||
outlined
|
<div class="col-xs-12 col-sm-auto">
|
||||||
dense
|
<q-select
|
||||||
options-dense
|
v-model="visibleColumns"
|
||||||
:display-value="$q.lang.table.columns"
|
multiple
|
||||||
emit-value
|
outlined
|
||||||
map-options
|
dense
|
||||||
:options="columns"
|
options-dense
|
||||||
option-value="name"
|
:display-value="$q.lang.table.columns"
|
||||||
style="min-width: 140px"
|
emit-value
|
||||||
/>
|
map-options
|
||||||
|
:options="columns"
|
||||||
|
option-value="name"
|
||||||
|
style="min-width: 140px"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Table -->
|
<!-- Table -->
|
||||||
|
|
@ -233,6 +289,16 @@ onMounted(() => {
|
||||||
<template v-slot:body="props">
|
<template v-slot:body="props">
|
||||||
<q-tr :props="props">
|
<q-tr :props="props">
|
||||||
<q-td auto-width>
|
<q-td auto-width>
|
||||||
|
<q-btn
|
||||||
|
dense
|
||||||
|
flat
|
||||||
|
round
|
||||||
|
color="edit"
|
||||||
|
@click="onEditData(props.row.id)"
|
||||||
|
icon="mdi-square-edit-outline"
|
||||||
|
>
|
||||||
|
<q-tooltip>แก้ไขข้อมูล</q-tooltip>
|
||||||
|
</q-btn>
|
||||||
<q-btn
|
<q-btn
|
||||||
dense
|
dense
|
||||||
flat
|
flat
|
||||||
|
|
@ -242,8 +308,8 @@ onMounted(() => {
|
||||||
icon="delete"
|
icon="delete"
|
||||||
>
|
>
|
||||||
<q-tooltip>ลบข้อมูล</q-tooltip>
|
<q-tooltip>ลบข้อมูล</q-tooltip>
|
||||||
</q-btn></q-td
|
</q-btn>
|
||||||
>
|
</q-td>
|
||||||
<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 v-html="col.value ? col.value : '-'"></div>
|
<div v-html="col.value ? col.value : '-'"></div>
|
||||||
|
|
||||||
|
|
@ -254,14 +320,12 @@ onMounted(() => {
|
||||||
</d-table>
|
</d-table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- สร้าง API Key -->
|
<DialogApi
|
||||||
<DialogApiKey
|
v-model:modal="modalDialog"
|
||||||
v-model:modal="modalApiKey"
|
:is-edit="isEditData"
|
||||||
:fetch-data="fetchListWebServices"
|
:api-id="apiId"
|
||||||
|
:fetch-data="fetchData"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- การใช้งาน -->
|
|
||||||
<DialogUsability v-model:modal="modalUsability" />
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<style scoped></style>
|
<style scoped></style>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue