Merge pull request 'feat: add VnMultiCheck component for multi-selection functionality' (!1734) from vnTable_multi_check into dev
gitea/salix-front/pipeline/head This commit looks good Details

Reviewed-on: #1734
This commit is contained in:
Javier Segarra 2025-04-23 17:53:04 +00:00
commit 2c8d3ac0e0
5 changed files with 143 additions and 22 deletions

View File

@ -33,7 +33,8 @@ import VnTableOrder from 'src/components/VnTable/VnOrder.vue';
import VnTableFilter from './VnTableFilter.vue';
import { getColAlign } from 'src/composables/getColAlign';
import RightMenu from '../common/RightMenu.vue';
import VnScroll from '../common/VnScroll.vue'
import VnScroll from '../common/VnScroll.vue';
import VnMultiCheck from '../common/VnMultiCheck.vue';
const arrayData = useArrayData(useAttrs()['data-key']);
const $props = defineProps({
@ -113,6 +114,10 @@ const $props = defineProps({
type: Object,
default: () => ({}),
},
multiCheck: {
type: Object,
default: () => ({}),
},
crudModel: {
type: Object,
default: () => ({}),
@ -157,6 +162,7 @@ const CARD_MODE = 'card';
const TABLE_MODE = 'table';
const mode = ref(CARD_MODE);
const selected = ref([]);
const selectAll = ref(false);
const hasParams = ref(false);
const CrudModelRef = ref({});
const showForm = ref(false);
@ -195,10 +201,10 @@ const onVirtualScroll = ({ to }) => {
handleScroll();
const virtualScrollContainer = tableRef.value?.$el?.querySelector('.q-table__middle');
if (virtualScrollContainer) {
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
if (vnScrollRef.value) {
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
}
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
if (vnScrollRef.value) {
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
}
}
};
@ -341,11 +347,11 @@ function handleOnDataSaved(_) {
else $props.create.onDataSaved(_);
}
function handleScroll() {
if ($props.crudModel.disableInfiniteScroll) return;
const tMiddle = tableRef.value.$el.querySelector('.q-table__middle');
const { scrollHeight, scrollTop, clientHeight } = tMiddle;
const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) <= 40;
if (isAtBottom) CrudModelRef.value.vnPaginateRef.paginate();
if ($props.crudModel.disableInfiniteScroll) return;
const tMiddle = tableRef.value.$el.querySelector('.q-table__middle');
const { scrollHeight, scrollTop, clientHeight } = tMiddle;
const isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) <= 40;
if (isAtBottom) CrudModelRef.value.vnPaginateRef.paginate();
}
function handleSelection({ evt, added, rows: selectedRows }, rows) {
if (evt?.shiftKey && added) {
@ -638,6 +644,23 @@ const rowCtrlClickFunction = computed(() => {
};
return () => {};
});
const handleMultiCheck = (value) => {
if (value) {
selected.value = tableRef.value.rows;
} else {
selected.value = [];
}
emit('update:selected', selected.value);
};
const handleSelectedAll = (data) => {
if (data) {
selected.value = data;
} else {
selected.value = [];
}
emit('update:selected', selected.value);
};
</script>
<template>
<RightMenu v-if="$props.rightSearch" :overlay="overlay">
@ -661,7 +684,7 @@ const rowCtrlClickFunction = computed(() => {
<CrudModel
v-bind="$attrs"
:class="$attrs['class'] ?? 'q-px-md'"
:limit="$attrs['limit'] ?? 100"
:limit="$attrs['limit'] ?? 10"
ref="CrudModelRef"
@on-fetch="(...args) => emit('onFetch', ...args)"
:search-url="searchUrl"
@ -679,9 +702,9 @@ const rowCtrlClickFunction = computed(() => {
ref="tableRef"
v-bind="table"
:class="[
'vnTable',
table ? 'selection-cell' : '',
$props.footer ? 'last-row-sticky' : '',
'vnTable',
table ? 'selection-cell' : '',
$props.footer ? 'last-row-sticky' : '',
]"
wrap-cells
:columns="splittedColumns.columns"
@ -700,6 +723,18 @@ const rowCtrlClickFunction = computed(() => {
:hide-selected-banner="true"
:data-cy
>
<template #header-selection>
{{ $attrs['url'] }}
<VnMultiCheck
:searchUrl="searchUrl"
:expand="$props.multiCheck.expand"
v-model="selectAll"
:url="$attrs['url']"
@update:selected="handleMultiCheck"
@select:all="handleSelectedAll"
></VnMultiCheck>
</template>
<template #top-left v-if="!$props.withoutHeader">
<slot name="top-left"> </slot>
</template>
@ -1098,10 +1133,10 @@ const rowCtrlClickFunction = computed(() => {
</template>
</FormModelPopup>
</QDialog>
<VnScroll
ref="vnScrollRef"
v-if="isTableMode"
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
<VnScroll
ref="vnScrollRef"
v-if="isTableMode"
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
/>
</template>
<i18n>

View File

@ -0,0 +1,80 @@
<script setup>
import { ref } from 'vue';
import VnCheckbox from './VnCheckbox.vue';
import axios from 'axios';
import { toRaw } from 'vue';
import { useI18n } from 'vue-i18n';
import { useRoute } from 'vue-router';
const route = useRoute();
const { t } = useI18n();
const model = defineModel({ type: [Boolean] });
const props = defineProps({
expand: {
type: Boolean,
default: false,
},
url: {
type: String,
default: null,
required: true,
},
searchUrl: {
type: [String, Boolean],
default: 'table',
},
});
const value = ref(false);
const rows = ref(0);
const onClick = () => {
if (value.value) {
const { filter } = JSON.parse(route.query[props.searchUrl]);
filter.limit = 0;
const params = {
params: { filter: JSON.stringify(filter) },
};
axios
.get(props.url, params)
.then(({ data }) => {
rows.value = data;
})
.catch(console.error);
}
};
defineEmits(['update:selected', 'select:all']);
</script>
<template>
<div style="display: flex">
<VnCheckbox v-model="value" @click="$emit('update:selected', value)" />
<QBtn
v-if="value && $props.expand"
flat
dense
icon="expand_more"
@click="onClick"
>
<QMenu anchor="bottom right" self="top right">
<QList>
<QItem v-ripple clickable @click="$emit('select:all', toRaw(rows))">
{{ t('Select all', { rows: rows.length }) }}
</QItem>
<slot name="more-options"></slot>
</QList>
</QMenu>
</QBtn>
</div>
</template>
<i18n lang="yml">
en:
Select all: 'Select all ({rows})'
fr:
Select all: 'Sélectionner tout ({rows})'
es:
Select all: 'Seleccionar todo ({rows})'
de:
Select all: 'Alle auswählen ({rows})'
it:
Select all: 'Seleziona tutto ({rows})'
pt:
Select all: 'Selecionar tudo ({rows})'
</i18n>

View File

@ -100,6 +100,9 @@ const columns = computed(() => [
'row-key': 'id',
selection: 'multiple',
}"
:multi-check="{
expand: true,
}"
v-model:selected="selected"
:right-search="true"
:columns="columns"

View File

@ -98,7 +98,9 @@ onMounted(async () => {
<QBtn color="primary" icon="show_chart" :disable="!selectedRows">
<QPopupProxy ref="popupProxyRef">
<QCard class="column q-pa-md">
<span class="text-body1 q-mb-sm">{{ t('Campaign consumption') }}</span>
<span class="text-body1 q-mb-sm">{{
t('Campaign consumption', { rows: $props.clients.length })
}}</span>
<VnRow>
<VnSelect
:options="moreFields"
@ -140,12 +142,13 @@ onMounted(async () => {
valentinesDay: Valentine's Day
mothersDay: Mother's Day
allSaints: All Saints' Day
Campaign consumption: Campaign consumption ({rows})
es:
params:
valentinesDay: Día de San Valentín
mothersDay: Día de la Madre
allSaints: Día de Todos los Santos
Campaign consumption: Consumo campaña
Campaign consumption: Consumo campaña ({rows})
Campaign: Campaña
From: Desde
To: Hasta

View File

@ -54,7 +54,7 @@ describe('Handle Items FixedPrice', () => {
});
it('should edit all items', () => {
cy.get('.bg-header > :nth-child(1) > .q-checkbox > .q-checkbox__inner').click();
cy.get('.bg-header > :nth-child(1) [data-cy="vnCheckbox"]').click();
cy.dataCy('FixedPriceToolbarEditBtn').should('not.be.disabled');
cy.dataCy('FixedPriceToolbarEditBtn').click();
cy.dataCy('EditFixedPriceSelectOption').type(grouping);
@ -65,7 +65,7 @@ describe('Handle Items FixedPrice', () => {
});
it('should remove all items', () => {
cy.get('.bg-header > :nth-child(1) > .q-checkbox > .q-checkbox__inner').click();
cy.get('.bg-header > :nth-child(1) [data-cy="vnCheckbox"]').click();
cy.dataCy('crudModelDefaultRemoveBtn').should('not.be.disabled');
cy.dataCy('crudModelDefaultRemoveBtn').click();
cy.dataCy('VnConfirm_confirm').click();