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
gitea/salix-front/pipeline/head This commit looks good
Details
Reviewed-on: #1734
This commit is contained in:
commit
2c8d3ac0e0
|
@ -33,7 +33,8 @@ import VnTableOrder from 'src/components/VnTable/VnOrder.vue';
|
||||||
import VnTableFilter from './VnTableFilter.vue';
|
import VnTableFilter from './VnTableFilter.vue';
|
||||||
import { getColAlign } from 'src/composables/getColAlign';
|
import { getColAlign } from 'src/composables/getColAlign';
|
||||||
import RightMenu from '../common/RightMenu.vue';
|
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 arrayData = useArrayData(useAttrs()['data-key']);
|
||||||
const $props = defineProps({
|
const $props = defineProps({
|
||||||
|
@ -113,6 +114,10 @@ const $props = defineProps({
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
},
|
},
|
||||||
|
multiCheck: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({}),
|
||||||
|
},
|
||||||
crudModel: {
|
crudModel: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => ({}),
|
default: () => ({}),
|
||||||
|
@ -157,6 +162,7 @@ const CARD_MODE = 'card';
|
||||||
const TABLE_MODE = 'table';
|
const TABLE_MODE = 'table';
|
||||||
const mode = ref(CARD_MODE);
|
const mode = ref(CARD_MODE);
|
||||||
const selected = ref([]);
|
const selected = ref([]);
|
||||||
|
const selectAll = ref(false);
|
||||||
const hasParams = ref(false);
|
const hasParams = ref(false);
|
||||||
const CrudModelRef = ref({});
|
const CrudModelRef = ref({});
|
||||||
const showForm = ref(false);
|
const showForm = ref(false);
|
||||||
|
@ -195,10 +201,10 @@ const onVirtualScroll = ({ to }) => {
|
||||||
handleScroll();
|
handleScroll();
|
||||||
const virtualScrollContainer = tableRef.value?.$el?.querySelector('.q-table__middle');
|
const virtualScrollContainer = tableRef.value?.$el?.querySelector('.q-table__middle');
|
||||||
if (virtualScrollContainer) {
|
if (virtualScrollContainer) {
|
||||||
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
|
virtualScrollContainer.dispatchEvent(new CustomEvent('scroll'));
|
||||||
if (vnScrollRef.value) {
|
if (vnScrollRef.value) {
|
||||||
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
|
vnScrollRef.value.updateScrollContainer(virtualScrollContainer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -638,6 +644,23 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
};
|
};
|
||||||
return () => {};
|
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>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<RightMenu v-if="$props.rightSearch" :overlay="overlay">
|
<RightMenu v-if="$props.rightSearch" :overlay="overlay">
|
||||||
|
@ -661,7 +684,7 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
<CrudModel
|
<CrudModel
|
||||||
v-bind="$attrs"
|
v-bind="$attrs"
|
||||||
:class="$attrs['class'] ?? 'q-px-md'"
|
:class="$attrs['class'] ?? 'q-px-md'"
|
||||||
:limit="$attrs['limit'] ?? 100"
|
:limit="$attrs['limit'] ?? 10"
|
||||||
ref="CrudModelRef"
|
ref="CrudModelRef"
|
||||||
@on-fetch="(...args) => emit('onFetch', ...args)"
|
@on-fetch="(...args) => emit('onFetch', ...args)"
|
||||||
:search-url="searchUrl"
|
:search-url="searchUrl"
|
||||||
|
@ -679,9 +702,9 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
ref="tableRef"
|
ref="tableRef"
|
||||||
v-bind="table"
|
v-bind="table"
|
||||||
:class="[
|
:class="[
|
||||||
'vnTable',
|
'vnTable',
|
||||||
table ? 'selection-cell' : '',
|
table ? 'selection-cell' : '',
|
||||||
$props.footer ? 'last-row-sticky' : '',
|
$props.footer ? 'last-row-sticky' : '',
|
||||||
]"
|
]"
|
||||||
wrap-cells
|
wrap-cells
|
||||||
:columns="splittedColumns.columns"
|
:columns="splittedColumns.columns"
|
||||||
|
@ -700,6 +723,18 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
:hide-selected-banner="true"
|
:hide-selected-banner="true"
|
||||||
:data-cy
|
: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">
|
<template #top-left v-if="!$props.withoutHeader">
|
||||||
<slot name="top-left"> </slot>
|
<slot name="top-left"> </slot>
|
||||||
</template>
|
</template>
|
||||||
|
@ -1099,9 +1134,9 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
</FormModelPopup>
|
</FormModelPopup>
|
||||||
</QDialog>
|
</QDialog>
|
||||||
<VnScroll
|
<VnScroll
|
||||||
ref="vnScrollRef"
|
ref="vnScrollRef"
|
||||||
v-if="isTableMode"
|
v-if="isTableMode"
|
||||||
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
|
:scroll-target="tableRef?.$el?.querySelector('.q-table__middle')"
|
||||||
/>
|
/>
|
||||||
</template>
|
</template>
|
||||||
<i18n>
|
<i18n>
|
||||||
|
|
|
@ -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>
|
|
@ -100,6 +100,9 @@ const columns = computed(() => [
|
||||||
'row-key': 'id',
|
'row-key': 'id',
|
||||||
selection: 'multiple',
|
selection: 'multiple',
|
||||||
}"
|
}"
|
||||||
|
:multi-check="{
|
||||||
|
expand: true,
|
||||||
|
}"
|
||||||
v-model:selected="selected"
|
v-model:selected="selected"
|
||||||
:right-search="true"
|
:right-search="true"
|
||||||
:columns="columns"
|
:columns="columns"
|
||||||
|
|
|
@ -98,7 +98,9 @@ onMounted(async () => {
|
||||||
<QBtn color="primary" icon="show_chart" :disable="!selectedRows">
|
<QBtn color="primary" icon="show_chart" :disable="!selectedRows">
|
||||||
<QPopupProxy ref="popupProxyRef">
|
<QPopupProxy ref="popupProxyRef">
|
||||||
<QCard class="column q-pa-md">
|
<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>
|
<VnRow>
|
||||||
<VnSelect
|
<VnSelect
|
||||||
:options="moreFields"
|
:options="moreFields"
|
||||||
|
@ -140,12 +142,13 @@ onMounted(async () => {
|
||||||
valentinesDay: Valentine's Day
|
valentinesDay: Valentine's Day
|
||||||
mothersDay: Mother's Day
|
mothersDay: Mother's Day
|
||||||
allSaints: All Saints' Day
|
allSaints: All Saints' Day
|
||||||
|
Campaign consumption: Campaign consumption ({rows})
|
||||||
es:
|
es:
|
||||||
params:
|
params:
|
||||||
valentinesDay: Día de San Valentín
|
valentinesDay: Día de San Valentín
|
||||||
mothersDay: Día de la Madre
|
mothersDay: Día de la Madre
|
||||||
allSaints: Día de Todos los Santos
|
allSaints: Día de Todos los Santos
|
||||||
Campaign consumption: Consumo campaña
|
Campaign consumption: Consumo campaña ({rows})
|
||||||
Campaign: Campaña
|
Campaign: Campaña
|
||||||
From: Desde
|
From: Desde
|
||||||
To: Hasta
|
To: Hasta
|
||||||
|
|
|
@ -54,7 +54,7 @@ describe('Handle Items FixedPrice', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should edit all items', () => {
|
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').should('not.be.disabled');
|
||||||
cy.dataCy('FixedPriceToolbarEditBtn').click();
|
cy.dataCy('FixedPriceToolbarEditBtn').click();
|
||||||
cy.dataCy('EditFixedPriceSelectOption').type(grouping);
|
cy.dataCy('EditFixedPriceSelectOption').type(grouping);
|
||||||
|
@ -65,7 +65,7 @@ describe('Handle Items FixedPrice', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove all items', () => {
|
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').should('not.be.disabled');
|
||||||
cy.dataCy('crudModelDefaultRemoveBtn').click();
|
cy.dataCy('crudModelDefaultRemoveBtn').click();
|
||||||
cy.dataCy('VnConfirm_confirm').click();
|
cy.dataCy('VnConfirm_confirm').click();
|
||||||
|
|
Loading…
Reference in New Issue