From 2e4f70ce3305d6cab40dc51ce713bd8f91452e0a Mon Sep 17 00:00:00 2001 From: "DESKTOP-1R2VSQH\\Lenovo ThinkPad E490" Date: Fri, 25 Jul 2025 13:27:20 +0700 Subject: [PATCH] =?UTF-8?q?fix=20fetchDataTree=20=3D=3D>=20=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=AA=E0=B8=A3=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/StructureOrgMain.vue | 3 +- src/modules/02_organization/store/chart.ts | 30 ----------------- .../02_organization/store/organizational.ts | 33 ++++++++++++++++++- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/modules/02_organization/components/StructureOrgMain.vue b/src/modules/02_organization/components/StructureOrgMain.vue index 4a6ae377f..ea8cdecf0 100644 --- a/src/modules/02_organization/components/StructureOrgMain.vue +++ b/src/modules/02_organization/components/StructureOrgMain.vue @@ -154,8 +154,7 @@ async function fetchAgencyData(id: string) { agencyId.value = ""; try { - const data = await storeOrg.fetchDataTree(id); - console.log(data); + const data = await store.fetchDataTree(id); agencyData.value = data.data.map((item: any) => ({ id: item.orgTreeId, diff --git a/src/modules/02_organization/store/chart.ts b/src/modules/02_organization/store/chart.ts index 23dff2503..678225335 100644 --- a/src/modules/02_organization/store/chart.ts +++ b/src/modules/02_organization/store/chart.ts @@ -1,40 +1,10 @@ import { defineStore } from "pinia"; import { ref } from "vue"; -import http from "@/plugins/http"; -import config from "@/app.config"; - export const useStructStore = defineStore("StructStore", () => { const dataSource = ref(); - const cachedData = ref>({}); - - /** - * ฟังก์ชันดึงข้อมูลโครงสร้าง - * @param keyId id โครงสร้าง - */ - async function fetchDataTree(keyId: string) { - // ตรวจสอบว่ามีข้อมูลใน cache แล้วหรือไม่ - if (cachedData.value[keyId]) { - return cachedData.value[keyId]; - } - - // ถ้าไม่มีข้อมูลใน cache หรือ forceRefresh เป็น true ให้ดึงข้อมูลจาก API - try { - const res = await http.get(config.API.orgByid(keyId)); - const result = res.data.result; - - // เก็บข้อมูลใน cache - cachedData.value[keyId] = result; - - return result; - } catch (error) { - console.error("Error fetching data tree:", error); - return []; - } - } return { dataSource, - fetchDataTree, }; }); diff --git a/src/modules/02_organization/store/organizational.ts b/src/modules/02_organization/store/organizational.ts index faecc64a9..07022d5ac 100644 --- a/src/modules/02_organization/store/organizational.ts +++ b/src/modules/02_organization/store/organizational.ts @@ -1,6 +1,9 @@ import { defineStore } from "pinia"; import { reactive, ref } from "vue"; +import http from "@/plugins/http"; +import config from "@/app.config"; + /** importType*/ import type { DataActive, @@ -96,7 +99,7 @@ export const useOrganizational = defineStore("organizationalStore", () => { posMasterNo: e.orgShortname + (e.posMasterNoPrefix ? e.posMasterNoPrefix : "") + - (e.posMasterNo ? ` ${e.posMasterNo }`: "") + + (e.posMasterNo ? ` ${e.posMasterNo}` : "") + (e.posMasterNoSuffix ? e.posMasterNoSuffix : ""), positionName: e.isSit ? e.profilePosition : e.positionName, posTypeName: e.isSit ? e.profilePostype : e.posTypeName, @@ -166,6 +169,33 @@ export const useOrganizational = defineStore("organizationalStore", () => { } } + const cachedData = ref>({}); + + /** + * ฟังก์ชันดึงข้อมูลโครงสร้าง + * @param keyId id โครงสร้าง + */ + async function fetchDataTree(keyId: string) { + // ตรวจสอบว่ามีข้อมูลใน cache แล้วหรือไม่ + if (cachedData.value[keyId]) { + return cachedData.value[keyId]; + } + + // ถ้าไม่มีข้อมูลใน cache หรือ forceRefresh เป็น true ให้ดึงข้อมูลจาก API + try { + const res = await http.get(config.API.orgByid(keyId)); + const result = res.data.result; + + // เก็บข้อมูลใน cache + cachedData.value[keyId] = result; + + return result; + } catch (error) { + console.error("Error fetching data tree:", error); + return []; + } + } + return { typeOrganizational, statusView, @@ -190,5 +220,6 @@ export const useOrganizational = defineStore("organizationalStore", () => { isLosck, remark, convertStatus, + fetchDataTree, }; });