Blame view

src/components/table/table-head.vue 5.6 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
7f34c510   梁灏   update Table
2
3
4
5
6
7
8
      <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)">
c6f21c2f   jingsam   :bug: fix ie bug
9
                      <div :class="cellClasses(column)">
7f34c510   梁灏   update Table
10
                          <template v-if="column.type === 'selection'"><Checkbox :checked="isSelectAll" @on-change="selectAll"></Checkbox></template>
52874e27   梁灏   update Table
11
12
13
                          <template v-else>
                              {{{ renderHeader(column, $index) }}}
                              <span :class="[prefixCls + '-sort']" v-if="column.sortable">
35ad3764   梁灏   update Table
14
15
                                  <i class="ivu-icon ivu-icon-arrow-up-b" :class="{on: column._sortType === 'asc'}" @click="handleSort($index, 'asc')"></i>
                                  <i class="ivu-icon ivu-icon-arrow-down-b" :class="{on: column._sortType === 'desc'}" @click="handleSort($index, 'desc')"></i>
52874e27   梁灏   update Table
16
                              </span>
adaeca88   梁灏   update Table
17
18
19
20
21
                              <Poptip
                                  v-if="column.filters && (fixed || (!fixed && !column.fixed))"
                                  :visible.sync="column._filterVisible"
                                  placement="bottom"
                                  @on-popper-hide="handleFilterHide($index)">
642299b9   梁灏   update Table
22
                                  <span :class="[prefixCls + '-filter']">
99f80db0   梁灏   update Table
23
                                      <i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
642299b9   梁灏   update Table
24
                                  </span>
adaeca88   梁灏   update Table
25
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
99f80db0   梁灏   update Table
26
27
28
29
30
                                      <div :class="[prefixCls + '-filter-list-item']">
                                          <checkbox-group :model.sync="column._filterChecked">
                                              <checkbox v-for="item in column.filters" :value="item.value">{{ item.label }}</checkbox>
                                          </checkbox-group>
                                      </div>
99f80db0   梁灏   update Table
31
                                      <div :class="[prefixCls + '-filter-footer']">
adaeca88   梁灏   update Table
32
                                          <i-button type="text" size="small" :disabled="!column._filterChecked.length" @click="handleFilter($index)">筛选</i-button>
99f80db0   梁灏   update Table
33
34
                                          <i-button type="text" size="small" @click="handleReset($index)">重置</i-button>
                                      </div>
642299b9   梁灏   update Table
35
                                  </div>
adaeca88   梁灏   update Table
36
37
38
39
40
41
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
                                      <ul>
                                          <li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: !column._filterChecked.lengtg}]">全部</li>
                                          <li :class="[prefixCls + '-filter-select-item', {[prefixCls + '-filter-select-item-selected']: column._filterChecked[0] === item.value}]" v-for="item in column.filters">{{ item.label }}</li>
                                      </ul>
                                  </div>
642299b9   梁灏   update Table
42
                              </Poptip>
52874e27   梁灏   update Table
43
                          </template>
7f34c510   梁灏   update Table
44
45
46
47
48
                      </div>
                  </th>
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
49
50
  </template>
  <script>
99f80db0   梁灏   update Table
51
      import CheckboxGroup from '../checkbox/checkbox-group.vue';
0d136465   梁灏   update Table
52
      import Checkbox from '../checkbox/checkbox.vue';
642299b9   梁灏   update Table
53
      import Poptip from '../poptip/poptip.vue';
99f80db0   梁灏   update Table
54
      import iButton from '../button/button.vue';
0d136465   梁灏   update Table
55
56
57
      import Mixin from './mixin';
      import { deepCopy } from '../../utils/assist';
  
2cb8a6d9   梁灏   commit Table comp...
58
      export default {
0d136465   梁灏   update Table
59
          mixins: [ Mixin ],
99f80db0   梁灏   update Table
60
          components: { CheckboxGroup, Checkbox, Poptip, iButton },
2cb8a6d9   梁灏   commit Table comp...
61
62
          props: {
              prefixCls: String,
7f34c510   梁灏   update Table
63
              style: Object,
0d136465   梁灏   update Table
64
              columns: Array,
d3dfdb26   梁灏   update Table
65
              objData: Object,
7f34c510   梁灏   update Table
66
              fixed: Boolean
2cb8a6d9   梁灏   commit Table comp...
67
          },
2cb8a6d9   梁灏   commit Table comp...
68
          computed: {
0d136465   梁灏   update Table
69
              isSelectAll () {
d3dfdb26   梁灏   update Table
70
71
72
73
74
75
                  let isSelectAll = true;
                  for (let i in this.objData) {
                      if (!this.objData[i]._isChecked) isSelectAll = false;
                  }
  
                  return isSelectAll;
0d136465   梁灏   update Table
76
              }
2cb8a6d9   梁灏   commit Table comp...
77
78
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
79
80
81
82
83
84
85
86
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
                  ]
              },
7f34c510   梁灏   update Table
87
88
89
              setCellWidth (column, index) {
                  return this.$parent.setCellWidth(column, index);
              },
2cb8a6d9   梁灏   commit Table comp...
90
91
92
93
94
95
              renderHeader (column, $index) {
                  if ('renderHeader' in this.columns[$index]) {
                      return this.columns[$index].renderHeader(column, $index);
                  } else {
                      return column.title || '#';
                  }
744eb0af   梁灏   update Table comp...
96
              },
0d136465   梁灏   update Table
97
98
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
99
                  this.$parent.selectAll(status);
52874e27   梁灏   update Table
100
              },
35ad3764   梁灏   update Table
101
102
103
              handleSort (index, type) {
                  if (this.columns[index]._sortType === type) {
                      type = 'normal';
741b987a   梁灏   update Table
104
                  }
35ad3764   梁灏   update Table
105
                  this.$parent.handleSort(index, type);
642299b9   梁灏   update Table
106
107
              },
              handleFilter (index) {
adaeca88   梁灏   update Table
108
                  this.$parent.handleFilter(index);
99f80db0   梁灏   update Table
109
110
              },
              handleReset (index) {
adaeca88   梁灏   update Table
111
                  this.$parent.handleFilterReset(index);
99f80db0   梁灏   update Table
112
              },
adaeca88   梁灏   update Table
113
114
              handleFilterHide (index) {
                  this.$parent.handleFilterHide(index);
2cb8a6d9   梁灏   commit Table comp...
115
116
117
              }
          }
      }
c6f21c2f   jingsam   :bug: fix ie bug
118
  </script>