From e8c830454a20605957ffd1b80c61282b74b0c146 Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 28 Feb 2025 14:50:11 +0700 Subject: [PATCH] fix fetch StructrueTree --- .../04_registryPerson/views/listView.vue | 22 ++++++-- .../21_report/views/02_reportRegistry.vue | 51 ++++++++++++++----- src/stores/structureTree.ts | 3 ++ 3 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/modules/04_registryPerson/views/listView.vue b/src/modules/04_registryPerson/views/listView.vue index b53f6ff4b..9909e3287 100644 --- a/src/modules/04_registryPerson/views/listView.vue +++ b/src/modules/04_registryPerson/views/listView.vue @@ -13,7 +13,7 @@ import http from "@/plugins/http"; import config from "@/app.config"; import { useRegistryNewDataStore } from "@/modules/04_registryPerson/store"; import { useCounterMixin } from "@/stores/mixin"; -import { useRoute } from "vue-router"; +import { useRoute, useRouter } from "vue-router"; import avatar from "@/assets/avatar_user.jpg"; import { useStructureTree } from "@/stores/structureTree"; @@ -40,6 +40,7 @@ const store = useRegistryNewDataStore(); const { fetchStructureTree } = useStructureTree(); const { showLoader, hideLoader, messageError } = useCounterMixin(); const route = useRoute(); +const router = useRouter(); const empType = ref("officer"); // officer / employee / perm const dataPersonMain = ref([]); //ข้อมูลรายการที่ค้นหาข้อมูลทะเบียนประวัติ @@ -391,6 +392,10 @@ function getSearch() { fetchDataPerson(); } +function goToAdvancedSearch() { + router.push("/report/registry"); +} + /** hook เมื่อมีการเรียกใช้ Components*/ onMounted(async () => { await Promise.all([selectType(), fetchTree()]); @@ -596,12 +601,23 @@ onMounted(async () => { (false); const total = ref(0); @@ -325,6 +329,7 @@ const rangeTerm = ref({ min: 0, max: 20, }); +const isLoadStructureTree = ref(true); function onOpenOrg() { modalOrg.value = true; @@ -660,21 +665,27 @@ const expandedModal = ref(false); async function fetchTree() { try { - const res = await http.get(config.API.orgPermissionsSys); - const response = res.data.result.roles; + if (storeMenu.permissions) { + isLoadStructureTree.value = true; + const response = storeMenu.permissions.roles ?? []; - const sysName = response.find( - (e: DataRoles) => - e.authSysId === "SYS_REGISTRY_OFFICER" || - e.authSysId === "REPORT_REGISTRY" - )?.authSysId; + const sysName = response + ?.find( + (e: DataRoles) => + e.authSysId === "SYS_REGISTRY_OFFICER" || + e.authSysId === "REPORT_REGISTRY" + ) + ?.authSysId.toString(); - const data = await fetchStructureTree(sysName ?? "REPORT_REGISTRY", true); - if (data) { - node.value = data; + const data = await fetchStructureTree(sysName ?? "REPORT_REGISTRY"); + if (data) { + node.value = data; + } } } catch (err) { messageError($q, err); + } finally { + isLoadStructureTree.value = false; } } @@ -712,7 +723,7 @@ onMounted(async () => { getOptions(), getExecutive(), getDataPerson(), - getEducationLevel(), + // getEducationLevel(), fetchTree(), ]) @@ -726,6 +737,15 @@ onMounted(async () => { }, 500); }); }); + +watch( + () => storeMenu.permissions, + () => { + if (storeMenu.permissions) { + fetchTree(); + } + } +); - + + + + { * @returns ข้อมูลโครงสร้าง */ async function fetchStructureTree(sysKey: string, isLoad: boolean = false) { + console.log(sysKey); + console.log(dataStore.value); + if (dataStore.value[sysKey]) { return dataStore.value[sysKey] || []; } else {