Blame view

src/components/table/table-body.vue 4.14 KB
2cb8a6d9   梁灏   commit Table comp...
1
  <template>
486d4fda   梁灏   update Table
2
      <table cellspacing="0" cellpadding="0" border="0" :style="styleObject">
7f34c510   梁灏   update Table
3
          <colgroup>
486d4fda   梁灏   update Table
4
              <col v-for="(column, index) in columns" :width="setCellWidth(column, index, false)">
7f34c510   梁灏   update Table
5
6
          </colgroup>
          <tbody :class="[prefixCls + '-tbody']">
08fd628d   Aresn   Table support expand
7
8
              <template v-for="(row, index) in data">
                  <tr
08fd628d   Aresn   Table support expand
9
10
11
12
13
14
15
16
17
18
                      :class="rowClasses(row._index)"
                      @mouseenter.stop="handleMouseIn(row._index)"
                      @mouseleave.stop="handleMouseOut(row._index)"
                      @click.stop="clickCurrentRow(row._index)"
                      @dblclick.stop="dblclickCurrentRow(row._index)">
                      <td v-for="column in columns" :class="alignCls(column, row)">
                          <Cell
                              :fixed="fixed"
                              :prefix-cls="prefixCls"
                              :row="row"
4098c176   Aresn   update Table
19
                              :key="row"
08fd628d   Aresn   Table support expand
20
21
22
23
24
25
                              :column="column"
                              :natural-index="index"
                              :index="row._index"
                              :checked="rowChecked(row._index)"
                              :disabled="rowDisabled(row._index)"
                              :expanded="rowExpanded(row._index)"
0dcc9482   leonine   itable 添加禁用某行选中的功能
26
                          ></Cell>
08fd628d   Aresn   Table support expand
27
28
29
                      </td>
                  </tr>
                  <tr v-if="rowExpanded(row._index)">
367a4196   Aresn   update Table
30
                      <td :colspan="columns.length" :class="prefixCls + '-expanded-cell'">
4098c176   Aresn   update Table
31
                          <Expand :key="row" :row="row" :render="expandRender" :index="row._index"></Expand>
08fd628d   Aresn   Table support expand
32
33
34
                      </td>
                  </tr>
              </template>
7f34c510   梁灏   update Table
35
          </tbody>
3ef4dfb9   梁灏   update Table
36
      </table>
2cb8a6d9   梁灏   commit Table comp...
37
38
  </template>
  <script>
6cadeba4   梁灏   support Message
39
      // todo :key="row"
7f34c510   梁灏   update Table
40
      import Cell from './cell.vue';
718e773f   刘荣   -
41
      import Expand from './expand.js';
7f34c510   梁灏   update Table
42
43
      import Mixin from './mixin';
  
2cb8a6d9   梁灏   commit Table comp...
44
      export default {
486d4fda   梁灏   update Table
45
          name: 'TableBody',
7f34c510   梁灏   update Table
46
          mixins: [ Mixin ],
08fd628d   Aresn   Table support expand
47
          components: { Cell, Expand },
2cb8a6d9   梁灏   commit Table comp...
48
          props: {
7f34c510   梁灏   update Table
49
              prefixCls: String,
486d4fda   梁灏   update Table
50
              styleObject: Object,
7f34c510   梁灏   update Table
51
              columns: Array,
741b987a   梁灏   update Table
52
              data: Array,    // rebuildData
741b987a   梁灏   update Table
53
              objData: Object,
224a3ae5   梁灏   publish 0.9.9-rc-3
54
              columnsWidth: Object,
5d0499ce   梁灏   update Table
55
56
57
58
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
2cb8a6d9   梁灏   commit Table comp...
59
          },
08fd628d   Aresn   Table support expand
60
61
62
63
64
65
66
67
68
69
70
71
72
73
          computed: {
              expandRender () {
                  let render = function () {
                      return '';
                  };
                  for (let i = 0; i < this.columns.length; i++) {
                      const column = this.columns[i];
                      if (column.type && column.type === 'expand') {
                          if (column.render) render = column.render;
                      }
                  }
                  return render;
              }
          },
2cb8a6d9   梁灏   commit Table comp...
74
          methods: {
d3dfdb26   梁灏   update Table
75
              rowClasses (_index) {
c6f21c2f   jingsam   :bug: fix ie bug
76
77
                  return [
                      `${this.prefixCls}-row`,
741b987a   梁灏   update Table
78
                      this.rowClsName(_index),
c6f21c2f   jingsam   :bug: fix ie bug
79
                      {
97edb2eb   梁灏   update Table
80
                          [`${this.prefixCls}-row-highlight`]: this.objData[_index] && this.objData[_index]._isHighlight,
87379c82   leonine   去掉禁用行的 tr>td 的dis...
81
                          [`${this.prefixCls}-row-hover`]: this.objData[_index] && this.objData[_index]._isHover
c6f21c2f   jingsam   :bug: fix ie bug
82
                      }
b0893113   jingsam   :art: add eslint
83
                  ];
c6f21c2f   jingsam   :bug: fix ie bug
84
              },
d3dfdb26   梁灏   update Table
85
              rowChecked (_index) {
97edb2eb   梁灏   update Table
86
                  return this.objData[_index] && this.objData[_index]._isChecked;
741b987a   梁灏   update Table
87
              },
0dcc9482   leonine   itable 添加禁用某行选中的功能
88
89
90
              rowDisabled(_index){
                  return this.objData[_index] && this.objData[_index]._isDisabled;
              },
08fd628d   Aresn   Table support expand
91
92
93
              rowExpanded(_index){
                  return this.objData[_index] && this.objData[_index]._isExpanded;
              },
d3dfdb26   梁灏   update Table
94
95
              rowClsName (_index) {
                  return this.$parent.rowClassName(this.objData[_index], _index);
7f34c510   梁灏   update Table
96
              },
d3dfdb26   梁灏   update Table
97
98
              handleMouseIn (_index) {
                  this.$parent.handleMouseIn(_index);
7f34c510   梁灏   update Table
99
              },
d3dfdb26   梁灏   update Table
100
101
              handleMouseOut (_index) {
                  this.$parent.handleMouseOut(_index);
7f34c510   梁灏   update Table
102
              },
da55375f   Rijn   Added click and d...
103
104
105
106
107
              clickCurrentRow (_index) {
                  this.$parent.clickCurrentRow(_index);
              },
              dblclickCurrentRow (_index) {
                  this.$parent.dblclickCurrentRow(_index);
7f34c510   梁灏   update Table
108
              }
2cb8a6d9   梁灏   commit Table comp...
109
          }
b0893113   jingsam   :art: add eslint
110
111
      };
  </script>