โครงสร้างทะเบียนประวัติ

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-09-05 10:54:04 +07:00
parent 3666cd61a9
commit b5f7d75599
5 changed files with 92 additions and 54 deletions

View file

@ -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)