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

View File

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

View File

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

View File

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