แก้ UI เครื่องราช

This commit is contained in:
oat 2024-01-25 15:05:51 +07:00
parent dabc016e39
commit 42e7fd6b1d
5 changed files with 557 additions and 145 deletions

View file

@ -1,15 +1,120 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref, onMounted } from "vue";
import { useRouter } from "vue-router"; import { useRouter, useRoute } from "vue-router";
import InsigniaDetail from "@/modules/01_metadataNew/components/insignia/InsigniaList.vue"; import InsigniaList from "@/modules/01_metadataNew/components/insignia/InsigniaList.vue";
const router = useRouter(); const router = useRouter();
const route = useRoute();
const nameType = ref<string>(""); const nameType = ref<string>("");
import { useCounterMixin } from "@/stores/mixin";
import type {
DetailResponse,
DetailRow,
} from "@/modules/01_metadataNew/interface/response/insignia/Insignia";
const row = ref<DetailRow[]>();
const mixin = useCounterMixin();
const { date2Thai } = mixin;
const id = ref<string>(route.params.id.toString());
function fetchName(name: string) { function fetchName(name: string) {
nameType.value = name; nameType.value = name;
} }
const data = ref<DetailResponse[]>([
{
id: "1",
level: 1,
shortName: "จ.ม.",
insigniaType: "ชั้นต่ำกว่าสายสะพาย",
insigniaTypeId: "1",
note: "-",
name: "จัตุรถาภรณ์มงกุฎไทย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "System Administrator",
isActive: true,
},
{
id: "2",
level: 1,
shortName: "จ.ช.",
insigniaType: "ชั้นต่ำกว่าสายสะพาย",
insigniaTypeId: "1",
note: "-",
name: "จัตุรถาภรณ์ช้างเผือก",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "คณะกรรมการ ตรวจรับ",
isActive: false,
},
{
id: "1",
level: 1,
shortName: "บ.ม.",
insigniaType: "ชั้นสายสะพาย",
insigniaTypeId: "2",
note: "-",
name: "เบญจมาภรณ์มงกุฎไทย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "คณะกรรมการ ตรวจรับ",
isActive: true,
},
{
id: "2",
level: 1,
shortName: "ท.ม.",
insigniaType: "ชั้นสายสะพาย",
insigniaTypeId: "2",
note: "-",
name: "ทวีติยาภรณ์มงกุฎไทย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "คณะกรรมการ ตรวจรับ",
isActive: true,
},
{
id: "1",
level: 1,
shortName: "บ.ช.",
insigniaType: "เหรียญบำเหน็จในราชการ",
insigniaTypeId: "3",
note: "-",
name: "เบญจมาภรณ์ช้างเผือก",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "สาวิตรี ศรีสมัย",
isActive: true,
},
{
id: "2",
level: 1,
shortName: "ท.ม.",
insigniaType: "เหรียญบำเหน็จในราชการ",
insigniaTypeId: "3",
note: "-",
name: "ทวีติยาภรณ์มงกุฎไทย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "System Administrator",
isActive: true,
},
]);
function fetchData() {
const datafilter = data.value.find((e) => e.insigniaTypeId === id.value);
console.log(datafilter);
datafilter && fetchName(datafilter.insigniaType);
const list = data.value.map((e) => ({
...e,
createdAt: e.createdAt ? date2Thai(e.createdAt) : "",
lastUpdatedAt: e.lastUpdatedAt ? date2Thai(e.lastUpdatedAt) : "",
}));
row.value = list.filter((e) => e.insigniaTypeId === id.value);
}
onMounted(() => {
fetchData();
});
</script> </script>
<template> <template>
<div class="toptitle text-dark col-12 row items-center"> <div class="toptitle text-dark col-12 row items-center">
@ -27,7 +132,11 @@ function fetchName(name: string) {
</div> </div>
<q-card flat bordered> <q-card flat bordered>
<InsigniaDetail @update:fetchName="fetchName" /> <InsigniaList
:data="row"
@update:fetchName="fetchName"
:nameType="nameType"
/>
</q-card> </q-card>
</template> </template>

View file

@ -1,12 +1,15 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref, onMounted } from "vue";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import dialogHeader from "@/components/DialogHeader.vue";
import { useQuasar } from "quasar";
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { date2Thai, dialogRemove } = mixin; const { date2Thai, dialogRemove, dialogConfirm } = mixin;
const $q = useQuasar();
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "level", name: "level",
@ -123,8 +126,9 @@ const isActive = ref<boolean>(false);
const name = ref<string>(""); const name = ref<string>("");
const shortName = ref<string>(""); const shortName = ref<string>("");
const note = ref<string>(""); const note = ref<string>("");
const insigniaTypeId = ref<string>("บำเหน็จ"); const insigniaTypeId = ref<string>("");
const nameRef = ref<any>(null);
const shortNameRef = ref<any>(null);
const dialogStatus = ref<string>(""); const dialogStatus = ref<string>("");
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"level", "level",
@ -138,30 +142,36 @@ const visibleColumns = ref<string[]>([
"note", "note",
]); ]);
const row = ref([ const props = defineProps({
{ data: { type: Object },
level: 1, nameType: { type: String },
shortName: "เทส", });
insigniaType: "บำเหน็จ",
note: "-", function closeDialog() {
name: "testInside1", dialog.value = false;
createdAt: date2Thai(new Date()), }
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest", function validateForm() {
isActive: true, nameRef.value.validate();
}, shortNameRef.value.validate();
{ onSubmit();
level: 2, }
shortName: "เทส2",
insigniaType: "บำนาญ", async function onSubmit() {
note: "-", if (name.value.length > 0 && shortName.value.length > 0) {
name: "testInside2", dialogConfirm(
createdAt: date2Thai(new Date()), $q,
lastUpdatedAt: date2Thai(new Date()), async () => {
lastUpdateFullName: "TestTest", console.log("สำเร็จ");
isActive: false, closeDialog();
}, name.value = "";
]); shortName.value = "";
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
}
</script> </script>
<template> <template>
@ -204,7 +214,7 @@ const row = ref([
<d-table <d-table
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="row" :rows="props.data"
:filter="filterKeyword" :filter="filterKeyword"
row-key="name" row-key="name"
flat flat
@ -292,52 +302,164 @@ const row = ref([
</d-table> </d-table>
<q-dialog v-model="dialog" class="dialog" persistent> <q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="width: 400px"> <q-card style="min-width: 350px" class="bg-grey-11">
<q-card-section class="flex justify-between"> <form @submit.prevent="validateForm">
<div v-if="dialogStatus == 'edit'" class="text-h6">แก้ไข</div> <q-card-section class="flex justify-between" style="padding: 0">
<div v-else class="text-h6">เพ</div> <dialog-header
<q-btn flat v-close-popup round dense icon="close" color="red" /> :tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
</q-card-section> :close="closeDialog"
/>
</q-card-section>
<q-card-section class="q-pt-none q-gutter-md"> <q-separator color="grey-4" />
<q-input <q-card-section class="q-pa-none">
outlined <q-input
v-model="insigniaTypeId" outlined
label="ลำดับชั้นเครื่องราชฯ" :model-value="nameType"
dense label="ลำดับชั้นเครื่องราชฯ"
readonly dense
/> lazy-rules
<q-input outlined v-model="name" label="ชื่อเครื่องราชฯ" dense /> borderless
<q-input outlined v-model="shortName" label="ชื่อย่อ" dense /> class="col-12 bg-white q-ma-md"
<q-input hide-bottom-space
outlined readonly
v-model="note" />
type="textarea" <q-input
label="หมายเหตุ" ref="nameRef"
dense outlined
/> v-model="name"
<div class="row justify-between q-mt-md"> label="ชื่อเครื่องราช"
<span class="text-bold"> สถานะการใชงาน </span> dense
<q-toggle v-model="isActive" dense /> lazy-rules
</div> borderless
</q-card-section> class="col-12 bg-white q-ma-md"
:rules="[
(val) => val.length > 0 || 'กรุณากรอกลำดับชั้นเครื่องราชฯ',
]"
hide-bottom-space
/>
<q-input
ref="shortNameRef"
outlined
v-model="shortName"
label="ชื่อย่อ"
dense
lazy-rules
borderless
class="col-12 bg-white q-ma-md"
:rules="[
(val) => val.length > 0 || 'กรุณากรอกลำดับชั้นเครื่องราชฯ',
]"
hide-bottom-space
/>
<q-input
outlined
v-model="note"
label="หมายเหตุ"
dense
type="textarea"
borderless
class="col-12 bg-white q-ma-md"
hide-bottom-space
/>
<div
class="col q-ma-md q-pa-sm bg-white border_custom text-weight-medium"
>
<div class="row items-center q-my-sm justify-between">
<p class="q-ma-none">สถานะการใชงาน</p>
<label class="toggle-control">
<input type="checkbox" dense v-model="isActive" @change="" />
<span class="control"></span>
</label>
</div>
</div>
</q-card-section>
<q-card-actions align="right"> <q-card-actions align="right">
<q-btn <q-btn
flat id="onSubmit"
label="ตกลง" type="submit"
color="primary" dense
v-close-popup unelevated
@click=" label="บันทึก"
() => { color="public"
(name = ''), (isActive = false); class="q-px-md"
} >
" <q-tooltip>นทกขอม</q-tooltip>
/> </q-btn>
</q-card-actions> </q-card-actions>
</form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</div> </div>
</template> </template>
<style></style> <style scoped lang="scss">
.border_custom {
border-radius: 6px !important;
border: 1px solid #e1e1e1;
}
$toggle-background-color-on: #06884d;
$toggle-background-color-off: darkgray;
$toggle-control-color: white;
$toggle-width: 40px;
$toggle-height: 25px;
$toggle-gutter: 3px;
$toggle-radius: 50%;
$toggle-control-speed: 0.15s;
$toggle-control-ease: ease-in;
// These are our computed variables
// change at your own risk.
$toggle-radius: $toggle-height / 2;
$toggle-control-size: $toggle-height - ($toggle-gutter * 2);
.toggle-control {
display: block;
position: relative;
padding-left: $toggle-width;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
user-select: none;
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
input:checked ~ .control {
background-color: $toggle-background-color-on;
&:after {
left: $toggle-width - $toggle-control-size - $toggle-gutter;
}
}
.control {
position: absolute;
top: -7px;
left: -15px;
height: $toggle-height;
width: $toggle-width;
border-radius: $toggle-radius;
background-color: $toggle-background-color-off;
transition: background-color $toggle-control-speed $toggle-control-ease;
&:after {
content: "";
position: absolute;
left: $toggle-gutter;
top: $toggle-gutter;
width: $toggle-control-size;
height: $toggle-control-size;
border-radius: $toggle-radius;
background: $toggle-control-color;
transition: left $toggle-control-speed $toggle-control-ease;
}
}
}
</style>

View file

@ -1,12 +1,16 @@
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref, onMounted } from "vue";
import type { QTableProps } from "quasar"; import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin"; import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
import { useInsigniaDataStore } from "@/modules/01_metadataNew/stores/InsigniaStore";
import dialogHeader from "@/components/DialogHeader.vue";
import { useQuasar } from "quasar";
const store = useInsigniaDataStore();
const router = useRouter(); const router = useRouter();
const mixin = useCounterMixin(); const mixin = useCounterMixin();
const { date2Thai, dialogRemove } = mixin; const { dialogRemove, dialogConfirm } = mixin;
const columns = ref<QTableProps["columns"]>([ const columns = ref<QTableProps["columns"]>([
{ {
name: "name", name: "name",
@ -65,11 +69,13 @@ const columns = ref<QTableProps["columns"]>([
}, },
]); ]);
const $q = useQuasar();
const filterKeyword = ref<string>(""); const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false); const dialog = ref<boolean>(false);
const isActive = ref<boolean>(false); const isActive = ref<boolean>(false);
const name = ref<string>(""); const name = ref<string>("");
const nameRef = ref<any>(null);
const dialogStatus = ref<string>(""); const dialogStatus = ref<string>("");
const visibleColumns = ref<string[]>([ const visibleColumns = ref<string[]>([
"name", "name",
@ -79,28 +85,68 @@ const visibleColumns = ref<string[]>([
"isActive", "isActive",
]); ]);
const row = ref([ // const row = ref([]);
{
id: "",
name: "test",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: true,
},
{
id: "",
name: "test2",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: false,
},
]);
function onclickDetail(data: (typeof row)["value"][number]) { function fetchData() {
const id = data.id; const data = [
router.push(`/master-data/insignia/detail/test`); {
id: "1",
name: "ชั้นต่ำกว่าสายสะพาย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "สาวิตรี ศรีสมัย",
isActive: true,
},
{
id: "2",
name: "ชั้นสายสะพาย",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "System Administrator",
isActive: false,
},
{
id: "3",
name: "เหรียญบำเหน็จในราชการ",
createdAt: new Date(),
lastUpdatedAt: new Date(),
lastUpdateFullName: "คณะกรรมการ ตรวจรับ",
isActive: false,
},
];
store.fetchData(data);
}
onMounted(async () => {
fetchData();
});
function closeDialog() {
dialog.value = false;
}
function onclickDetail(id: string) {
router.push(`/master-data/insignia/detail/${id}`);
}
function validateForm() {
nameRef.value.validate();
onSubmit();
}
async function onSubmit() {
if (name.value.length > 0) {
dialogConfirm(
$q,
async () => {
console.log("สำเร็จ");
closeDialog();
name.value = "";
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
} }
</script> </script>
@ -143,7 +189,7 @@ function onclickDetail(data: (typeof row)["value"][number]) {
<d-table <d-table
ref="table" ref="table"
:columns="columns" :columns="columns"
:rows="row" :rows="store.row"
:filter="filterKeyword" :filter="filterKeyword"
row-key="name" row-key="name"
flat flat
@ -165,7 +211,7 @@ function onclickDetail(data: (typeof row)["value"][number]) {
<q-tr <q-tr
:props="props" :props="props"
class="cursor-pointer" class="cursor-pointer"
@click.stop="onclickDetail(props.row)" @click.stop="onclickDetail(props.row.id)"
> >
<q-td v-for="col in props.cols" :key="col.id"> <q-td v-for="col in props.cols" :key="col.id">
<div v-if="col.name == 'isActive'"> <div v-if="col.name == 'isActive'">
@ -230,36 +276,128 @@ function onclickDetail(data: (typeof row)["value"][number]) {
</d-table> </d-table>
<q-dialog v-model="dialog" class="dialog" persistent> <q-dialog v-model="dialog" class="dialog" persistent>
<q-card style="width: 400px"> <q-card style="min-width: 350px" class="bg-grey-11">
<q-card-section class="flex justify-between"> <form @submit.prevent="validateForm">
<div v-if="dialogStatus == 'edit'" class="text-h6">แก้ไข</div> <q-card-section class="flex justify-between" style="padding: 0">
<div v-else class="text-h6">เพ</div> <dialog-header
<q-btn flat v-close-popup round dense icon="close" color="red" /> :tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
</q-card-section> :close="closeDialog"
/>
</q-card-section>
<q-card-section class="q-pt-none"> <q-separator color="grey-4" />
<q-input outlined v-model="name" label="ลำดับชั้นเครื่องราชฯ" dense /> <q-card-section class="q-pa-none">
<div class="row justify-between q-mt-md"> <q-input
<span class="text-bold"> สถานะการใชงาน </span> ref="nameRef"
<q-toggle v-model="isActive" dense /> outlined
</div> v-model="name"
</q-card-section> label="ลำดับชั้นเครื่องราชฯ"
dense
lazy-rules
borderless
class="col-12 bg-white q-ma-md"
:rules="[
(val) => val.length > 0 || 'กรุณากรอกลำดับชั้นเครื่องราชฯ',
]"
hide-bottom-space
/>
<div
class="col q-ma-md q-pa-sm bg-white border_custom text-weight-medium"
>
<div class="row items-center q-my-sm justify-between">
<p class="q-ma-none">สถานะการใชงาน</p>
<label class="toggle-control">
<input type="checkbox" dense v-model="isActive" @change="" />
<span class="control"></span>
</label>
</div>
</div>
</q-card-section>
<q-card-actions align="right"> <q-card-actions align="right">
<q-btn <q-btn
flat id="onSubmit"
label="ตกลง" type="submit"
color="primary" dense
v-close-popup unelevated
@click=" label="บันทึก"
() => { color="public"
(name = ''), (isActive = false); class="q-px-md"
} >
" <q-tooltip>นทกขอม</q-tooltip>
/> </q-btn>
</q-card-actions> </q-card-actions>
</form>
</q-card> </q-card>
</q-dialog> </q-dialog>
</template> </template>
<style></style> <style scoped lang="scss">
.border_custom {
border-radius: 6px !important;
border: 1px solid #e1e1e1;
}
$toggle-background-color-on: #06884d;
$toggle-background-color-off: darkgray;
$toggle-control-color: white;
$toggle-width: 40px;
$toggle-height: 25px;
$toggle-gutter: 3px;
$toggle-radius: 50%;
$toggle-control-speed: 0.15s;
$toggle-control-ease: ease-in;
// These are our computed variables
// change at your own risk.
$toggle-radius: $toggle-height / 2;
$toggle-control-size: $toggle-height - ($toggle-gutter * 2);
.toggle-control {
display: block;
position: relative;
padding-left: $toggle-width;
margin-bottom: 12px;
cursor: pointer;
font-size: 22px;
user-select: none;
input {
position: absolute;
opacity: 0;
cursor: pointer;
height: 0;
width: 0;
}
input:checked ~ .control {
background-color: $toggle-background-color-on;
&:after {
left: $toggle-width - $toggle-control-size - $toggle-gutter;
}
}
.control {
position: absolute;
top: -7px;
left: -15px;
height: $toggle-height;
width: $toggle-width;
border-radius: $toggle-radius;
background-color: $toggle-background-color-off;
transition: background-color $toggle-control-speed $toggle-control-ease;
&:after {
content: "";
position: absolute;
left: $toggle-gutter;
top: $toggle-gutter;
width: $toggle-control-size;
height: $toggle-control-size;
border-radius: $toggle-radius;
background: $toggle-control-color;
transition: left $toggle-control-speed $toggle-control-ease;
}
}
}
</style>

View file

@ -1,18 +1,33 @@
//ข้อมูล interface DataResponse {
interface ResponseHistoryObject { createdAt: Date;
createdAt?: Date; id: string;
createdFullName: String; isActive: boolean;
createdUserId: String;
id: String;
isActive: Boolean;
lastUpdateFullName: String; lastUpdateFullName: String;
lastUpdateUserId: String; lastUpdatedAt: Date;
lastUpdatedAt?: Date; name: string;
level: number;
name: String;
shortName: String;
insigniaType?: any;
note: string;
} }
export type { ResponseHistoryObject }; interface DataRow {
createdAt: string | null;
id: string;
isActive: boolean;
lastUpdateFullName: String;
lastUpdatedAt: string | null;
name: string;
}
interface DetailResponse extends DataResponse {
note: string;
shortName: string;
insigniaType: string;
insigniaTypeId: string;
level: number;
}
interface DetailRow
extends Omit<DetailResponse, "createdAt" | "lastUpdatedAt"> {
createdAt: string | null;
lastUpdatedAt: string | null;
}
export type { DataResponse, DataRow, DetailResponse, DetailRow };

View file

@ -0,0 +1,28 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import type {
DataResponse,
DataRow,
} from "../interface/response/insignia/Insignia";
import { useCounterMixin } from "@/stores/mixin";
const { date2Thai } = useCounterMixin();
export const useInsigniaDataStore = defineStore("insigniaData", () => {
const row = ref<DataRow[]>();
function fetchData(data: DataResponse[]) {
console.log(data);
const list = data.map((e) => ({
...e,
createdAt: e.createdAt ? date2Thai(e.createdAt) : "",
lastUpdatedAt: e.lastUpdatedAt ? date2Thai(e.lastUpdatedAt) : "",
}));
console.log(list);
row.value = list;
}
return {
fetchData,
row,
};
});