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

View file

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

View file

@ -30,30 +30,33 @@ const currentIndex = ref<number>(-1);
const statusOcr = ref<boolean>(false);
const props = defineProps<{
showTitle?: boolean;
ocr?: (
group: any,
file: File,
) => void | Promise<{
status: boolean;
group: string;
meta: { name: string; value: string }[];
}>;
getFileList?: (group: any) => Promise<typeof obj.value>;
deleteItem?: (obj: any) => void | Promise<boolean>;
download?: (obj: any) => void;
save?: (
group: any,
meta: any,
file: File | undefined,
) => void | Promise<boolean>;
autoSave?: boolean;
readonly?: boolean;
hideAction?: boolean;
columns: QTableProps['columns'];
menu?: { label: string; value: string; _meta?: Record<string, any> }[];
}>();
const props = withDefaults(
defineProps<{
readonly?: boolean;
showTitle?: boolean;
ocr?: (
group: any,
file: File,
) => void | Promise<{
status: boolean;
group: string;
meta: { name: string; value: string }[];
}>;
getFileList?: (group: any) => Promise<typeof obj.value>;
deleteItem?: (obj: any) => void | Promise<boolean>;
download?: (obj: any) => void;
save?: (
group: any,
meta: any,
file: File | undefined,
) => void | Promise<boolean>;
autoSave?: boolean;
hideAction?: boolean;
columns: QTableProps['columns'];
menu?: { label: string; value: string; _meta?: Record<string, any> }[];
}>(),
{},
);
async function triggerDelete(item: any) {
dialog({
@ -272,6 +275,7 @@ defineEmits<{
<div class="full-width q-pa-md">
<TableComponents
buttomDownload
:readonly="readonly"
@download="
(index) => {
download?.(obj[index]);
@ -331,6 +335,7 @@ defineEmits<{
edit
hideDelete
:is-edit="isEdit"
:readonly="readonly"
style="position: absolute"
height="100vh"
weight="90%"
@ -359,7 +364,15 @@ defineEmits<{
:submit="
async () => {
modalDialog = false;
$emit('submit', obj[currentIndex].group, allMeta);
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?.(
obj[currentIndex].group,
obj[currentIndex]._meta,
@ -370,7 +383,6 @@ defineEmits<{
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="currentFromDataEmployee.file"
hide-action
:readonly="!employeeFormState.isEmployeeEdit"
:group-list="uploadFileListEmployee"
:menu="uploadFileListEmployee"
:columns="columnsAttachment"
@ -4091,6 +4092,7 @@ const emptyCreateDialog = ref(false);
v-model:current-id="currentFromDataEmployee.id"
v-model="currentFromDataEmployee.file"
hide-action
:readonly="!employeeFormState.isEmployeeEdit"
:group-list="uploadFileListEmployee"
:menu="uploadFileListEmployee"
:columns="columnsAttachment"