ソースを参照

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

RuoYi 1 年間 前
コミット
d4af286f41
共有1 個のファイルを変更した33 個の追加8 個の削除を含む
  1. 33 8
      ruoyi-ui/src/components/RightToolbar/index.vue

+ 33 - 8
ruoyi-ui/src/components/RightToolbar/index.vue

@@ -12,9 +12,14 @@
12 12
         <el-dropdown trigger="click" :hide-on-click="false" style="padding-left: 12px" v-if="showColumnsType == 'checkbox'">
13 13
           <el-button size="mini" circle icon="el-icon-menu" />
14 14
           <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>
15 20
             <template v-for="item in columns">
16 21
               <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" />
18 23
               </el-dropdown-item>
19 24
             </template>
20 25
           </el-dropdown-menu>
@@ -41,33 +46,33 @@ export default {
41 46
       // 弹出层标题
42 47
       title: "显示/隐藏",
43 48
       // 是否显示弹出层
44
-      open: false,
49
+      open: false
45 50
     };
46 51
   },
47 52
   props: {
48 53
     /* 是否显示检索条件 */
49 54
     showSearch: {
50 55
       type: Boolean,
51
-      default: true,
56
+      default: true
52 57
     },
53 58
     /* 显隐列信息 */
54 59
     columns: {
55
-      type: Array,
60
+      type: Array
56 61
     },
57 62
     /* 是否显示检索图标 */
58 63
     search: {
59 64
       type: Boolean,
60
-      default: true,
65
+      default: true
61 66
     },
62 67
     /* 显隐列类型(transfer穿梭框、checkbox复选框) */
63 68
     showColumnsType: {
64 69
       type: String,
65
-      default: "checkbox",
70
+      default: "checkbox"
66 71
     },
67 72
     /* 右外边距 */
68 73
     gutter: {
69 74
       type: Number,
70
-      default: 10,
75
+      default: 10
71 76
     },
72 77
   },
73 78
   computed: {
@@ -77,6 +82,15 @@ export default {
77 82
         ret.marginRight = `${this.gutter / 2}px`;
78 83
       }
79 84
       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;
80 94
     }
81 95
   },
82 96
   created() {
@@ -109,9 +123,14 @@ export default {
109 123
     showColumn() {
110 124
       this.open = true;
111 125
     },
112
-    // 勾选
126
+    // 勾选
113 127
     checkboxChange(event, label) {
114 128
       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))
115 134
     }
116 135
   },
117 136
 };
@@ -126,4 +145,10 @@ export default {
126 145
 ::v-deep .el-transfer__button:first-child {
127 146
   margin-bottom: 10px;
128 147
 }
148
+.check-line {
149
+  width: 90%;
150
+  height: 1px;
151
+  background-color: #ccc;
152
+  margin: 3px auto;
153
+}
129 154
 </style>