feat: add VnMultiCheck component for multi-selection functionality
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
gitea/salix-front/pipeline/pr-dev This commit is unstable
Details
This commit is contained in:
parent
508cf2f684
commit
b13bcea331
|
@ -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({
|
||||||
|
@ -157,6 +158,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);
|
||||||
|
@ -638,6 +640,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">
|
||||||
|
@ -700,6 +719,15 @@ const rowCtrlClickFunction = computed(() => {
|
||||||
:hide-selected-banner="true"
|
:hide-selected-banner="true"
|
||||||
:data-cy
|
:data-cy
|
||||||
>
|
>
|
||||||
|
<template #header-selection>
|
||||||
|
<VnMultiCheck
|
||||||
|
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>
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
<script setup>
|
||||||
|
import { ref } from 'vue';
|
||||||
|
import VnCheckbox from './VnCheckbox.vue';
|
||||||
|
import axios from 'axios';
|
||||||
|
import { toRaw } from 'vue';
|
||||||
|
|
||||||
|
const model = defineModel({ type: [Boolean] });
|
||||||
|
const props = defineProps({
|
||||||
|
url: {
|
||||||
|
type: String,
|
||||||
|
default: null,
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const value = ref(false);
|
||||||
|
const rows = ref(0);
|
||||||
|
defineEmits(['update:selected', 'select:all']);
|
||||||
|
const onClick = async () => {
|
||||||
|
if (value.value) {
|
||||||
|
axios
|
||||||
|
.get(props.url, {
|
||||||
|
params: {
|
||||||
|
filter: null,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
rows.value = response.data;
|
||||||
|
console.log(response.data);
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<div style="display: flex">
|
||||||
|
<VnCheckbox v-model="value" @click="$emit('update:selected', value)" />
|
||||||
|
<QBtn v-if="value" 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))">
|
||||||
|
Select all({{ rows.length }})</QItem
|
||||||
|
>
|
||||||
|
<slot name="more-options"></slot>
|
||||||
|
</QList>
|
||||||
|
</QMenu>
|
||||||
|
</QBtn>
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue