tableConfig.vue
2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<template>
<el-dialog
:title="$t('配置显示列')"
:visible.sync="configBool"
width="50%"
:close-on-click-modal="false"
class="manage-dialog"
:before-close="closeDialog"
>
<!-- 自定义字段 S -->
<el-checkbox-group v-model="keys" style="padding-bottom:20px;" >
<el-checkbox style="margin-top:6px;margin-bottom:6px;min-width:120px;" v-for="item in tabColumn" :checked="item.checked" :disabled="item.disable" :label="item.label" :key="item.prop"></el-checkbox>
</el-checkbox-group>
<!-- 自定义字段 e -->
<div slot="footer" class="dialog-footer">
<el-button class="dialog-btn" @click="closeDialog">{{$t('dialog.cancel')}}</el-button>
<el-button
type="primary"
@click="confirmSubmit"
class="dialog-btn dialog-confirm-btn"
>{{$t('dialog.confirm')}}</el-button>
</div>
</el-dialog>
</template>
<script>
import _ from 'underscore';
export default {
name: 'tableConfig',
data() {
return {
tabKey:'',
tabColumn:[],
keys:[],
configBool:false
}
},
methods:{
initDialog({tabKey,tabColumn}){
this.tabKey = tabKey+'_itable';
let localCols = localStorage.getItem(this.tabKey);
let hasConfig = false;
if(localCols){
hasConfig = true;
localCols = localCols.split(',');
}else{
localCols=[];
}
let keys = [];
let propObj = {};
this.tabColumn = _.map(tabColumn,col=>{
if((!hasConfig&&col.show)||(hasConfig&&localCols.includes(col.prop))){
col.checked = true;
propObj[col.prop] = true;
}else{
col.checked = false
}
col.label = this.$t(col.label);
col.disable = col.disable||false;
return col;
});
//if(this.keys.length)this.keys = keys;
return propObj;
},
showDialog(){
this.configBool = true;
},
closeDialog(){
this.configBool = false;
},
confirmSubmit(){
let propsObj = {};
let propsList = _.map(this.keys,label=>{
let col = _.findWhere(this.tabColumn,{label});
if(col&&col.prop){
propsObj[col.prop]=true;
return col.prop
}
return null;
});
localStorage.setItem(this.tabKey,propsList);
this.$emit('confirm',propsObj);
this.closeDialog();
},
}
}
</script>
<style>
</style>