แก้ 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">
import { ref } from "vue";
import { useRouter } from "vue-router";
import InsigniaDetail from "@/modules/01_metadataNew/components/insignia/InsigniaList.vue";
import { ref, onMounted } from "vue";
import { useRouter, useRoute } from "vue-router";
import InsigniaList from "@/modules/01_metadataNew/components/insignia/InsigniaList.vue";
const router = useRouter();
const route = useRoute();
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) {
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>
<template>
<div class="toptitle text-dark col-12 row items-center">
@ -27,7 +132,11 @@ function fetchName(name: string) {
</div>
<q-card flat bordered>
<InsigniaDetail @update:fetchName="fetchName" />
<InsigniaList
:data="row"
@update:fetchName="fetchName"
:nameType="nameType"
/>
</q-card>
</template>

View file

@ -1,12 +1,15 @@
<script setup lang="ts">
import { ref } from "vue";
import { ref, onMounted } from "vue";
import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
import { useRouter } from "vue-router";
import dialogHeader from "@/components/DialogHeader.vue";
import { useQuasar } from "quasar";
const router = useRouter();
const mixin = useCounterMixin();
const { date2Thai, dialogRemove } = mixin;
const { date2Thai, dialogRemove, dialogConfirm } = mixin;
const $q = useQuasar();
const columns = ref<QTableProps["columns"]>([
{
name: "level",
@ -123,8 +126,9 @@ const isActive = ref<boolean>(false);
const name = ref<string>("");
const shortName = 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 visibleColumns = ref<string[]>([
"level",
@ -138,30 +142,36 @@ const visibleColumns = ref<string[]>([
"note",
]);
const row = ref([
{
level: 1,
shortName: "เทส",
insigniaType: "บำเหน็จ",
note: "-",
name: "testInside1",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: true,
},
{
level: 2,
shortName: "เทส2",
insigniaType: "บำนาญ",
note: "-",
name: "testInside2",
createdAt: date2Thai(new Date()),
lastUpdatedAt: date2Thai(new Date()),
lastUpdateFullName: "TestTest",
isActive: false,
},
]);
const props = defineProps({
data: { type: Object },
nameType: { type: String },
});
function closeDialog() {
dialog.value = false;
}
function validateForm() {
nameRef.value.validate();
shortNameRef.value.validate();
onSubmit();
}
async function onSubmit() {
if (name.value.length > 0 && shortName.value.length > 0) {
dialogConfirm(
$q,
async () => {
console.log("สำเร็จ");
closeDialog();
name.value = "";
shortName.value = "";
},
"ยืนยันการบันทึกข้อมูล",
"ต้องการยืนยันการบันทึกข้อมูลนี้หรือไม่ ?"
);
}
}
</script>
<template>
@ -204,7 +214,7 @@ const row = ref([
<d-table
ref="table"
:columns="columns"
:rows="row"
:rows="props.data"
:filter="filterKeyword"
row-key="name"
flat
@ -292,52 +302,164 @@ const row = ref([
</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 style="min-width: 350px" class="bg-grey-11">
<form @submit.prevent="validateForm">
<q-card-section class="flex justify-between" style="padding: 0">
<dialog-header
:tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="closeDialog"
/>
</q-card-section>
<q-card-section class="q-pt-none q-gutter-md">
<q-input
outlined
v-model="insigniaTypeId"
label="ลำดับชั้นเครื่องราชฯ"
dense
readonly
/>
<q-input outlined v-model="name" label="ชื่อเครื่องราชฯ" dense />
<q-input outlined v-model="shortName" label="ชื่อย่อ" dense />
<q-input
outlined
v-model="note"
type="textarea"
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-separator color="grey-4" />
<q-card-section class="q-pa-none">
<q-input
outlined
:model-value="nameType"
label="ลำดับชั้นเครื่องราชฯ"
dense
lazy-rules
borderless
class="col-12 bg-white q-ma-md"
hide-bottom-space
readonly
/>
<q-input
ref="nameRef"
outlined
v-model="name"
label="ชื่อเครื่องราช"
dense
lazy-rules
borderless
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-btn
flat
label="ตกลง"
color="primary"
v-close-popup
@click="
() => {
(name = ''), (isActive = false);
}
"
/>
</q-card-actions>
<q-card-actions align="right">
<q-btn
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip>
</q-btn>
</q-card-actions>
</form>
</q-card>
</q-dialog>
</div>
</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">
import { ref } from "vue";
import { ref, onMounted } from "vue";
import type { QTableProps } from "quasar";
import { useCounterMixin } from "@/stores/mixin";
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 mixin = useCounterMixin();
const { date2Thai, dialogRemove } = mixin;
const { dialogRemove, dialogConfirm } = mixin;
const columns = ref<QTableProps["columns"]>([
{
name: "name",
@ -65,11 +69,13 @@ const columns = ref<QTableProps["columns"]>([
},
]);
const $q = useQuasar();
const filterKeyword = ref<string>("");
const dialog = ref<boolean>(false);
const isActive = ref<boolean>(false);
const name = ref<string>("");
const nameRef = ref<any>(null);
const dialogStatus = ref<string>("");
const visibleColumns = ref<string[]>([
"name",
@ -79,28 +85,68 @@ const visibleColumns = ref<string[]>([
"isActive",
]);
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,
},
]);
// const row = ref([]);
function onclickDetail(data: (typeof row)["value"][number]) {
const id = data.id;
router.push(`/master-data/insignia/detail/test`);
function fetchData() {
const data = [
{
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>
@ -143,7 +189,7 @@ function onclickDetail(data: (typeof row)["value"][number]) {
<d-table
ref="table"
:columns="columns"
:rows="row"
:rows="store.row"
:filter="filterKeyword"
row-key="name"
flat
@ -165,7 +211,7 @@ function onclickDetail(data: (typeof row)["value"][number]) {
<q-tr
:props="props"
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">
<div v-if="col.name == 'isActive'">
@ -230,36 +276,128 @@ function onclickDetail(data: (typeof row)["value"][number]) {
</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 style="min-width: 350px" class="bg-grey-11">
<form @submit.prevent="validateForm">
<q-card-section class="flex justify-between" style="padding: 0">
<dialog-header
:tittle="dialogStatus == 'edit' ? 'แก้ไขข้อมูล' : 'เพิ่มข้อมูล'"
:close="closeDialog"
/>
</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-separator color="grey-4" />
<q-card-section class="q-pa-none">
<q-input
ref="nameRef"
outlined
v-model="name"
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-btn
flat
label="ตกลง"
color="primary"
v-close-popup
@click="
() => {
(name = ''), (isActive = false);
}
"
/>
</q-card-actions>
<q-card-actions align="right">
<q-btn
id="onSubmit"
type="submit"
dense
unelevated
label="บันทึก"
color="public"
class="q-px-md"
>
<q-tooltip>นทกขอม</q-tooltip>
</q-btn>
</q-card-actions>
</form>
</q-card>
</q-dialog>
</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 ResponseHistoryObject {
createdAt?: Date;
createdFullName: String;
createdUserId: String;
id: String;
isActive: Boolean;
interface DataResponse {
createdAt: Date;
id: string;
isActive: boolean;
lastUpdateFullName: String;
lastUpdateUserId: String;
lastUpdatedAt?: Date;
level: number;
name: String;
shortName: String;
insigniaType?: any;
note: string;
lastUpdatedAt: Date;
name: 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,
};
});