From c33b218455727f63df68012bd00192b3285db710 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 3 Nov 2025 14:17:42 +0700 Subject: [PATCH 1/4] feat:select org --- .../02_users/interface/response/Main.ts | 5 + .../components/DialogApiKey.vue | 383 ++++++++++++++---- .../06_webservices/interface/request/Main.ts | 11 +- 3 files changed, 313 insertions(+), 86 deletions(-) diff --git a/src/modules/02_users/interface/response/Main.ts b/src/modules/02_users/interface/response/Main.ts index 732fd5c9..c446f746 100644 --- a/src/modules/02_users/interface/response/Main.ts +++ b/src/modules/02_users/interface/response/Main.ts @@ -49,6 +49,11 @@ interface NodeTree { totalRootPositionNextVacant: number; children: NodeTree[]; isOfficer: boolean; + orgRootDnaId: string; + orgChild1DnaId: string; + orgChild2DnaId: string; + orgChild3DnaId: string; + orgChild4DnaId: string; } interface PosMaster { diff --git a/src/modules/06_webservices/components/DialogApiKey.vue b/src/modules/06_webservices/components/DialogApiKey.vue index 3111eeb3..b642c1fe 100644 --- a/src/modules/06_webservices/components/DialogApiKey.vue +++ b/src/modules/06_webservices/components/DialogApiKey.vue @@ -3,13 +3,18 @@ import { computed, reactive, ref, watch } from "vue"; import { useQuasar } from "quasar"; import { useCounterMixin } from "@/stores/mixin"; +import { tokenParsed } from "@/plugins/auth"; import http from "@/plugins/http"; import config from "@/app.config"; /** importType*/ import type { ListApi } from "@/modules/06_webservices/interface/index/Main"; -import type { FormCreate } from "@/modules/06_webservices/interface/request/Main"; +import type { + FormCreate, + DnaId, +} from "@/modules/06_webservices/interface/request/Main"; import type { ResApiName } from "@/modules/06_webservices/interface/response/Main"; +import type { NodeTree } from "@/modules/02_users/interface/response/Main"; /** importComponents*/ import DialogHeader from "@/components/DialogHeader.vue"; @@ -35,24 +40,44 @@ const props = defineProps({ }); const topicRef = ref(null); //refinput ชื่อ/คำอธิบาย +const accessTypeRef = ref(null); //ref select การเข้าถึง const isAPIKey = ref(false); //status API Key const apiKey = ref(""); // API Key const options = ref([]); //รายการ API ที่เข้าถึงได้ +const optionsAccessType = ref([ + { label: "ทั้งหมด", value: "ALL" }, + { label: "ROOT", value: "ROOT" }, + { label: "CHILD", value: "CHILD" }, + { label: "NORMAL", value: "NORMAL" }, +]); // form การสร้างรายการ API Key const formData = reactive({ name: "", //ชื่อ/คำอธิบาย + accessType: "", //การเข้าถึง apiId: [], //id รายการ API ที่เข้าถึงได้ }); +const dnaId = reactive({ + dnaRootId: "", + dnaChild1Id: "", + dnaChild2Id: "", + dnaChild3Id: "", + dnaChild4Id: "", +}); + +const filter = ref(""); // ตัวกรองค้นหา +const expanded = ref([]); // ขยายรายการ tree +const orgId = ref(""); // รหัสหน่วยงาน +const nodeTree = ref>([]); +const lazy = ref(nodeTree); const titleName = computed(() => { return !isAPIKey.value ? "สร้าง API Key" : "API Key"; }); /** ฟังก์ชันเรียกรายการข้อมูล API ที่เข้าถึงได้*/ -function fetchListApiKeyName() { - showLoader(); - http +async function fetchListApiKeyName() { + await http .get(config.API.apiKeyMain + "/name") .then(async (res) => { const data = (await res.data?.result) || []; @@ -63,42 +88,50 @@ function fetchListApiKeyName() { }) .catch((err) => { messageError($q, err); - }) - .finally(() => { - hideLoader(); }); } /** ฟังก์ชันยืนยันการสร้าง API Key */ function onCreateAPIKey() { topicRef.value.validate(); + accessTypeRef.value.validate(); + + const isCheckRootID = orgId.value ? true : false; + const isCheckAscessType = formData.accessType === "ALL" ? true : false; + //เช็คข้อมูล ชื่อ/คำอธิบาย - if (topicRef.value.validate()) { + if (topicRef.value.validate() && accessTypeRef.value.validate()) { // ช็คข้อมูล รายการ API ที่เข้าถึงได้ที่เลือก ถ้ามีแสดง popup ยืนยันการสร้าง API Key - if (formData.apiId.length > 0) { - dialogConfirm($q, async () => { - showLoader(); - await http - .post(config.API.apiKeyMain, { - ...formData, - name: formData.name.replace(/\s+/g, ""), //ตัดช่องว่างทั้งหมด - }) - .then(async (res) => { - const data = await res.data.result; - apiKey.value = data; - success($q, "สร้าง API Key สำเร็จ"); - isAPIKey.value = true; - }) - .catch((err) => { - messageError($q, err); - }) - .finally(() => { - hideLoader(); - }); - }); + + if (!isCheckAscessType && !isCheckRootID) { + dialogMessageNotify($q, "กรุณาเลือก หน่วยงาน/ส่วนราชการ"); } else { - //ไม่มีรายการ แสดง Popup กรุณาเลือก API ที่เข้าถึงได้ - dialogMessageNotify($q, "กรุณาเลือก API ที่เข้าถึงได้"); + if (formData.apiId.length > 0) { + dialogConfirm($q, async () => { + showLoader(); + await http + .post(config.API.apiKeyMain, { + ...formData, + name: formData.name.replace(/\s+/g, ""), //ตัดช่องว่างทั้งหมด + ...dnaId, + }) + .then(async (res) => { + const data = await res.data.result; + apiKey.value = data; + success($q, "สร้าง API Key สำเร็จ"); + isAPIKey.value = true; + }) + .catch((err) => { + messageError($q, err); + }) + .finally(() => { + hideLoader(); + }); + }); + } else { + //ไม่มีรายการ แสดง Popup กรุณาเลือก API ที่เข้าถึงได้ + dialogMessageNotify($q, "กรุณาเลือก API ที่เข้าถึงได้"); + } } } } @@ -120,78 +153,243 @@ function onCloseDialog() { modal.value = false; isAPIKey.value = false; formData.name = ""; + formData.accessType = ""; formData.apiId = []; + nodeTree.value = []; + expanded.value = []; +} + +/** ฟังก์ชันเรียกข้อมูลโครงสร้าง แบบปัจุบัน*/ +async function fetchOrganizationActive() { + await http + .get(config.API.activeOrganization) + .then(async (res) => { + const data = res.data.result; + if (data) { + // activeId.value = data.activeId; + await fetchDataTree(data.activeId); + } + }) + .catch((err) => { + messageError($q, err); + }); +} + +/** + * ฟังก์ชัน fetch ข้อมูลของโครงสร้าง + * @param id id โครงสร้าง + */ +async function fetchDataTree(id: string) { + const tokenParsedData = await tokenParsed(); + const isSuperAdmin = tokenParsedData.role.includes("SUPER_ADMIN"); + if (!isSuperAdmin) { + nodeTree.value = []; + } + await http + .get(config.API.orgByid(id.toString())) + .then(async (res) => { + const data = await res.data.result; + nodeTree.value.push(...data); + }) + .catch((err) => { + messageError($q, err); + }); +} + +async function selectedOrg(node: NodeTree) { + if (node.orgTreeId) { + orgId.value = node.orgTreeId; + dnaId.dnaRootId = node.orgRootDnaId || ""; + dnaId.dnaChild1Id = node.orgChild1DnaId || ""; + dnaId.dnaChild2Id = node.orgChild2DnaId || ""; + dnaId.dnaChild3Id = node.orgChild3DnaId || ""; + dnaId.dnaChild4Id = node.orgChild4DnaId || ""; + } +} + +async function onChangeAccessType(val: string) { + if (val === "ALL") { + orgId.value = ""; + dnaId.dnaRootId = ""; + dnaId.dnaChild1Id = ""; + dnaId.dnaChild2Id = ""; + dnaId.dnaChild3Id = ""; + dnaId.dnaChild4Id = ""; + } } /** * ดูการเปลี่ยนแปลงข้อมูลของ `modal` * ถ้า modal เป็น True เรียกรายการข้อมูล API ที่เข้าถึงได้ */ -watch(modal, (val) => { +watch(modal, async (val) => { if (val) { - fetchListApiKeyName(); + try { + showLoader(); + await Promise.all([fetchOrganizationActive(), fetchListApiKeyName()]); + } finally { + hideLoader(); + } } }); - + diff --git a/src/modules/06_webservices/interface/request/Main.ts b/src/modules/06_webservices/interface/request/Main.ts index e60b1cbd..7870a5f3 100644 --- a/src/modules/06_webservices/interface/request/Main.ts +++ b/src/modules/06_webservices/interface/request/Main.ts @@ -1,6 +1,15 @@ interface FormCreate { name: string; + accessType: string; apiId: string[]; } -export type { FormCreate }; +interface DnaId { + dnaRootId: string; + dnaChild1Id: string; + dnaChild2Id: string; + dnaChild3Id: string; + dnaChild4Id: string; +} + +export type { FormCreate, DnaId }; From a3ddff981aab651aff23e2de597ec7df54edee03 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Mon, 3 Nov 2025 16:21:37 +0700 Subject: [PATCH 2/4] fix: Disable --- src/modules/02_users/views/01_user.vue | 24 ++++++++++++++++++- .../components/DialogApiKey.vue | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/modules/02_users/views/01_user.vue b/src/modules/02_users/views/01_user.vue index 0ceba23f..9d188adc 100644 --- a/src/modules/02_users/views/01_user.vue +++ b/src/modules/02_users/views/01_user.vue @@ -1,6 +1,7 @@