Skip to content

Commit 6d56dae

Browse files
committed
feat: 显隐列组件支持全选/全不选
1 parent 68a9203 commit 6d56dae

File tree

1 file changed

+33
-8
lines changed
  • ruoyi-fastapi-frontend/src/components/RightToolbar

1 file changed

+33
-8
lines changed

ruoyi-fastapi-frontend/src/components/RightToolbar/index.vue

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
<el-dropdown trigger="click" :hide-on-click="false" style="padding-left: 12px" v-if="showColumnsType == 'checkbox'">
1313
<el-button size="mini" circle icon="el-icon-menu" />
1414
<el-dropdown-menu slot="dropdown">
15+
<!-- 全选/反选 按钮 -->
16+
<el-dropdown-item>
17+
<el-checkbox :indeterminate="isIndeterminate" v-model="isChecked" @change="toggleCheckAll"> 列展示 </el-checkbox>
18+
</el-dropdown-item>
19+
<div class="check-line"></div>
1520
<template v-for="item in columns">
1621
<el-dropdown-item :key="item.key">
17-
<el-checkbox :checked="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
22+
<el-checkbox v-model="item.visible" @change="checkboxChange($event, item.label)" :label="item.label" />
1823
</el-dropdown-item>
1924
</template>
2025
</el-dropdown-menu>
@@ -41,33 +46,33 @@ export default {
4146
// 弹出层标题
4247
title: "显示/隐藏",
4348
// 是否显示弹出层
44-
open: false,
49+
open: false
4550
};
4651
},
4752
props: {
4853
/* 是否显示检索条件 */
4954
showSearch: {
5055
type: Boolean,
51-
default: true,
56+
default: true
5257
},
5358
/* 显隐列信息 */
5459
columns: {
55-
type: Array,
60+
type: Array
5661
},
5762
/* 是否显示检索图标 */
5863
search: {
5964
type: Boolean,
60-
default: true,
65+
default: true
6166
},
6267
/* 显隐列类型(transfer穿梭框、checkbox复选框) */
6368
showColumnsType: {
6469
type: String,
65-
default: "checkbox",
70+
default: "checkbox"
6671
},
6772
/* 右外边距 */
6873
gutter: {
6974
type: Number,
70-
default: 10,
75+
default: 10
7176
},
7277
},
7378
computed: {
@@ -77,6 +82,15 @@ export default {
7782
ret.marginRight = `${this.gutter / 2}px`;
7883
}
7984
return ret;
85+
},
86+
isChecked: {
87+
get() {
88+
return this.columns.every((col) => col.visible);
89+
},
90+
set() {}
91+
},
92+
isIndeterminate() {
93+
return this.columns.some((col) => col.visible) && !this.isChecked;
8094
}
8195
},
8296
created() {
@@ -109,9 +123,14 @@ export default {
109123
showColumn() {
110124
this.open = true;
111125
},
112-
// 勾选
126+
// 单勾选
113127
checkboxChange(event, label) {
114128
this.columns.filter(item => item.label == label)[0].visible = event;
129+
},
130+
// 切换全选/反选
131+
toggleCheckAll() {
132+
const newValue = !this.isChecked;
133+
this.columns.forEach((col) => (col.visible = newValue))
115134
}
116135
},
117136
};
@@ -126,4 +145,10 @@ export default {
126145
::v-deep .el-transfer__button:first-child {
127146
margin-bottom: 10px;
128147
}
148+
.check-line {
149+
width: 90%;
150+
height: 1px;
151+
background-color: #ccc;
152+
margin: 3px auto;
153+
}
129154
</style>

0 commit comments

Comments
 (0)