2024-07-05 17:34:30 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { ref, onMounted, computed } from "vue";
|
|
|
|
|
import { useQuasar } from "quasar";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* importType
|
|
|
|
|
*/
|
|
|
|
|
import type { QTableProps } from "quasar";
|
|
|
|
|
import type { DataBackup } from "@/modules/04_system/interface/response/Main";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* importStore
|
|
|
|
|
*/
|
|
|
|
|
import { useCounterMixin } from "@/stores/mixin";
|
2024-07-10 17:43:26 +07:00
|
|
|
import { useDataStore } from "@/modules/04_system/stores/main";
|
|
|
|
|
import { storeToRefs } from "pinia";
|
2024-07-05 17:34:30 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* use
|
|
|
|
|
*/
|
|
|
|
|
const $q = useQuasar();
|
|
|
|
|
const { showLoader, hideLoader, date2Thai, dialogRemove, dialogConfirm } =
|
|
|
|
|
useCounterMixin();
|
2024-07-10 17:51:13 +07:00
|
|
|
const { fetchListBackup, createBackUp, restore, deleteBackUp } = useDataStore();
|
2024-07-10 17:43:26 +07:00
|
|
|
const storeData = useDataStore();
|
2024-07-15 14:31:17 +07:00
|
|
|
const { dataBackUp, backupRunTotal, restoreRunTotal } = storeToRefs(storeData);
|
2024-07-05 17:34:30 +07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* props
|
|
|
|
|
*/
|
|
|
|
|
const tab = defineModel<string>("tab", { required: true });
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Table
|
|
|
|
|
*/
|
|
|
|
|
const filter = ref<string>("");
|
|
|
|
|
const visibleColumns = ref<string[]>(["name", "createAt", "status"]);
|
|
|
|
|
const baseColumns = ref<QTableProps["columns"]>([
|
|
|
|
|
{
|
|
|
|
|
name: "name",
|
|
|
|
|
align: "left",
|
|
|
|
|
label: "ชื่อข้อมูลสำรอง",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "name",
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "createAt",
|
2024-07-11 15:48:37 +07:00
|
|
|
align: "center",
|
2024-07-05 17:34:30 +07:00
|
|
|
label: "วันที่สร้าง",
|
|
|
|
|
sortable: true,
|
2024-07-11 15:30:36 +07:00
|
|
|
// field: (v) => date2Thai(v, false, true),
|
|
|
|
|
field: "timestamp",
|
|
|
|
|
format: (v) => date2Thai(v, false, true),
|
|
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
name: "status",
|
2024-07-11 15:48:37 +07:00
|
|
|
align: "center",
|
2024-07-11 15:30:36 +07:00
|
|
|
label: "สถานะ",
|
|
|
|
|
sortable: true,
|
|
|
|
|
field: "status",
|
2024-07-05 17:34:30 +07:00
|
|
|
headerStyle: "font-size: 14px",
|
|
|
|
|
style: "font-size: 14px",
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
const columns = computed(() => {
|
|
|
|
|
return baseColumns.value;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function สร้างรายการข้อมูสำรอง
|
|
|
|
|
*/
|
|
|
|
|
function onCreateBackup() {
|
|
|
|
|
dialogConfirm(
|
|
|
|
|
$q,
|
2024-07-10 17:43:26 +07:00
|
|
|
async () => {
|
2024-07-05 17:34:30 +07:00
|
|
|
showLoader();
|
2024-07-10 17:43:26 +07:00
|
|
|
await createBackUp();
|
2024-07-05 17:34:30 +07:00
|
|
|
},
|
|
|
|
|
"ยืนยันการสร้างข้อมูสำรอง",
|
|
|
|
|
"ต้องการยืนยันการสร้างข้อมูสำรองใช่หรือไม่?"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function ลบรายการข้อมูสำรอง
|
|
|
|
|
* @param id รายการสำรอง
|
|
|
|
|
*/
|
2024-07-10 17:51:13 +07:00
|
|
|
function onDelete(name: string) {
|
|
|
|
|
dialogRemove($q, async () => {
|
2024-07-05 17:34:30 +07:00
|
|
|
showLoader();
|
2024-07-10 17:51:13 +07:00
|
|
|
deleteBackUp(name);
|
2024-07-05 17:34:30 +07:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* function คืนค่าข้อมูสำรอง
|
|
|
|
|
* @param id ข้อมูสำรอง
|
|
|
|
|
*/
|
2024-07-10 17:43:26 +07:00
|
|
|
function onRestore(name: string) {
|
2024-07-05 17:34:30 +07:00
|
|
|
dialogConfirm(
|
|
|
|
|
$q,
|
2024-07-10 17:43:26 +07:00
|
|
|
async () => {
|
|
|
|
|
await restore(name);
|
2024-07-05 17:34:30 +07:00
|
|
|
},
|
|
|
|
|
"ยืนยันการคืนค่าข้อมูสำรอง",
|
|
|
|
|
"ต้องการยืนยันการคืนค่าข้อมูสำรองนี้ใช่หรือไม่?"
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-10 17:43:26 +07:00
|
|
|
onMounted(async () => {
|
2024-07-12 11:25:14 +07:00
|
|
|
setTimeout(() => {
|
|
|
|
|
fetchListBackup();
|
|
|
|
|
}, 1000);
|
2024-07-05 17:34:30 +07:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<q-card-section>
|
|
|
|
|
<div class="items-center col-12 row q-gutter-x-sm q-mb-sm">
|
|
|
|
|
<q-btn
|
|
|
|
|
v-if="tab === 'backup'"
|
|
|
|
|
color="primary"
|
|
|
|
|
icon="add"
|
|
|
|
|
label="สร้างข้อมูลสำรอง"
|
|
|
|
|
@click="onCreateBackup"
|
2024-07-11 15:30:36 +07:00
|
|
|
:disable="backupRunTotal > 0"
|
2024-07-05 17:34:30 +07:00
|
|
|
>
|
|
|
|
|
<q-tooltip>สร้างข้อมูลสำรอง </q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
|
|
|
|
|
<q-space />
|
|
|
|
|
|
|
|
|
|
<q-input
|
|
|
|
|
borderless
|
|
|
|
|
dense
|
|
|
|
|
debounce="300"
|
|
|
|
|
outlined
|
|
|
|
|
v-model="filter"
|
|
|
|
|
placeholder="ค้นหา"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:append>
|
|
|
|
|
<q-icon name="search" />
|
|
|
|
|
</template>
|
|
|
|
|
</q-input>
|
|
|
|
|
<q-select
|
|
|
|
|
v-model="visibleColumns"
|
|
|
|
|
multiple
|
|
|
|
|
outlined
|
|
|
|
|
dense
|
|
|
|
|
options-dense
|
|
|
|
|
:display-value="$q.lang.table.columns"
|
|
|
|
|
emit-value
|
|
|
|
|
map-options
|
|
|
|
|
:options="columns"
|
|
|
|
|
option-value="name"
|
|
|
|
|
options-cover
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<d-table
|
2024-07-10 17:43:26 +07:00
|
|
|
:rows="dataBackUp"
|
2024-07-05 17:34:30 +07:00
|
|
|
:columns="columns"
|
|
|
|
|
row-key="name"
|
|
|
|
|
:visible-columns="visibleColumns"
|
|
|
|
|
:filter="filter"
|
|
|
|
|
>
|
|
|
|
|
<template v-slot:header="props">
|
|
|
|
|
<q-tr :props="props">
|
2024-07-15 14:31:17 +07:00
|
|
|
<q-th v-for="(col, i) in props.cols" :key="col.name" :props="props">
|
|
|
|
|
<span class="text-weight-medium" :class="{ 'q-ml-md': i === 2 }">{{
|
|
|
|
|
col.label
|
|
|
|
|
}}</span>
|
2024-07-05 17:34:30 +07:00
|
|
|
</q-th>
|
|
|
|
|
<q-th auto-width></q-th>
|
|
|
|
|
</q-tr>
|
|
|
|
|
</template>
|
|
|
|
|
<template v-slot:body="props">
|
|
|
|
|
<q-tr :props="props">
|
2024-07-15 14:31:17 +07:00
|
|
|
<q-td v-for="(col, i) in props.cols" :key="col.name" :props="props">
|
|
|
|
|
<div :class="{ 'text-center': i === 2 }">
|
2024-07-11 15:30:36 +07:00
|
|
|
{{ i !== 2 ? col.value : col.value === "สำเร็จ" ? "สำเร็จ" : "" }}
|
|
|
|
|
|
|
|
|
|
<q-circular-progress
|
|
|
|
|
v-if="props.row.status === 'running' && col.name === 'status'"
|
|
|
|
|
indeterminate
|
|
|
|
|
rounded
|
|
|
|
|
size="20px"
|
|
|
|
|
color="lime"
|
|
|
|
|
class="q-ma-md"
|
|
|
|
|
/>
|
2024-07-05 17:34:30 +07:00
|
|
|
</div>
|
|
|
|
|
</q-td>
|
|
|
|
|
<q-td>
|
|
|
|
|
<q-btn
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
round
|
|
|
|
|
icon="delete"
|
|
|
|
|
color="red"
|
|
|
|
|
size="12px"
|
2024-07-10 17:51:13 +07:00
|
|
|
@click.petvent="onDelete(props.row.name)"
|
2024-07-05 17:34:30 +07:00
|
|
|
>
|
|
|
|
|
<q-tooltip>ลบข้อมูลสำรอง </q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
|
|
|
|
|
<q-btn
|
|
|
|
|
dense
|
|
|
|
|
flat
|
|
|
|
|
round
|
2024-07-15 14:31:17 +07:00
|
|
|
:disable="restoreRunTotal !== 0"
|
2024-07-05 17:34:30 +07:00
|
|
|
icon="restore"
|
|
|
|
|
color="primary"
|
|
|
|
|
size="12px"
|
2024-07-10 17:43:26 +07:00
|
|
|
@click.petvent="onRestore(props.row.name)"
|
2024-07-05 17:34:30 +07:00
|
|
|
>
|
|
|
|
|
<q-tooltip>คืนค่า </q-tooltip>
|
|
|
|
|
</q-btn>
|
|
|
|
|
</q-td>
|
|
|
|
|
</q-tr>
|
|
|
|
|
</template>
|
|
|
|
|
</d-table>
|
|
|
|
|
</q-card-section>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style scoped></style>
|