เพิ่ม function Schedule
This commit is contained in:
parent
84e8af2e5b
commit
a9ecba3a17
1 changed files with 127 additions and 0 deletions
|
|
@ -7,8 +7,10 @@ import { useCounterMixin } from "@/stores/mixin";
|
||||||
import type {
|
import type {
|
||||||
DataBackup,
|
DataBackup,
|
||||||
BackUpRunning,
|
BackUpRunning,
|
||||||
|
Schedule,
|
||||||
} from "@/modules/04_system/interface/response/Main";
|
} from "@/modules/04_system/interface/response/Main";
|
||||||
|
|
||||||
|
import type { ScheduleCreate } from "@/modules/04_system/interface/request/Main";
|
||||||
import { ref } from "vue";
|
import { ref } from "vue";
|
||||||
|
|
||||||
const mixin = useCounterMixin();
|
const mixin = useCounterMixin();
|
||||||
|
|
@ -23,6 +25,7 @@ const {
|
||||||
|
|
||||||
export const useDataStore = defineStore("systemStore", () => {
|
export const useDataStore = defineStore("systemStore", () => {
|
||||||
const dataBackUp = ref<DataBackup[]>([]);
|
const dataBackUp = ref<DataBackup[]>([]);
|
||||||
|
const dataSchedule = ref<Schedule[]>([]);
|
||||||
const prevBackupRunTotal = ref<number>(-1);
|
const prevBackupRunTotal = ref<number>(-1);
|
||||||
const backupRunTotal = ref<number>(0);
|
const backupRunTotal = ref<number>(0);
|
||||||
|
|
||||||
|
|
@ -178,11 +181,130 @@ export const useDataStore = defineStore("systemStore", () => {
|
||||||
return sizeNumber.toFixed(2) + " " + units[i];
|
return sizeNumber.toFixed(2) + " " + units[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function convertCronToForm(schedule: string, typeReturn: string): string {
|
||||||
|
let allValues = schedule.split(" ");
|
||||||
|
|
||||||
|
if (typeReturn === "typeOfSchedule") {
|
||||||
|
if (
|
||||||
|
allValues[3].includes("*") &&
|
||||||
|
allValues[4].includes("*") &&
|
||||||
|
allValues[5].includes("*")
|
||||||
|
) {
|
||||||
|
return `daily`;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
allValues[3].includes("*") &&
|
||||||
|
allValues[4].includes("*") &&
|
||||||
|
!allValues[5].includes("*")
|
||||||
|
) {
|
||||||
|
return `weekly`;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
!allValues[3].includes("*") &&
|
||||||
|
allValues[4].includes("*") &&
|
||||||
|
allValues[5].includes("*")
|
||||||
|
) {
|
||||||
|
return `monthly`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log(allValues);
|
||||||
|
|
||||||
|
if (typeReturn === "time") {
|
||||||
|
if (allValues[2].includes("/")) {
|
||||||
|
console.log(allValues[2]);
|
||||||
|
return "";
|
||||||
|
} else {
|
||||||
|
return `${allValues[2]}:${allValues[1]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeReturn === "timeStartEvery") {
|
||||||
|
return allValues[2].split("/")[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeReturn === "date") {
|
||||||
|
return `${allValues[5].split(",")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getSchedule() {
|
||||||
|
showLoader();
|
||||||
|
await http
|
||||||
|
.get<Schedule[]>(config.API.backup + "/schedule")
|
||||||
|
.then((res) => {
|
||||||
|
dataSchedule.value = res.data.map((item) => {
|
||||||
|
return {
|
||||||
|
id: item.id,
|
||||||
|
name: item.name,
|
||||||
|
schedule: item.schedule,
|
||||||
|
type: convertCronToForm(item.schedule, "typeOfSchedule") || "",
|
||||||
|
time: convertCronToForm(item.schedule, "time") || "",
|
||||||
|
date: convertCronToForm(item.schedule, "date") || "",
|
||||||
|
timeStartEvery:
|
||||||
|
convertCronToForm(item.schedule, "timeStartEvery") || "",
|
||||||
|
startAt: item.startAt,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log(dataSchedule.value);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createSchedule(data: ScheduleCreate) {
|
||||||
|
showLoader();
|
||||||
|
await http
|
||||||
|
.post(config.API.backup + "/schedule", {
|
||||||
|
name: data.name,
|
||||||
|
schedule: data.schedule,
|
||||||
|
startAt: data.startAt !== undefined ? data.startAt : undefined,
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
return res.data;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function editSchedule(data: ScheduleCreate) {
|
||||||
|
showLoader();
|
||||||
|
await http
|
||||||
|
.put(config.API.backup + "/schedule", {
|
||||||
|
data,
|
||||||
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
return res.data;
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteSchedule(id: string) {
|
||||||
|
showLoader();
|
||||||
|
await http
|
||||||
|
.delete(config.API.backup + "/schedule/" + id)
|
||||||
|
.then(async (res) => {
|
||||||
|
await fetchListBackup();
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
hideLoader();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
dataBackUp,
|
dataBackUp,
|
||||||
backupRunTotal,
|
backupRunTotal,
|
||||||
restoreRunTotal,
|
restoreRunTotal,
|
||||||
|
|
||||||
|
dataSchedule,
|
||||||
|
|
||||||
fetchListBackup,
|
fetchListBackup,
|
||||||
createBackUp,
|
createBackUp,
|
||||||
restore,
|
restore,
|
||||||
|
|
@ -192,5 +314,10 @@ export const useDataStore = defineStore("systemStore", () => {
|
||||||
restoreRunningList,
|
restoreRunningList,
|
||||||
|
|
||||||
getSize,
|
getSize,
|
||||||
|
|
||||||
|
getSchedule,
|
||||||
|
createSchedule,
|
||||||
|
editSchedule,
|
||||||
|
deleteSchedule,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue