84 lines
1.6 KiB
TypeScript
84 lines
1.6 KiB
TypeScript
import { defineStore } from "pinia";
|
|
import http from "@/plugins/http";
|
|
import config from "@/app.config";
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
|
|
|
import type { DataBackup } from "@/modules/04_system/interface/response/Main";
|
|
|
|
import { ref } from "vue";
|
|
|
|
const mixin = useCounterMixin();
|
|
const {
|
|
dialogRemove,
|
|
messageError,
|
|
showLoader,
|
|
hideLoader,
|
|
success,
|
|
dialogConfirm,
|
|
} = mixin;
|
|
|
|
export const useDataStore = defineStore("storeData", () => {
|
|
const dataBackUp = ref<DataBackup[]>([]);
|
|
|
|
async function fetchListBackup() {
|
|
showLoader();
|
|
await http
|
|
.get(config.API.backup)
|
|
.then((res) => {
|
|
dataBackUp.value = res.data;
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
async function createBackUp() {
|
|
showLoader();
|
|
await http
|
|
.post(config.API.backup + "/create")
|
|
.then(async (res) => {
|
|
fetchListBackup();
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
async function deleteBackUp(filename: string) {
|
|
showLoader();
|
|
await http
|
|
.delete(config.API.backup + "/delete", {
|
|
data: { filename: filename },
|
|
})
|
|
.then(async (res) => {
|
|
fetchListBackup();
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
async function restore(filename: string) {
|
|
showLoader();
|
|
await http
|
|
.post(config.API.restore, {
|
|
filename: filename,
|
|
})
|
|
.then((res) => {
|
|
fetchListBackup();
|
|
})
|
|
.finally(() => {
|
|
hideLoader();
|
|
});
|
|
}
|
|
|
|
return {
|
|
dataBackUp,
|
|
|
|
fetchListBackup,
|
|
createBackUp,
|
|
restore,
|
|
deleteBackUp,
|
|
};
|
|
});
|