Blame view

src/components/table/table-head.vue 1.72 KB
2cb8a6d9   梁灏   commit Table comp...
1
2
3
  <template>
      <thead>
          <tr>
0d136465   梁灏   update Table
4
5
6
7
8
9
              <th v-for="column in columns" :class="alignCls(column)">
                  <div :class="[prefixCls + '-cell']">
                      <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
                      <template v-else>{{{ renderHeader(column, $index) }}}</template>
                  </div>
              </th>
2cb8a6d9   梁灏   commit Table comp...
10
11
12
13
          </tr>
      </thead>
  </template>
  <script>
0d136465   梁灏   update Table
14
15
16
17
      import Checkbox from '../checkbox/checkbox.vue';
      import Mixin from './mixin';
      import { deepCopy } from '../../utils/assist';
  
2cb8a6d9   梁灏   commit Table comp...
18
      export default {
0d136465   梁灏   update Table
19
20
          mixins: [ Mixin ],
          components: { Checkbox },
2cb8a6d9   梁灏   commit Table comp...
21
22
          props: {
              prefixCls: String,
0d136465   梁灏   update Table
23
24
              columns: Array,
              cloneData: Array
2cb8a6d9   梁灏   commit Table comp...
25
26
27
28
29
30
31
          },
          data () {
              return {
              
              }
          },
          computed: {
0d136465   梁灏   update Table
32
33
34
              isSelectAll () {
                  return !this.cloneData.some(data => !data._isChecked);
              }
2cb8a6d9   梁灏   commit Table comp...
35
36
37
38
39
40
41
42
          },
          methods: {
              renderHeader (column, $index) {
                  if ('renderHeader' in this.columns[$index]) {
                      return this.columns[$index].renderHeader(column, $index);
                  } else {
                      return column.title || '#';
                  }
744eb0af   梁灏   update Table comp...
43
              },
0d136465   梁灏   update Table
44
45
46
47
48
49
50
51
52
53
54
55
              selectAll () {
                  const status = !this.isSelectAll;
  
                  let tmpData = deepCopy(this.cloneData);
                  tmpData.forEach((data) => {
                      data._isChecked = status;
                  });
                  this.cloneData = tmpData;
  
                  if (status) {
                      this.$parent.selectAll();
                  }
2cb8a6d9   梁灏   commit Table comp...
56
57
58
59
              }
          }
      }
  </script>