2016-11-23 16:27:17 +08:00
|
|
|
<template>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
2016-11-24 15:27:46 +08:00
|
|
|
<th v-for="column in columns" :class="alignCls(column)">
|
2016-11-25 22:51:50 +08:00
|
|
|
<div :class="[prefixCls + '-cell', {[prefixCls + '-hidden']: column.fixed && (column.fixed === 'left' || column.fixed === 'right')}]">
|
2016-11-24 15:27:46 +08:00
|
|
|
<template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
|
|
|
|
<template v-else>{{{ renderHeader(column, $index) }}}</template>
|
|
|
|
</div>
|
|
|
|
</th>
|
2016-11-23 16:27:17 +08:00
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
</template>
|
|
|
|
<script>
|
2016-11-24 15:27:46 +08:00
|
|
|
import Checkbox from '../checkbox/checkbox.vue';
|
|
|
|
import Mixin from './mixin';
|
|
|
|
import { deepCopy } from '../../utils/assist';
|
|
|
|
|
2016-11-23 16:27:17 +08:00
|
|
|
export default {
|
2016-11-24 15:27:46 +08:00
|
|
|
mixins: [ Mixin ],
|
|
|
|
components: { Checkbox },
|
2016-11-23 16:27:17 +08:00
|
|
|
props: {
|
|
|
|
prefixCls: String,
|
2016-11-24 15:27:46 +08:00
|
|
|
columns: Array,
|
|
|
|
cloneData: Array
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
data () {
|
|
|
|
return {
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2016-11-24 15:27:46 +08:00
|
|
|
isSelectAll () {
|
|
|
|
return !this.cloneData.some(data => !data._isChecked);
|
|
|
|
}
|
2016-11-23 16:27:17 +08:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
renderHeader (column, $index) {
|
|
|
|
if ('renderHeader' in this.columns[$index]) {
|
|
|
|
return this.columns[$index].renderHeader(column, $index);
|
|
|
|
} else {
|
|
|
|
return column.title || '#';
|
|
|
|
}
|
2016-11-23 18:38:39 +08:00
|
|
|
},
|
2016-11-24 15:27:46 +08:00
|
|
|
selectAll () {
|
|
|
|
const status = !this.isSelectAll;
|
|
|
|
|
|
|
|
let tmpData = deepCopy(this.cloneData);
|
|
|
|
tmpData.forEach((data) => {
|
|
|
|
data._isChecked = status;
|
|
|
|
});
|
|
|
|
this.cloneData = tmpData;
|
|
|
|
|
|
|
|
if (status) {
|
|
|
|
this.$parent.selectAll();
|
|
|
|
}
|
2016-11-23 16:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|