fetchData
This commit is contained in:
parent
c4764c1a4d
commit
1df4fcfcb9
1 changed files with 25 additions and 33 deletions
|
|
@ -272,28 +272,30 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
selector: boolean = false,
|
||||
newFetch: boolean = false
|
||||
) => {
|
||||
if (dataPrefix.value.length === 0) {
|
||||
await fetchPrefix(true, selector);
|
||||
let apiPrefix = "";
|
||||
if (selector) {
|
||||
apiPrefix = config.API.prefix;
|
||||
} else {
|
||||
apiPrefix = config.API.listPrefixHistory;
|
||||
}
|
||||
if (
|
||||
dataPrefix.value.length === 0 ||
|
||||
(dataPrefix.value.length !== 0 && newFetch)
|
||||
) {
|
||||
let data = await fetchData(true, apiPrefix);
|
||||
dataPrefix.value = data;
|
||||
draftPrefix.value = data;
|
||||
return {
|
||||
data: draftPrefix.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
} else {
|
||||
if (newFetch) {
|
||||
await fetchPrefix(true, selector);
|
||||
return {
|
||||
data: draftPrefix.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
data: draftPrefix.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
}
|
||||
return {
|
||||
data: draftPrefix.value,
|
||||
version: storeVersion.value,
|
||||
idversion: storeIdVersion.value,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -558,23 +560,17 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
}
|
||||
};
|
||||
|
||||
const fetchPrefix = async (loader: boolean, selector: boolean) => {
|
||||
let apiPrefix = "";
|
||||
const fetchData = async (loader: boolean, api: string): Promise<any> => {
|
||||
if (loader) {
|
||||
showLoader();
|
||||
}
|
||||
if (selector) {
|
||||
apiPrefix = config.API.prefix;
|
||||
} else {
|
||||
apiPrefix = config.API.listPrefixHistory;
|
||||
}
|
||||
let rows: any = [];
|
||||
await http
|
||||
.get(apiPrefix)
|
||||
.get(api)
|
||||
.then((res) => {
|
||||
const data = res.data.result;
|
||||
let rows: RequestItemsHistoryObject[] = [];
|
||||
if (selector) {
|
||||
data.map((e: RequestItemsHistoryObject) => {
|
||||
if (api) {
|
||||
data.map((e: any) => {
|
||||
rows.push({
|
||||
...e,
|
||||
});
|
||||
|
|
@ -583,17 +579,12 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
storeVersion.value = data.version; //ตัวแปรที่บอกว่าข้อมูลเผยแพร่ไปหรือยัง published=เผยแพร่แล้ว draft=ยังไม่เผยแพร่
|
||||
storeIdVersion.value = data.id; //เลข id ใน mongodb
|
||||
|
||||
data.items.map((e: RequestItemsHistoryObject) => {
|
||||
data.items.map((e: any) => {
|
||||
rows.push({
|
||||
...e,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
draftPrefix.value = rows;
|
||||
if (loader) {
|
||||
dataPrefix.value = rows;
|
||||
}
|
||||
})
|
||||
.catch((e) => {
|
||||
messageError($q, e);
|
||||
|
|
@ -603,6 +594,7 @@ export const useManageDataStore = defineStore("manage", () => {
|
|||
hideLoader();
|
||||
}
|
||||
});
|
||||
return rows;
|
||||
};
|
||||
|
||||
const fetchInsignia = async (loader: boolean, selector: boolean) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue