0
0
Fork 0

refactors

This commit is contained in:
Alex Moreno 2024-06-20 10:55:29 +02:00
parent 11a82f3ae5
commit 03be4bc0e6
4 changed files with 37 additions and 28 deletions

View File

@ -9,7 +9,7 @@ import VnInput from 'components/common/VnInput.vue';
import VnInputDate from 'components/common/VnInputDate.vue';
import VnComponent from 'components/common/VnComponent.vue';
const model = defineModel();
const model = defineModel(undefined, { required: true });
const $props = defineProps({
column: {
type: Object,
@ -17,7 +17,7 @@ const $props = defineProps({
},
row: {
type: Object,
required: true,
default: () => {},
},
default: {
type: [Object, String],

View File

@ -27,7 +27,7 @@ const $props = defineProps({
default: 'params',
},
});
const model = defineModel();
const model = defineModel(undefined, { required: true });
const arrayData = useArrayData($props.dataKey, { searchUrl: $props.searchUrl });
const columnFilter = computed(() => $props.column?.columnFilter);
@ -96,7 +96,7 @@ const components = {
forceAttrs,
},
};
console.log(components);
async function addFilter(value) {
value ??= undefined;
if (value && typeof value === 'object') value = model.value;
@ -111,32 +111,36 @@ async function addFilter(value) {
}
function alignRow() {
if ($props.column.align == 'left') return 'justify-start items-start';
if ($props.column.align == 'right') return 'justify-end items-end';
switch ($props.column.align) {
case 'left':
return 'justify-start items-start';
case 'right':
return 'justify-end items-end';
default:
return 'flex-center';
}
}
const showFilter = computed(
() => $props.column?.columnFilter !== false && $props.column.name != 'tableActions'
);
</script>
<template>
<div
v-if="showTitle && column"
v-if="showTitle"
class="q-pt-sm q-px-sm ellipsis"
:class="`text-${column.align ?? 'left'}`"
:class="`text-${column?.align ?? 'left'}`"
:style="!showFilter ? { 'min-height': 72 + 'px' } : ''"
>
{{ column.label }}
{{ column?.label }}
</div>
<div
v-if="columnFilter !== false && column.name != 'tableActions'"
class="full-width"
:class="alignRow()"
>
<div v-if="showFilter" class="full-width" :class="alignRow()">
<VnTableColumn
:column="$props.column"
:row="{}"
default="input"
v-model="model"
:components="components"
component-prop="columnFilter"
/>
</div>
<div v-else-if="showTitle" style="height: 45px"><!-- fixme! --></div>
</template>

View File

@ -66,7 +66,9 @@ const route = useRoute();
const router = useRouter();
const quasar = useQuasar();
const mode = ref('card');
const DEFAULT_MODE = 'card';
const TABLE_MODE = 'table';
const mode = ref(DEFAULT_MODE);
const selected = ref([]);
const routeQuery = JSON.parse(route?.query[$props.searchUrl] ?? '{}');
const params = ref({ ...routeQuery, ...routeQuery.filter?.where });
@ -77,17 +79,17 @@ const tableModes = [
{
icon: 'view_column',
title: t('table view'),
value: 'table',
value: TABLE_MODE,
},
{
icon: 'grid_view',
title: t('grid view'),
value: 'card',
value: DEFAULT_MODE,
},
];
onMounted(() => {
mode.value = quasar.platform.is.mobile ? 'card' : $props.defaultMode;
mode.value = quasar.platform.is.mobile ? DEFAULT_MODE : $props.defaultMode;
stateStore.rightDrawer = true;
setUserParams(route.query[$props.searchUrl]);
});
@ -172,6 +174,9 @@ function columnName(col) {
return name;
}
function getColAlign(col) {
return 'text-' + (col.align ?? 'left')
}
defineExpose({
reload,
redirect: redirectFn,
@ -218,7 +223,7 @@ defineExpose({
:limit="20"
ref="CrudModelRef"
:search-url="searchUrl"
:disable-infinite-scroll="mode == 'table'"
:disable-infinite-scroll="mode == TABLE_MODE"
@save-changes="reload"
:has-subtoolbar="isEditable"
>
@ -229,11 +234,11 @@ defineExpose({
:columns="splittedColumns.columns"
:rows="rows"
v-model:selected="selected"
:grid="mode != 'table'"
:grid="mode != TABLE_MODE"
table-header-class="bg-header"
card-container-class="grid-three"
flat
:style="mode == 'table' && 'max-height: 90vh'"
:style="mode == TABLE_MODE && 'max-height: 90vh'"
virtual-scroll
@virtual-scroll="
(event) =>
@ -287,7 +292,7 @@ defineExpose({
<QTh auto-width class="sticky" />
</template>
<template #body-cell-tableStatus="{ col, row }">
<QTd auto-width :class="`text-${col.align ?? 'left'}`">
<QTd auto-width :class="getColAlign(col)">
<VnTableChip
:columns="splittedColumns.columnChips"
:row="row"
@ -303,7 +308,7 @@ defineExpose({
<QTd
auto-width
class="no-margin q-px-xs"
:class="`text-${col.align ?? 'left'}`"
:class="getColAlign(col)"
>
<VnTableColumn
:column="col"
@ -317,7 +322,7 @@ defineExpose({
<template #body-cell-tableActions="{ col, row }">
<QTd
auto-width
:class="`text-${col.align ?? 'left'}`"
:class="getColAlign(col)"
class="sticky no-padding"
@click="stopEventPropagation($event)"
>

View File

@ -1,7 +1,7 @@
<script setup>
import { computed, defineModel } from 'vue';
const model = defineModel();
const model = defineModel(undefined, { required: true });
const $props = defineProps({
prop: {
type: Object,