table-head.vue
2.23 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
<template>
<table cellspacing="0" cellpadding="0" border="0" :style="style">
<colgroup>
<col v-for="column in columns" :width="setCellWidth(column, $index)">
</colgroup>
<thead>
<tr>
<th v-for="column in columns" :class="alignCls(column)">
<div :class="[prefixCls + '-cell', {[prefixCls + '-hidden']: !fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')}]">
<template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
<template v-else>{{{ renderHeader(column, $index) }}}</template>
</div>
</th>
</tr>
</thead>
</table>
</template>
<script>
import Checkbox from '../checkbox/checkbox.vue';
import Mixin from './mixin';
import { deepCopy } from '../../utils/assist';
export default {
mixins: [ Mixin ],
components: { Checkbox },
props: {
prefixCls: String,
style: Object,
columns: Array,
cloneData: Array,
fixed: Boolean
},
computed: {
isSelectAll () {
return !this.cloneData.some(data => !data._isChecked);
}
},
methods: {
setCellWidth (column, index) {
return this.$parent.setCellWidth(column, index);
},
renderHeader (column, $index) {
if ('renderHeader' in this.columns[$index]) {
return this.columns[$index].renderHeader(column, $index);
} else {
return column.title || '#';
}
},
selectAll () {
const status = !this.isSelectAll;
this.$parent.selectAll(status);
// let tmpData = deepCopy(this.cloneData);
// tmpData.forEach((data) => {
// data._isChecked = status;
// });
// this.cloneData = tmpData;
//
// if (status) {
// this.$parent.selectAll();
// }
}
}
}
</script>