Prechádzať zdrojové kódy

by-table组件添加列开关功能

asd26269546 2 rokov pred
rodič
commit
7597f7739f

+ 30 - 2
src/components/by-table/index.js

@@ -4,6 +4,7 @@ export default {
         return {
             sortFilterModal:false,
             checkboxValue:[],
+            columnsCopy:[],
         }
     },
     props: {
@@ -87,7 +88,11 @@ export default {
             return (
                 <elTable data={this.data}>
                     {
-                        this.columns.map(item => {
+                        this.columnsCopy.map(item => {
+                            //是否显示判断
+                            if(!item.isShow) {
+                                return
+                            }
                             if (item.actions) {
                                 return this.renderActionColumn(h, item)
                             } else if (item.render) {
@@ -227,11 +232,34 @@ export default {
             </el-dialog>
         },
         sortFilterSubmit(){
-            console.log(this.checkboxValue)
+            this.columnsCopy.map(items => {
+                items.isShow = false
+                this.checkboxValue.map(j => {
+                    if(items.label === j){
+                        items.isShow = true
+                    }
+                })
+            })
+        },
+        //获取列配置和初始化
+        getSortFilterConfig(){
+            const v = this
+            if(!v.columns){
+                console.log('请配置columns') 
+                return
+            }
+            this.checkboxValue = []
+            v.columns.map(items => {
+                items.isShow = true,
+                this.checkboxValue.push(items.label)
+            })
+            v.columnsCopy = JSON.parse(JSON.stringify(this.columns))
+
         },
     },
     created() {
         this.renderSearchInit()
+        this.getSortFilterConfig()
     },
     name: 'by-table',
     render(h) {

+ 1 - 1
src/views/management/video-setting/index.vue

@@ -149,7 +149,7 @@ export default {
           },
         },
         {
-          label: "姓名",
+          label: "操作",
           prop: "title",
           actions: [
             {