UI หน้าข้อมูลเครื่องราช

This commit is contained in:
oat 2024-01-24 18:02:46 +07:00
parent 61d8e40fc2
commit c0139fc2ce
3 changed files with 372 additions and 1414 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,47 +1,12 @@
<!-- tab ลำดบชนเครองราชฯ หนาจดการขอมลหล/อมลเครองราชอสรยาภรณ -->
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { useQuasar } from "quasar";
import { useRouter } from "vue-router";
import http from "@/plugins/http";
import config from "@/app.config";
import keycloak from "@/plugins/keycloak";
/** importType*/
import { ref } from "vue";
import type { QTableProps } from "quasar";
import type {
RequestItemsHistoryObject,
RequestItemsPublishHistoryObject,
} from "@/modules/01_metadataNew/interface/request/insignia/InsigniaType";
import type { ResponseHistoryObject } from "@/modules/01_metadataNew/interface/response/insignia/InsigniaType";
/** importComponents*/
import HistoryTable from "@/components/TableHistory.vue";
/** importStore*/
import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router";
const $q = useQuasar();
const router = useRouter();
const mixin = useCounterMixin();
const { success, dateText, messageError, showLoader, hideLoader } = mixin;
const rows = ref<RequestItemsHistoryObject[]>([]); //list data table
const rowsHistory = ref<RequestItemsHistoryObject[]>([]); //select data history
const rawHistory = ref<RequestItemsHistoryObject[]>([]); //raw data history
const tittleHistory = ref<string>("ประวัติแก้ไขลำดับชั้นเครื่องราชฯ"); //
const myForm = ref<any>(null); //ref
const filter = ref<string>(""); //search data table
const filterHistory = ref<string>(""); //search data table history
const modalHistory = ref<boolean>(false); //modal
const edit = ref<boolean>(false); //
const idVersion = ref<string>(""); //id data mongodb
const version = ref<string>("published"); // published= draft=
const updateData = ref<boolean>(false); //
const checkValidate = ref<boolean>(false);
/** ข้อมูล Table*/
const { date2Thai, dialogRemove } = mixin;
const columns = ref<QTableProps["columns"]>([
{
name: "name",
@ -99,539 +64,111 @@ const columns = ref<QTableProps["columns"]>([
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
]);
const visibleColumns = ref<String[]>([
const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false);
const isActive = ref<boolean>(false);
const name = ref<string>("");
const dialogStatus = ref<string>("");
const visibleColumns = ref<string[]>([
"name",
"createdAt",
"lastUpdatedAt",
"lastUpdateFullName",
"isActive",
]);
const columnsHistory = ref<QTableProps["columns"]>([
const row = ref([
{
name: "name",
align: "left",
label: "ลำดับชั้นเครื่องราชฯ",
sortable: true,
field: "name",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
id: "",
name: "test",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: true,
},
{
name: "lastUpdatedAt",
align: "center",
label: "วันที่แก้ไข",
sortable: true,
field: "lastUpdatedAt",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "lastUpdateFullName",
align: "left",
label: "ผู้ดำเนินการ",
sortable: true,
field: "lastUpdateFullName",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
},
{
name: "isActive",
align: "left",
label: "สถานะ",
sortable: true,
field: "isActive",
headerStyle: "font-size: 14px",
style: "font-size: 14px",
sort: (a: string, b: string) =>
a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }),
id: "",
name: "test2",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: false,
},
]);
const visibleColumnsHistory = ref<String[]>([
"name",
"lastUpdatedAt",
"lastUpdateFullName",
"isActive",
]);
/**
* เมอเขาหนานจะเรยกฟงชนนอน(get list data)
*/
onMounted(async () => {
await fetchData();
await fetchHistory();
});
/**
* งก get data าส
*/
const fetchData = async () => {
// await props.fetchDataComponent();
// const result = await getInsigniaType(false, load);
// version.value = result.version; // published= draft=
// idVersion.value = result.idversion; // id mongodb
// rows.value = result.data;
// updateData.value = false;
// rows.value.splice(0);
// showLoader();
await http
.get(config.API.listInsigniaTypeHistory)
.then((res) => {
let data = res.data.result;
version.value = data.version; // published= draft=
idVersion.value = data.id; // id mongodb
rows.value = [];
data.items.map((e: RequestItemsHistoryObject) => {
rows.value.push({
id: e.id,
name: e.name,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
lastUpdateFullName: e.lastUpdateFullName,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateUserId: e.lastUpdateUserId,
});
});
})
.catch((e) => {
messageError($q, e);
})
.finally(() => {
updateData.value = false;
hideLoader();
});
};
/**
* งชนดอมลประวแกไขขอมลทงหมด
*/
const fetchHistory = async () => {
showLoader();
await http
.get(config.API.listInsigniaTypePublishedHistory)
.then((res) => {
const data = res.data.result;
rawHistory.value = [];
if (data.length > 0) {
data.map((e: RequestItemsPublishHistoryObject) => {
e.items.map((i: RequestItemsHistoryObject) => {
rawHistory.value.push({
createdAt: i.createdAt,
createdFullName: i.createdFullName,
createdUserId: i.createdUserId,
id: i.id,
isActive: i.isActive,
lastUpdateFullName: i.lastUpdateFullName,
lastUpdateUserId: i.lastUpdateUserId,
lastUpdatedAt: i.lastUpdatedAt,
name: i.name,
});
});
});
}
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
});
};
/**
* งก clear data แบบราง
* เมอเรยก api เสรจแลวจะ get data มาใหม
*/
const clearPublishedData = async () => {
showLoader();
await http
.delete(config.API.listInsigniaTypeHistory)
.then((res) => {
success($q, "ลบข้อมูลร่างสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchHistory();
await fetchData();
});
};
/**
* งกนเผยแพรแบบราง
* เมอเรยก api เสรจแลวจะ get data มาใหม
*/
const publishedData = async () => {
showLoader();
await http
.get(config.API.listInsigniaTypePublished)
.then((res) => {
success($q, "เผยแพร่ข้อมูลสำเร็จ");
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
await fetchData();
});
};
/**
* งกนเพมขอม
*/
const clickAdd = async () => {
const filterRowNull = rows.value.filter(
(f: RequestItemsHistoryObject) =>
f.id === "00000000-0000-0000-0000-000000000000" && f.name == "" // array
);
if (filterRowNull.length == 0) {
//
rows.value.push({
createdAt: new Date(),
createdFullName: "",
createdUserId: "",
id: "00000000-0000-0000-0000-000000000000",
isActive: true,
lastUpdateFullName:
keycloak.tokenParsed == null ? "" : keycloak.tokenParsed.name,
lastUpdateUserId: "",
lastUpdatedAt: new Date(),
name: "",
});
updateData.value = true;
}
};
/**
* งกนบนทกแบบราง
* เมอเรยก api เสรจแลวจะ get data มาใหม
* publish เมอบนทกแบบรางแลวจะเผยแพรเลยไหม true=นทกและเผยแพร false=นทกอยางเดยว
*/
const save = async (publish: boolean) => {
await validateData();
if (checkValidate.value == false) return;
rows.value.map((e: ResponseHistoryObject) => ({
// data backend
id: e.id,
createdAt: e.createdAt,
lastUpdatedAt: e.lastUpdatedAt,
name: e.name,
isActive: e.isActive,
createdFullName: e.createdFullName,
createdUserId: e.createdUserId,
lastUpdateFullName: e.lastUpdateFullName,
lastUpdateUserId: e.lastUpdateUserId,
}));
showLoader();
await http
.post(config.API.listInsigniaTypeHistoryId(idVersion.value), {
id: idVersion.value,
version: "draft",
items: rows.value,
})
.then(async (res) => {
if (publish === false) {
success($q, "บันทึกข้อมูลร่างสำเร็จ");
await fetchData(); // get data
} else {
await publishedData(); //
}
edit.value = false;
})
.catch((e) => {
messageError($q, e);
})
.finally(async () => {
hideLoader();
await fetchData();
});
};
/**
* เชคชอซำกบขอมลทอยแล
* @param val input
*/
const checkDupDataName = (val: string) => {
const filterNameNull = rows.value.filter(
(f: RequestItemsHistoryObject) => f.name == val
); //
if (filterNameNull.length > 1) {
return false;
}
return true;
};
/**
* งกนปมแกไข ให get data มาใหม
*/
const clickEdit = async () => {
await fetchData();
};
/**
* งกนปมบนทกแบบราง
*/
const clickSave = async () => {
await save(false);
await fetchData();
};
/**
* งกนปมลบแบบราง
*/
const clickDelete = async () => {
await clearPublishedData();
await fetchData();
};
/**
* งกนปมยกเลกการแกไขขอม
*/
const clickCancel = async () => {
edit.value = false;
await fetchData();
};
/**
* งกนปมเผยแพรอม
* เชคขอมลกอนวาใน array กรอกขอมลครบไหมถาครบกใหเผยแพรได
* าคาใน array ไมอมลใน row จะใหนทกได
*/
const clickPublish = async () => {
if (myForm.value !== null) {
myForm.value.validate().then(async (result: boolean) => {
if (result) {
await save(true);
}
});
} else {
await save(true);
}
};
/**
* งกนปมลบ row data
* @param val data ใน row จะลบ
*/
const clickDeleteRow = (val: RequestItemsHistoryObject) => {
rows.value = rows.value.filter((x: RequestItemsHistoryObject) => x !== val);
updateData.value = true;
};
/**
* งกนเช input ามการแกไขหรอย
*/
const clickEditRow = () => {
myForm.value.validate(false);
updateData.value = true;
};
/**
* งชนดอมลประวแกไขขอมลทเลอก
* @param row อม row ประวการแกไข
*/
const clickHistory = async (row: RequestItemsHistoryObject) => {
modalHistory.value = true;
rowsHistory.value = rawHistory.value.filter(
(f: RequestItemsHistoryObject) => f.id == row.id
);
};
/**
* งกนแปลง date เปนภาษาไทย
* @param value นท type datetime จะแปลงเปนไทย
*/
const textDate = (value: Date) => {
return dateText(value);
};
/**
* validate component
*/
const validateData = async () => {
checkValidate.value = true;
await myForm.value.validate().then((result: boolean) => {
if (result == false) {
checkValidate.value = false;
}
});
};
function onclickDetail(data: any) {
function onclickDetail(data: (typeof row)["value"][number]) {
const id = data.id;
router.push(`/master-data/insignia/detail/${id}`);
router.push(`/master-data/insignia/detail/test`);
}
</script>
<template>
<div>
<q-form ref="myForm">
<data-table
:rows="rows"
:columns="columns"
:filter="filter"
:visible-columns="visibleColumns"
v-model:inputfilter="filter"
v-model:inputvisible="visibleColumns"
v-model:editvisible="edit"
:add="clickAdd"
:edit="clickEdit"
:save="clickSave"
:deleted="clickDelete"
:cancel="clickCancel"
:publish="clickPublish"
:validate="validateData"
:publicData="version === 'published'"
:updateData="updateData"
:history="true"
>
<template #columns="props">
<q-tr
:props="props"
v-if="edit == false"
@click.stop="onclickDetail(props.row)"
>
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'isActive'" class="">
<q-icon
v-if="col.value == false"
name="mdi-close"
color="red"
class="text-h5"
/>
<q-icon
v-else
name="mdi-check"
color="positive"
class="text-h5"
/>
</div>
<div v-else-if="col.name == 'createdAt'" class="">
{{ textDate(col.value) }}
</div>
<div v-else-if="col.name == 'lastUpdatedAt'" class="">
{{ textDate(col.value) }}
</div>
<div v-else class="">
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="info"
flat
dense
round
size="14px"
icon="mdi-history"
@click.stop="clickHistory(props.row)"
/>
</q-td>
</q-tr>
<q-tr :props="props" v-if="edit == true">
<q-td key="name" :props="props" v-if="props.row.name !== undefined">
<q-input
class=""
outlined
@update:model-value="clickEditRow"
v-model="props.row.name"
dense
lazy-rules
autofocus
hide-bottom-space
:rules="[
(val) => (val && val.length > 0) || 'กรุณากรอกข้อมูลให้ครบ',
(val) =>
checkDupDataName(val) || 'ชื่อซ้ำกันกับข้อมูลที่มีอยู่แล้ว',
]"
></q-input>
</q-td>
<q-td
key="createdAt"
:props="props"
v-if="props.row.createdAt !== undefined"
>
<div class="">
{{ textDate(props.row.createdAt) }}
</div>
</q-td>
<q-td key="lastUpdatedAt" :props="props">
<div class="">
{{ textDate(props.row.lastUpdatedAt) }}
</div>
</q-td>
<q-td
key="lastUpdateFullName"
:props="props"
v-if="props.row.lastUpdateFullName !== undefined"
class=""
>
{{ props.row.lastUpdateFullName }}
</q-td>
<q-td
key="isActive"
:props="props"
v-if="props.row.isActive !== undefined"
>
<q-toggle
v-model="props.row.isActive"
dense
size="34px"
color="positive"
@update:model-value="clickEditRow"
/>
</q-td>
<q-toolbar style="padding: 0">
<q-btn
flat
round
color="primary"
icon="add"
@click.stop="
() => {
dialogStatus = 'create';
dialog = true;
}
"
>
<q-tooltip> เพมขอม </q-tooltip>
</q-btn>
<q-space />
<div class="row q-gutter-sm">
<q-input outlined dense v-model="filterKeyword" label="ค้นหา"></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
style="min-width: 150px"
/>
</div>
</q-toolbar>
<q-td auto-width>
<q-btn
v-if="props.row.id === '00000000-0000-0000-0000-000000000000'"
color="red"
flat
dense
round
size="14px"
icon="mdi-trash-can-outline"
@click.stop="clickDeleteRow(props.row)"
/>
<q-btn
v-if="props.row.id !== '00000000-0000-0000-0000-000000000000'"
color="info"
flat
dense
round
size="14px"
icon="mdi-history"
@click.stop="clickHistory(props.row)"
/>
</q-td>
</q-tr>
</template>
</data-table>
</q-form>
</div>
<HistoryTable
:rows="rowsHistory"
:columns="columnsHistory"
:filter="filterHistory"
:visible-columns="visibleColumnsHistory"
v-model:modal="modalHistory"
v-model:inputfilter="filterHistory"
v-model:inputvisible="visibleColumnsHistory"
v-model:tittle="tittleHistory"
<d-table
ref="table"
:columns="columns"
:rows="row"
:filter="filterKeyword"
row-key="name"
flat
bordered
:paging="true"
dense
class="custom-header-table"
:visible-columns="visibleColumns"
>
<template #columns="props">
<template v-slot:header="props">
<q-tr :props="props">
<q-td v-for="col in props.cols" :key="col.name" :props="props">
<div v-if="col.name == 'isActive'" class="">
<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-tr>
</template>
<template v-slot:body="props">
<q-tr
:props="props"
class="cursor-pointer"
@click.stop="onclickDetail(props.row)"
>
<q-td v-for="col in props.cols" :key="col.id">
<div v-if="col.name == 'isActive'">
<q-icon
v-if="col.value == false"
name="mdi-close"
@ -640,22 +177,89 @@ function onclickDetail(data: any) {
/>
<q-icon v-else name="mdi-check" color="positive" class="text-h5" />
</div>
<div v-else-if="col.name == 'lastUpdatedAt'" class="">
{{ textDate(col.value) }}
</div>
<div v-else class="">
<div v-else>
{{ col.value }}
</div>
</q-td>
<q-td auto-width>
<q-btn
color="grey"
flat
dense
round
size="14px"
icon="more_vert"
@click.stop
>
<q-menu>
<q-list dense>
<q-item
v-close-popup
clickable
@click.stop="
() => {
dialogStatus = 'edit';
dialog = true;
}
"
>
<q-item-section>
<div class="row items-center white">
<q-icon name="o_edit" color="positive" />
<span class="q-ml-sm">แกไข</span>
</div>
</q-item-section>
</q-item>
<q-item clickable>
<q-item-section
@click="dialogRemove($q, async () => {})"
v-close-popup
>
<div class="row items-center white">
<q-icon name="mdi-trash-can-outline" color="negative" />
<span class="q-ml-sm">ลบ</span>
</div>
</q-item-section>
</q-item>
</q-list>
</q-menu>
</q-btn>
</q-td>
</q-tr>
</template>
</HistoryTable>
</d-table>
<q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="width: 400px">
<q-card-section class="flex justify-between">
<div v-if="dialogStatus == 'edit'" class="text-h6">แก้ไข</div>
<div v-else class="text-h6">เพ</div>
<q-btn flat v-close-popup round dense icon="close" color="red" />
</q-card-section>
<q-card-section class="q-pt-none">
<q-input outlined v-model="name" label="ลำดับชั้นเครื่องราชฯ" dense />
<div class="row justify-between q-mt-md">
<span class="text-bold"> สถานะการใชงาน </span>
<q-toggle v-model="isActive" dense />
</div>
</q-card-section>
<q-card-actions align="right">
<q-btn
flat
label="ตกลง"
color="primary"
v-close-popup
@click="
() => {
(name = ''), (isActive = false);
}
"
/>
</q-card-actions>
</q-card>
</q-dialog>
</template>
<style>
/* สีของnoti */
.my-notif-class {
background: rgba(33, 186, 69, 0.5) !important;
color: #008f17 !important;
}
</style>
<style></style>

View file

@ -1,12 +1,12 @@
<script setup lang="ts">
import InsigniaType from "@/modules/01_metadataNew/components/insignia/InsigniaType.vue";
import InsigniaType from "@/modules/01_metadataNew/components/insignia/NewInsigniaType.vue";
</script>
<template>
<div class="toptitle text-dark col-12 row items-center">
อมลเครองราชอสรยาภรณ
</div>
<q-card flat bordered> <InsigniaType /> </q-card>
<q-card flat bordered class="q-pa-md"> <InsigniaType /> </q-card>
</template>
<style scoped></style>