Blame view

src/components/table/table-head.vue 2.23 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
7f34c510   梁灏   update Table
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
      <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>
2cb8a6d9   梁灏   commit Table comp...
17
18
  </template>
  <script>
0d136465   梁灏   update Table
19
20
21
22
      import Checkbox from '../checkbox/checkbox.vue';
      import Mixin from './mixin';
      import { deepCopy } from '../../utils/assist';
  
2cb8a6d9   梁灏   commit Table comp...
23
      export default {
0d136465   梁灏   update Table
24
25
          mixins: [ Mixin ],
          components: { Checkbox },
2cb8a6d9   梁灏   commit Table comp...
26
27
          props: {
              prefixCls: String,
7f34c510   梁灏   update Table
28
              style: Object,
0d136465   梁灏   update Table
29
              columns: Array,
7f34c510   梁灏   update Table
30
31
              cloneData: Array,
              fixed: Boolean
2cb8a6d9   梁灏   commit Table comp...
32
33
          },
          computed: {
0d136465   梁灏   update Table
34
35
36
              isSelectAll () {
                  return !this.cloneData.some(data => !data._isChecked);
              }
2cb8a6d9   梁灏   commit Table comp...
37
38
          },
          methods: {
7f34c510   梁灏   update Table
39
40
41
              setCellWidth (column, index) {
                  return this.$parent.setCellWidth(column, index);
              },
2cb8a6d9   梁灏   commit Table comp...
42
43
44
45
46
47
              renderHeader (column, $index) {
                  if ('renderHeader' in this.columns[$index]) {
                      return this.columns[$index].renderHeader(column, $index);
                  } else {
                      return column.title || '#';
                  }
744eb0af   梁灏   update Table comp...
48
              },
0d136465   梁灏   update Table
49
50
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
51
                  this.$parent.selectAll(status);
0d136465   梁灏   update Table
52
  
3d9e4f20   梁灏   update Table
53
54
55
56
57
58
59
60
61
  //                let tmpData = deepCopy(this.cloneData);
  //                tmpData.forEach((data) => {
  //                    data._isChecked = status;
  //                });
  //                this.cloneData = tmpData;
  //
  //                if (status) {
  //                    this.$parent.selectAll();
  //                }
2cb8a6d9   梁灏   commit Table comp...
62
63
64
65
              }
          }
      }
  </script>