โครงสร้างทะเบียนประวัติ
This commit is contained in:
parent
3666cd61a9
commit
b5f7d75599
5 changed files with 92 additions and 54 deletions
|
|
@ -6,23 +6,36 @@ import http from "@/plugins/http";
|
|||
import config from "@/app.config";
|
||||
import { useCounterMixin } from "@/stores/mixin";
|
||||
|
||||
import type { DataStructureTree } from "@/interface/main";
|
||||
|
||||
const $q = useQuasar();
|
||||
const { showLoader, hideLoader, messageError } = useCounterMixin();
|
||||
|
||||
export const useStructureTree = defineStore("structureTree", () => {
|
||||
const activeId = ref<string>("");
|
||||
const dataStore = ref<{ [key: string]: any[] }>({});
|
||||
const dataStore = ref<{ [key: string]: DataStructureTree[] }>({});
|
||||
|
||||
async function fetchStructureTree(sysKey: string) {
|
||||
/**
|
||||
* fetch ข้อมูลโครงสร้างตามคีย์ของระบบ
|
||||
* @param sysKey คีย์ของระบบ
|
||||
* @param isLoad สถานะที่ใช้ในการแสดงตัวโหลด true = แสดง, false = ไม่แสดง
|
||||
* @returns ข้อมูลโครงสร้าง
|
||||
*/
|
||||
async function fetchStructureTree(sysKey: string, isLoad: boolean = false) {
|
||||
if (dataStore.value[sysKey]) {
|
||||
return dataStore.value[sysKey] || [];
|
||||
} else {
|
||||
activeId.value === "" && (await fetchActive());
|
||||
const data = await fetchData(sysKey);
|
||||
const data = await fetchData(sysKey, isLoad);
|
||||
return data || [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* fetch ข้อมูลโครงสร้างองค์กรปัจจุบัน
|
||||
*
|
||||
* เช็ต activeId.value เป็นค่า data.activeId ที่ได้จากข้อมูลที่ดึงมา
|
||||
*/
|
||||
async function fetchActive() {
|
||||
try {
|
||||
const res = await http.get(config.API.activeOrganization);
|
||||
|
|
@ -33,8 +46,17 @@ export const useStructureTree = defineStore("structureTree", () => {
|
|||
}
|
||||
}
|
||||
|
||||
async function fetchData(sysKey: string) {
|
||||
// showLoader();
|
||||
/**
|
||||
* fetch ข้อมูลโครงสร้างจาก API
|
||||
* @param sysKey คีย์ของระบบ
|
||||
* @param isLoad สถานะที่ใช้ในการแสดงตัวโหลด true = แสดง, false = ไม่แสดง
|
||||
* @returns ข้อมูลโครงสร้าง
|
||||
*
|
||||
* เมื่อ isLoad เป็น true จะทำการแสดงตัวโหลด showLoader
|
||||
* และเก็บค่าใน dataStore.value ตามคีย์ของระบบที่รับมา
|
||||
*/
|
||||
async function fetchData(sysKey: string, isLoad: boolean) {
|
||||
isLoad && showLoader();
|
||||
try {
|
||||
const res = await http.get(
|
||||
config.API.orgByIdSystem(activeId.value, sysKey)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue