jws-frontend/src/components/TableComponents.vue

135 lines
3.3 KiB
Vue
Raw Normal View History

2024-09-18 11:01:33 +07:00
<script setup lang="ts">
import { QTableProps } from 'quasar';
import KebabAction from 'components/shared/KebabAction.vue';
2024-09-25 12:40:34 +07:00
import DeleteButton from './button/DeleteButton.vue';
2024-09-18 11:01:33 +07:00
const props = withDefaults(
defineProps<{
rows: QTableProps['rows'];
columns: QTableProps['columns'];
flat?: boolean;
bordered?: boolean;
grid?: boolean;
hideHeader?: boolean;
buttomDownload?: boolean;
2024-09-25 12:40:34 +07:00
buttonDelete?: boolean;
hidePagination?: boolean;
imgColumn?: string;
customColumn?: string[];
2024-09-18 11:01:33 +07:00
}>(),
{
row: () => [],
column: () => [],
flat: false,
bordered: false,
grid: false,
hideHeader: false,
buttomDownload: false,
2024-09-25 12:40:34 +07:00
imgColumn: '',
customColumn: () => [],
2024-09-18 11:01:33 +07:00
},
);
2024-09-19 09:52:21 +07:00
defineEmits<{
(e: 'view', index: number): void;
(e: 'edit', index: number): void;
(e: 'delete', index: number): void;
(e: 'toggleStatus', row: typeof props.rows): void;
2024-09-19 11:34:06 +07:00
(e: 'download', index: number): void;
2024-09-19 09:52:21 +07:00
}>();
2024-09-18 11:01:33 +07:00
</script>
<template>
2024-09-25 12:40:34 +07:00
<q-table
v-bind="props"
class="full-height"
:no-data-label="$t('general.noDataTable')"
:hide-pagination
>
2024-09-18 11:01:33 +07:00
<template v-slot:header="props">
<q-tr
2024-09-25 12:40:34 +07:00
style="background-color: hsla(var(--info-bg) / 0.07)"
2024-09-18 11:01:33 +07:00
:props="props"
>
<q-th v-for="col in props.cols" :key="col.name" :props="props">
<span v-if="col.label === 'nameEmployee'">
{{ $t('fullname') }}
</span>
<span v-if="col.label !== ''">
{{ $t(col.label) }}
</span>
</q-th>
</q-tr>
</template>
2024-09-25 12:40:34 +07:00
<template v-slot:body-cell-order="props">
<q-td class="text-center">
{{ props.rowIndex + 1 }}
</q-td>
</template>
<template v-slot:[`body-cell-${imgColumn}`]="props">
<q-td>
<slot name="img-column" :props="props"></slot>
{{ props.row[imgColumn] }}
</q-td>
</template>
<template
v-for="col in customColumn"
:key="col"
v-slot:[`body-cell-${col}`]="props"
>
<slot :name="`body-cell-${col}`" :props="props"></slot>
</template>
2024-09-18 11:01:33 +07:00
<template v-slot:body-cell-action="props">
<q-td class="text-center row items-center">
<slot name="button" :props="props"></slot>
2024-09-25 12:40:34 +07:00
<DeleteButton iconOnly v-if="buttonDelete" />
2024-09-18 11:01:33 +07:00
<q-btn
2024-09-25 12:40:34 +07:00
v-if="!buttonDelete"
2024-09-18 11:01:33 +07:00
icon="mdi-eye-outline"
size="sm"
dense
round
flat
2024-09-19 09:52:21 +07:00
@click.stop="$emit('view', props.rowIndex)"
2024-09-18 11:01:33 +07:00
/>
<q-btn
2024-09-19 11:34:06 +07:00
v-if="buttomDownload && props.row.id !== undefined"
2024-09-18 11:01:33 +07:00
icon="mdi-download-outline"
size="sm"
dense
round
flat
2024-09-19 11:34:06 +07:00
@click.stop="$emit('download', props.rowIndex)"
2024-09-18 11:01:33 +07:00
/>
<KebabAction
2024-09-25 12:40:34 +07:00
v-if="!buttonDelete"
2024-09-19 11:34:06 +07:00
hide-toggle
2024-09-18 11:01:33 +07:00
:id-name="props.row.code"
:status="props.row.status"
2024-09-19 09:52:21 +07:00
@view="$emit('view', props.rowIndex)"
@edit="$emit('edit', props.rowIndex)"
@delete="$emit('delete', props.rowIndex)"
2024-09-18 11:01:33 +07:00
@change-status="$emit('toggleStatus', props.row)"
/>
</q-td>
<slot name="dialog" :index="props.rowIndex" :row="props.row"></slot>
</template>
</q-table>
</template>
2024-09-25 12:40:34 +07:00
<style lang="scss" scoped>
:deep(i.q-icon.mdi.mdi-alert.q-table__bottom-nodata-icon) {
color: #ffc224 !important;
}
</style>