Blame view

src/components/table/table-head.vue 7.73 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
a404bbae   梁灏   update Table #167
2
      <table cellspacing="0" cellpadding="0" border="0" :style="styles">
7f34c510   梁灏   update Table
3
          <colgroup>
486d4fda   梁灏   update Table
4
              <col v-for="(column, index) in columns" :width="setCellWidth(column, index, true)">
7f34c510   梁灏   update Table
5
6
7
          </colgroup>
          <thead>
              <tr>
486d4fda   梁灏   update Table
8
                  <th v-for="(column, index) in columns" :class="alignCls(column)">
c6f21c2f   jingsam   :bug: fix ie bug
9
                      <div :class="cellClasses(column)">
08fd628d   Aresn   Table support expand
10
11
                          <template v-if="column.type === 'expand'"></template>
                          <template v-else-if="column.type === 'selection'"><Checkbox :value="isSelectAll" @on-change="selectAll"></Checkbox></template>
52874e27   梁灏   update Table
12
                          <template v-else>
1b737fdc   梁灏   fixed #122
13
                              <span v-if="!column.renderHeader" @click="handleSortByHead(index)">{{ column.title || '#' }}</span>
096f2bfe   梁灏   fixed #1357
14
                              <render-header v-else :render="column.renderHeader" :column="column" :index="index"></render-header>
52874e27   梁灏   update Table
15
                              <span :class="[prefixCls + '-sort']" v-if="column.sortable">
486d4fda   梁灏   update Table
16
17
                                  <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
18
                              </span>
adaeca88   梁灏   update Table
19
                              <Poptip
5d0499ce   梁灏   update Table
20
                                  v-if="isPopperShow(column)"
644c37b3   梁灏   update License
21
                                  v-model="column._filterVisible"
adaeca88   梁灏   update Table
22
                                  placement="bottom"
486d4fda   梁灏   update Table
23
                                  @on-popper-hide="handleFilterHide(index)">
642299b9   梁灏   update Table
24
                                  <span :class="[prefixCls + '-filter']">
99f80db0   梁灏   update Table
25
                                      <i class="ivu-icon ivu-icon-funnel" :class="{on: column._isFiltered}"></i>
642299b9   梁灏   update Table
26
                                  </span>
adaeca88   梁灏   update Table
27
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-if="column._filterMultiple">
99f80db0   梁灏   update Table
28
                                      <div :class="[prefixCls + '-filter-list-item']">
486d4fda   梁灏   update Table
29
                                          <checkbox-group v-model="column._filterChecked">
68b308ee   梁灏   fixex #1353
30
                                              <checkbox v-for="item in column.filters" :key="column._columnKey" :label="item.value">{{ item.label }}</checkbox>
99f80db0   梁灏   update Table
31
32
                                          </checkbox-group>
                                      </div>
99f80db0   梁灏   update Table
33
                                      <div :class="[prefixCls + '-filter-footer']">
486d4fda   梁灏   update Table
34
35
                                          <i-button type="text" size="small" :disabled="!column._filterChecked.length" @click.native="handleFilter(index)">{{ t('i.table.confirmFilter') }}</i-button>
                                          <i-button type="text" size="small" @click.native="handleReset(index)">{{ t('i.table.resetFilter') }}</i-button>
99f80db0   梁灏   update Table
36
                                      </div>
642299b9   梁灏   update Table
37
                                  </div>
adaeca88   梁灏   update Table
38
                                  <div slot="content" :class="[prefixCls + '-filter-list']" v-else>
d0e206c5   梁灏   Table add content...
39
                                      <ul :class="[prefixCls + '-filter-list-single']">
45e7ed7e   梁灏   update Table
40
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
41
                                              :class="itemAllClasses(column)"
486d4fda   梁灏   update Table
42
                                              @click="handleReset(index)">{{ t('i.table.clearFilter') }}</li>
45e7ed7e   梁灏   update Table
43
                                          <li
89670198   梁灏   publish 0.9.9-rc-5
44
                                              :class="itemClasses(column, item)"
45e7ed7e   梁灏   update Table
45
46
                                              v-for="item in column.filters"
                                              @click="handleSelect(index, item.value)">{{ item.label }}</li>
adaeca88   梁灏   update Table
47
48
                                      </ul>
                                  </div>
642299b9   梁灏   update Table
49
                              </Poptip>
52874e27   梁灏   update Table
50
                          </template>
7f34c510   梁灏   update Table
51
52
53
54
55
                      </div>
                  </th>
              </tr>
          </thead>
      </table>
2cb8a6d9   梁灏   commit Table comp...
56
57
  </template>
  <script>
99f80db0   梁灏   update Table
58
      import CheckboxGroup from '../checkbox/checkbox-group.vue';
0d136465   梁灏   update Table
59
      import Checkbox from '../checkbox/checkbox.vue';
642299b9   梁灏   update Table
60
      import Poptip from '../poptip/poptip.vue';
99f80db0   梁灏   update Table
61
      import iButton from '../button/button.vue';
096f2bfe   梁灏   fixed #1357
62
      import renderHeader from './header';
0d136465   梁灏   update Table
63
      import Mixin from './mixin';
4ab11811   梁灏   some component su...
64
      import Locale from '../../mixins/locale';
0d136465   梁灏   update Table
65
  
2cb8a6d9   梁灏   commit Table comp...
66
      export default {
486d4fda   梁灏   update Table
67
          name: 'TableHead',
4ab11811   梁灏   some component su...
68
          mixins: [ Mixin, Locale ],
096f2bfe   梁灏   fixed #1357
69
          components: { CheckboxGroup, Checkbox, Poptip, iButton, renderHeader },
2cb8a6d9   梁灏   commit Table comp...
70
71
          props: {
              prefixCls: String,
486d4fda   梁灏   update Table
72
              styleObject: Object,
0d136465   梁灏   update Table
73
              columns: Array,
d3dfdb26   梁灏   update Table
74
              objData: Object,
6c99b9fe   梁灏   update Table
75
              data: Array,    // rebuildData
224a3ae5   梁灏   publish 0.9.9-rc-3
76
              columnsWidth: Object,
5d0499ce   梁灏   update Table
77
78
79
80
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
2cb8a6d9   梁灏   commit Table comp...
81
          },
2cb8a6d9   梁灏   commit Table comp...
82
          computed: {
a404bbae   梁灏   update Table #167
83
              styles () {
486d4fda   梁灏   update Table
84
85
                  const style = Object.assign({}, this.styleObject);
                  const width = this.$parent.bodyHeight === 0 ? parseInt(this.styleObject.width) : parseInt(this.styleObject.width) + this.$parent.scrollBarWidth;
a404bbae   梁灏   update Table #167
86
87
88
                  style.width = `${width}px`;
                  return style;
              },
0d136465   梁灏   update Table
89
              isSelectAll () {
d3dfdb26   梁灏   update Table
90
                  let isSelectAll = true;
63e0444e   梁灏   fixed #142
91
                  if (!this.data.length) isSelectAll = false;
6c99b9fe   梁灏   update Table
92
                  for (let i = 0; i < this.data.length; i++) {
cd85c675   leonine   修改_checked=true 时...
93
                      if (!this.objData[this.data[i]._index]._isChecked && !this.objData[this.data[i]._index]._isDisabled) {
6c99b9fe   梁灏   update Table
94
95
96
                          isSelectAll = false;
                          break;
                      }
d3dfdb26   梁灏   update Table
97
98
                  }
  
cd85c675   leonine   修改_checked=true 时...
99
                  return isSelectAll;
0d136465   梁灏   update Table
100
              }
2cb8a6d9   梁灏   commit Table comp...
101
102
          },
          methods: {
c6f21c2f   jingsam   :bug: fix ie bug
103
104
105
106
107
108
              cellClasses (column) {
                  return [
                      `${this.prefixCls}-cell`,
                      {
                          [`${this.prefixCls}-hidden`]: !this.fixed && column.fixed && (column.fixed === 'left' || column.fixed === 'right')
                      }
b0893113   jingsam   :art: add eslint
109
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
110
              },
89670198   梁灏   publish 0.9.9-rc-5
111
112
113
114
115
116
              itemClasses (column, item) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: column._filterChecked[0] === item.value
                      }
b0893113   jingsam   :art: add eslint
117
                  ];
89670198   梁灏   publish 0.9.9-rc-5
118
119
120
121
122
123
124
              },
              itemAllClasses (column) {
                  return [
                      `${this.prefixCls}-filter-select-item`,
                      {
                          [`${this.prefixCls}-filter-select-item-selected`]: !column._filterChecked.length
                      }
b0893113   jingsam   :art: add eslint
125
                  ];
89670198   梁灏   publish 0.9.9-rc-5
126
              },
0d136465   梁灏   update Table
127
128
              selectAll () {
                  const status = !this.isSelectAll;
3d9e4f20   梁灏   update Table
129
                  this.$parent.selectAll(status);
52874e27   梁灏   update Table
130
              },
35ad3764   梁灏   update Table
131
132
133
              handleSort (index, type) {
                  if (this.columns[index]._sortType === type) {
                      type = 'normal';
741b987a   梁灏   update Table
134
                  }
35ad3764   梁灏   update Table
135
                  this.$parent.handleSort(index, type);
642299b9   梁灏   update Table
136
              },
1b737fdc   梁灏   fixed #122
137
138
139
140
141
142
143
144
145
146
147
148
149
              handleSortByHead (index) {
                  const column = this.columns[index];
                  if (column.sortable) {
                      const type = column._sortType;
                      if (type === 'normal') {
                          this.handleSort(index, 'asc');
                      } else if (type === 'asc') {
                          this.handleSort(index, 'desc');
                      } else {
                          this.handleSort(index, 'normal');
                      }
                  }
              },
642299b9   梁灏   update Table
150
              handleFilter (index) {
adaeca88   梁灏   update Table
151
                  this.$parent.handleFilter(index);
99f80db0   梁灏   update Table
152
              },
45e7ed7e   梁灏   update Table
153
154
155
              handleSelect (index, value) {
                  this.$parent.handleFilterSelect(index, value);
              },
99f80db0   梁灏   update Table
156
              handleReset (index) {
adaeca88   梁灏   update Table
157
                  this.$parent.handleFilterReset(index);
99f80db0   梁灏   update Table
158
              },
adaeca88   梁灏   update Table
159
160
              handleFilterHide (index) {
                  this.$parent.handleFilterHide(index);
2cb8a6d9   梁灏   commit Table comp...
161
162
              }
          }
b0893113   jingsam   :art: add eslint
163
164
      };
  </script>