แก้ fetch เเล้วสถานะไม่เปลี่ยน

This commit is contained in:
Net 2024-07-23 11:46:08 +07:00
parent 5e471aafc1
commit 0a8f34ab86

View file

@ -62,7 +62,7 @@ export const useDataStore = defineStore("systemStore", () => {
await http await http
.post(config.API.backup + "/create") .post(config.API.backup + "/create")
.then(async (res) => { .then(async (res) => {
await backupRunningList(); await backupRunningList(fetchListBackup);
}) })
.finally(() => { .finally(() => {
hideLoader(); hideLoader();
@ -99,24 +99,24 @@ export const useDataStore = defineStore("systemStore", () => {
recordRestore.value[res.data] = tempValue; recordRestore.value[res.data] = tempValue;
} }
restoreRunningList(); restoreRunningList(fetchListBackup);
}); });
} }
async function backupRunningList() { async function backupRunningList(cb: () => void) {
await http await http
.get<BackUpRunning[]>(config.API.backup + "/backup-running-list") .get<BackUpRunning[]>(config.API.backup + "/backup-running-list")
.then(async (res) => { .then(async (res) => {
backupRunTotal.value = res.data.length; backupRunTotal.value = res.data.length;
if (backupRunTotal.value == 0) { if (backupRunTotal.value === 0 && prevBackupRunTotal.value !== 0) {
fetchListBackup(); cb();
prevBackupRunTotal.value = backupRunTotal.value; prevBackupRunTotal.value = backupRunTotal.value;
return; return;
} }
setTimeout(async () => { setTimeout(async () => {
backupRunningList(); backupRunningList(cb);
}, 3000); }, 3000);
if (prevBackupRunTotal.value !== backupRunTotal.value) { if (prevBackupRunTotal.value !== backupRunTotal.value) {
@ -142,22 +142,19 @@ export const useDataStore = defineStore("systemStore", () => {
}); });
} }
async function restoreRunningList() { async function restoreRunningList(cb: () => void) {
await http await http
.get<BackUpRunning[]>(config.API.backup + "/restore-running-list") .get<BackUpRunning[]>(config.API.backup + "/restore-running-list")
.then(async (res) => { .then(async (res) => {
console.log(res.data);
restoreRunTotal.value = res.data.length; restoreRunTotal.value = res.data.length;
if (restoreRunTotal.value === 0 && prevRestoreRunTotal.value !== 0) {
if (restoreRunTotal.value == 0) { cb();
fetchListBackup();
prevRestoreRunTotal.value = restoreRunTotal.value; prevRestoreRunTotal.value = restoreRunTotal.value;
return; return;
} }
setTimeout(async () => { setTimeout(async () => {
restoreRunningList(); restoreRunningList(cb);
}, 3000); }, 3000);
if (prevRestoreRunTotal.value !== restoreRunTotal.value) { if (prevRestoreRunTotal.value !== restoreRunTotal.value) {