Merge branch 'develop' into devTee
This commit is contained in:
commit
2585599e75
3 changed files with 33 additions and 33 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Record<string, any>>({});
|
||||
|
||||
/**
|
||||
* ฟังก์ชันดึงข้อมูลโครงสร้าง
|
||||
* @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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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<Record<string, any>>({});
|
||||
|
||||
/**
|
||||
* ฟังก์ชันดึงข้อมูลโครงสร้าง
|
||||
* @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,
|
||||
};
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue