ตั้งค่าระบบ => UI

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-07-05 17:34:30 +07:00
parent 587daf6a0e
commit c82577c05b
8 changed files with 340 additions and 0 deletions

View file

@ -0,0 +1,241 @@
<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";
/**
* use
*/
const $q = useQuasar();
const { showLoader, hideLoader, date2Thai, dialogRemove, dialogConfirm } =
useCounterMixin();
/**
* props
*/
const tab = defineModel<string>("tab", { required: true });
/**
* Table
*/
const rows = ref<DataBackup[]>([]);
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",
align: "left",
label: "วันที่สร้าง",
sortable: true,
field: (v) => date2Thai(v),
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
{
name: "status",
align: "left",
label: "สถานะ",
sortable: true,
field: "status",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
},
]);
const columns = computed(() => {
if (tab.value === "restore") {
if (baseColumns.value) {
return baseColumns.value.filter((column) => column.name !== "status");
}
}
return baseColumns.value;
});
/**
* function เรยกขอมลรายการสำรอง
*/
function fetchListBackup() {
showLoader();
const data: DataBackup[] = [
{
id: "1",
name: "สำรอง1",
createAt: new Date(),
status: "ดำเนินการ",
},
{
id: "2",
name: "สำรอง2",
createAt: new Date(),
status: "ดำเนินการ",
},
];
rows.value = data;
setTimeout(() => {
hideLoader();
}, 500);
}
/**
* function สรางรายการขอมสำรอง
*/
function onCreateBackup() {
dialogConfirm(
$q,
() => {
showLoader();
fetchListBackup();
},
"ยืนยันการสร้างข้อมูสำรอง",
"ต้องการยืนยันการสร้างข้อมูสำรองใช่หรือไม่?"
);
}
/**
* function ลบรายการขอมสำรอง
* @param id รายการสำรอง
*/
function onDelete(id: string) {
dialogRemove($q, () => {
showLoader();
fetchListBackup();
});
}
/**
* function นคาขอมสำรอง
* @param id อมสำรอง
*/
function onRestore(id: string) {
dialogConfirm(
$q,
() => {
showLoader();
fetchListBackup();
},
"ยืนยันการคืนค่าข้อมูสำรอง",
"ต้องการยืนยันการคืนค่าข้อมูสำรองนี้ใช่หรือไม่?"
);
}
onMounted(() => {
fetchListBackup();
});
</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"
>
<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
:rows="rows"
:columns="columns"
row-key="name"
:visible-columns="visibleColumns"
:filter="filter"
>
<template v-slot:header="props">
<q-tr :props="props">
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span class="text-weight-medium">{{ col.label }}</span>
</q-th>
<q-th auto-width></q-th>
</q-tr>
</template>
<template v-slot:body="props">
<q-tr :props="props">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div>
{{ col.value ? col.value : "-" }}
</div>
</q-td>
<q-td>
<q-btn
v-if="tab === 'backup'"
dense
flat
round
icon="delete"
color="red"
size="12px"
@click.petvent="onDelete(props.row.id)"
>
<q-tooltip>ลบขอมลสำรอง </q-tooltip>
</q-btn>
<q-btn
v-else
dense
flat
round
icon="restore"
color="primary"
size="12px"
@click.petvent="onRestore(props.row.id)"
>
<q-tooltip>นค </q-tooltip>
</q-btn>
</q-td>
</q-tr>
</template>
</d-table>
</q-card-section>
</template>
<style scoped></style>