Bläddra i källkod

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

RuoYi 1 år sedan
förälder
incheckning
d4af286f41
1 ändrade filer med 33 tillägg och 8 borttagningar
  1. 33 8
      ruoyi-ui/src/components/RightToolbar/index.vue

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

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