refactor: set readonly

This commit is contained in:
Thanaphon Frappet 2024-10-17 11:48:56 +07:00
parent 2d4d0c7783
commit 48017761c2
4 changed files with 44 additions and 33 deletions

View file

@ -21,6 +21,7 @@ defineProps<{
edit?: boolean; edit?: boolean;
hideFooter?: boolean; hideFooter?: boolean;
hideDelete?: boolean; hideDelete?: boolean;
readonly?: boolean;
saveAmount?: number; saveAmount?: number;
submitLabel?: string; submitLabel?: string;
@ -67,7 +68,7 @@ const currentTab = defineModel<string>('currentTab');
}" }"
> >
<div class="row items-center"> <div class="row items-center">
<div v-if="isEdit && edit" class="row"> <div v-if="!readonly && isEdit && edit" class="row">
<q-btn <q-btn
round round
flat flat
@ -81,7 +82,7 @@ const currentTab = defineModel<string>('currentTab');
/> />
<div style="width: 31.98px"></div> <div style="width: 31.98px"></div>
</div> </div>
<div v-if="!isEdit && edit"> <div v-if="!readonly && !isEdit && edit">
<q-btn <q-btn
round round
flat flat

View file

@ -92,17 +92,13 @@ defineEmits<{
<template v-slot:body-cell-action="props"> <template v-slot:body-cell-action="props">
<q-td> <q-td>
<div <div class="row items-center full-width justify-end no-wrap">
class="row items-center full-width justify-end no-wrap"
v-if="!readonly"
>
<slot name="button" :props="props"></slot> <slot name="button" :props="props"></slot>
<DeleteButton <DeleteButton
iconOnly iconOnly
v-if="buttonDelete" v-if="buttonDelete"
@click="$emit('delete', props.rowIndex)" @click="$emit('delete', props.rowIndex)"
/> />
<q-btn <q-btn
v-if="!buttonDelete" v-if="!buttonDelete"
icon="mdi-eye-outline" icon="mdi-eye-outline"
@ -124,7 +120,7 @@ defineEmits<{
/> />
<KebabAction <KebabAction
v-if="!buttonDelete" v-if="!buttonDelete && !readonly"
hide-toggle hide-toggle
:id-name="props.row.code" :id-name="props.row.code"
:status="props.row.status" :status="props.row.status"

View file

@ -30,30 +30,33 @@ const currentIndex = ref<number>(-1);
const statusOcr = ref<boolean>(false); const statusOcr = ref<boolean>(false);
const props = defineProps<{ const props = withDefaults(
showTitle?: boolean; defineProps<{
ocr?: ( readonly?: boolean;
group: any, showTitle?: boolean;
file: File, ocr?: (
) => void | Promise<{ group: any,
status: boolean; file: File,
group: string; ) => void | Promise<{
meta: { name: string; value: string }[]; status: boolean;
}>; group: string;
getFileList?: (group: any) => Promise<typeof obj.value>; meta: { name: string; value: string }[];
deleteItem?: (obj: any) => void | Promise<boolean>; }>;
download?: (obj: any) => void; getFileList?: (group: any) => Promise<typeof obj.value>;
save?: ( deleteItem?: (obj: any) => void | Promise<boolean>;
group: any, download?: (obj: any) => void;
meta: any, save?: (
file: File | undefined, group: any,
) => void | Promise<boolean>; meta: any,
autoSave?: boolean; file: File | undefined,
readonly?: boolean; ) => void | Promise<boolean>;
hideAction?: boolean; autoSave?: boolean;
columns: QTableProps['columns']; hideAction?: boolean;
menu?: { label: string; value: string; _meta?: Record<string, any> }[]; columns: QTableProps['columns'];
}>(); menu?: { label: string; value: string; _meta?: Record<string, any> }[];
}>(),
{},
);
async function triggerDelete(item: any) { async function triggerDelete(item: any) {
dialog({ dialog({
@ -272,6 +275,7 @@ defineEmits<{
<div class="full-width q-pa-md"> <div class="full-width q-pa-md">
<TableComponents <TableComponents
buttomDownload buttomDownload
:readonly="readonly"
@download=" @download="
(index) => { (index) => {
download?.(obj[index]); download?.(obj[index]);
@ -331,6 +335,7 @@ defineEmits<{
edit edit
hideDelete hideDelete
:is-edit="isEdit" :is-edit="isEdit"
:readonly="readonly"
style="position: absolute" style="position: absolute"
height="100vh" height="100vh"
weight="90%" weight="90%"
@ -359,7 +364,15 @@ defineEmits<{
:submit=" :submit="
async () => { async () => {
modalDialog = false; modalDialog = false;
$emit('submit', obj[currentIndex].group, allMeta);
if (autoSave === true) { if (autoSave === true) {
if (obj[currentIndex].group === 'passport') {
delete obj[currentIndex]._meta?.firstName;
delete obj[currentIndex]._meta?.lastName;
delete obj[currentIndex]._meta?.gender;
}
const statusSave = await save?.( const statusSave = await save?.(
obj[currentIndex].group, obj[currentIndex].group,
obj[currentIndex]._meta, obj[currentIndex]._meta,
@ -370,7 +383,6 @@ defineEmits<{
fileList(); fileList();
} }
} }
$emit('submit', obj[currentIndex].group, allMeta);
} }
" "
> >

View file

@ -2655,6 +2655,7 @@ const emptyCreateDialog = ref(false);
v-model:current-id="currentFromDataEmployee.id" v-model:current-id="currentFromDataEmployee.id"
v-model="currentFromDataEmployee.file" v-model="currentFromDataEmployee.file"
hide-action hide-action
:readonly="!employeeFormState.isEmployeeEdit"
:group-list="uploadFileListEmployee" :group-list="uploadFileListEmployee"
:menu="uploadFileListEmployee" :menu="uploadFileListEmployee"
:columns="columnsAttachment" :columns="columnsAttachment"
@ -4091,6 +4092,7 @@ const emptyCreateDialog = ref(false);
v-model:current-id="currentFromDataEmployee.id" v-model:current-id="currentFromDataEmployee.id"
v-model="currentFromDataEmployee.file" v-model="currentFromDataEmployee.file"
hide-action hide-action
:readonly="!employeeFormState.isEmployeeEdit"
:group-list="uploadFileListEmployee" :group-list="uploadFileListEmployee"
:menu="uploadFileListEmployee" :menu="uploadFileListEmployee"
:columns="columnsAttachment" :columns="columnsAttachment"