显隐列组件支持全选/全不选

This commit is contained in:
RuoYi 2025-04-21 15:31:00 +08:00
parent b012116cdd
commit 6f79d5be91

View File

@ -13,9 +13,14 @@
<el-button circle icon="Menu" />
<template #dropdown>
<el-dropdown-menu>
<!-- 全选/反选 按钮 -->
<el-dropdown-item>
<el-checkbox :indeterminate="isIndeterminate" v-model="isChecked" @change="toggleCheckAll"> 列展示 </el-checkbox>
</el-dropdown-item>
<div class="check-line"></div>
<template v-for="item in columns" :key="item.key">
<el-dropdown-item>
<el-checkbox :checked="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
<el-checkbox v-model="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
</el-dropdown-item>
</template>
</el-dropdown-menu>
@ -39,83 +44,95 @@ const props = defineProps({
/* 是否显示检索条件 */
showSearch: {
type: Boolean,
default: true,
default: true
},
/* 显隐列信息 */
columns: {
type: Array,
type: Array
},
/* 是否显示检索图标 */
search: {
type: Boolean,
default: true,
default: true
},
/* 显隐列类型transfer穿梭框、checkbox复选框 */
showColumnsType: {
type: String,
default: "checkbox",
default: "checkbox"
},
/* 右外边距 */
gutter: {
type: Number,
default: 10,
default: 10
},
})
const emits = defineEmits(['update:showSearch', 'queryTable']);
const emits = defineEmits(['update:showSearch', 'queryTable'])
//
const value = ref([]);
const value = ref([])
//
const title = ref("显示/隐藏");
const title = ref("显示/隐藏")
//
const open = ref(false);
const open = ref(false)
const style = computed(() => {
const ret = {};
const ret = {}
if (props.gutter) {
ret.marginRight = `${props.gutter / 2}px`;
ret.marginRight = `${props.gutter / 2}px`
}
return ret;
});
return ret
})
// /
const isChecked = computed({
get: () => props.columns.every(col => col.visible),
set: () => {}
})
const isIndeterminate = computed(() => props.columns.some((col) => col.visible) && !isChecked.value)
//
function toggleSearch() {
emits("update:showSearch", !props.showSearch);
emits("update:showSearch", !props.showSearch)
}
//
function refresh() {
emits("queryTable");
emits("queryTable")
}
//
function dataChange(data) {
for (let item in props.columns) {
const key = props.columns[item].key;
props.columns[item].visible = !data.includes(key);
const key = props.columns[item].key
props.columns[item].visible = !data.includes(key)
}
}
// dialog
function showColumn() {
open.value = true;
open.value = true
}
if (props.showColumnsType == 'transfer') {
//
for (let item in props.columns) {
if (props.columns[item].visible === false) {
value.value.push(parseInt(item));
value.value.push(parseInt(item))
}
}
}
//
//
function checkboxChange(event, label) {
props.columns.filter(item => item.label == label)[0].visible = event;
props.columns.filter(item => item.label == label)[0].visible = event
}
// /
function toggleCheckAll() {
const newValue = !isChecked.value
props.columns.forEach((col) => (col.visible = newValue))
}
</script>
<style lang='scss' scoped>
@ -131,4 +148,10 @@ function checkboxChange(event, label) {
line-height: 30px;
padding: 0 17px;
}
.check-line {
width: 90%;
height: 1px;
background-color: #ccc;
margin: 3px auto;
}
</style>