Blame view

src/components/table/cell.vue 3.59 KB
a3547c1b   梁灏   update Table
1
  <template>
87a400d8   梁灏   update Table
2
      <div :class="classes" ref="cell">
19c208d3   梁灏   Poptip add prop `...
3
          <template v-if="renderType === 'index'"><span>{{naturalIndex + 1}}</span></template>
3ef4dfb9   梁灏   update Table
4
          <template v-if="renderType === 'selection'">
afea484f   梁灏   fixed #1271
5
              <Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
3ef4dfb9   梁灏   update Table
6
          </template>
b3dbdba9   anykno   impove table rend...
7
8
          <template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template>
          <template v-if="renderType === 'normal'"><span>{{row[column.key]}}</span></template>
e4e8711d   Aresn   Table support dis...
9
          <template v-if="renderType === 'expand' && !row._disableExpand">
08fd628d   Aresn   Table support expand
10
              <div :class="expandCls" @click="toggleExpand">
021bbec2   梁灏   update Table Icons
11
                  <Icon type="ios-arrow-forward"></Icon>
08fd628d   Aresn   Table support expand
12
13
              </div>
          </template>
4098c176   Aresn   update Table
14
15
16
17
18
19
          <Cell
              v-if="renderType === 'render'"
              :row="row"
              :column="column"
              :index="index"
              :render="column.render"></Cell>
a3547c1b   梁灏   update Table
20
21
22
      </div>
  </template>
  <script>
4098c176   Aresn   update Table
23
      import Cell from './expand';
08fd628d   Aresn   Table support expand
24
      import Icon from '../icon/icon.vue';
3ef4dfb9   梁灏   update Table
25
      import Checkbox from '../checkbox/checkbox.vue';
3ef4dfb9   梁灏   update Table
26
  
a3547c1b   梁灏   update Table
27
      export default {
486d4fda   梁灏   update Table
28
          name: 'TableCell',
4098c176   Aresn   update Table
29
          components: { Icon, Checkbox, Cell },
a3547c1b   梁灏   update Table
30
31
32
33
          props: {
              prefixCls: String,
              row: Object,
              column: Object,
741b987a   梁灏   update Table
34
35
              naturalIndex: Number,    // index of rebuildData
              index: Number,           // _index of data
7f34c510   梁灏   update Table
36
              checked: Boolean,
87379c82   leonine   去掉禁用行的 tr>td 的dis...
37
              disabled: Boolean,
08fd628d   Aresn   Table support expand
38
              expanded: Boolean,
5d0499ce   梁灏   update Table
39
40
41
42
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
a3547c1b   梁灏   update Table
43
44
45
46
          },
          data () {
              return {
                  renderType: '',
d0e206c5   梁灏   Table add content...
47
                  uid: -1,
e40c5352   Aresn   fixed #1195
48
                  context: this.$parent.$parent.$parent.currentContext
b0893113   jingsam   :art: add eslint
49
              };
a3547c1b   梁灏   update Table
50
          },
3ef4dfb9   梁灏   update Table
51
52
53
54
55
          computed: {
              classes () {
                  return [
                      `${this.prefixCls}-cell`,
                      {
eedcba58   Rijn   Added ellipsis pr...
56
                          [`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
08fd628d   Aresn   Table support expand
57
                          [`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false,
fc3e16cf   梁灏   update Table sele...
58
59
                          [`${this.prefixCls}-cell-with-expand`]: this.renderType === 'expand',
                          [`${this.prefixCls}-cell-with-selection`]: this.renderType === 'selection'
3ef4dfb9   梁灏   update Table
60
                      }
b0893113   jingsam   :art: add eslint
61
                  ];
08fd628d   Aresn   Table support expand
62
63
64
65
66
67
68
              },
              expandCls () {
                  return [
                      `${this.prefixCls}-cell-expand`,
                      {
                          [`${this.prefixCls}-cell-expand-expanded`]: this.expanded
                      }
af6e81cd   Aresn   update Table
69
                  ];
3ef4dfb9   梁灏   update Table
70
71
              }
          },
a3547c1b   梁灏   update Table
72
          methods: {
741b987a   梁灏   update Table
73
              toggleSelect () {
e40c5352   Aresn   fixed #1195
74
                  this.$parent.$parent.$parent.toggleSelect(this.index);
08fd628d   Aresn   Table support expand
75
76
              },
              toggleExpand () {
e40c5352   Aresn   fixed #1195
77
                  this.$parent.$parent.$parent.toggleExpand(this.index);
afea484f   梁灏   fixed #1271
78
79
80
              },
              handleClick () {
                  // 放置 Checkbox 冒泡
a3547c1b   梁灏   update Table
81
82
              }
          },
486d4fda   梁灏   update Table
83
          created () {
a3547c1b   梁灏   update Table
84
85
              if (this.column.type === 'index') {
                  this.renderType = 'index';
3ef4dfb9   梁灏   update Table
86
87
              } else if (this.column.type === 'selection') {
                  this.renderType = 'selection';
b3dbdba9   anykno   impove table rend...
88
89
              } else if (this.column.type === 'html') {
                  this.renderType = 'html';
08fd628d   Aresn   Table support expand
90
91
              } else if (this.column.type === 'expand') {
                  this.renderType = 'expand';
a3547c1b   梁灏   update Table
92
93
94
95
96
              } else if (this.column.render) {
                  this.renderType = 'render';
              } else {
                  this.renderType = 'normal';
              }
a3547c1b   梁灏   update Table
97
          }
b0893113   jingsam   :art: add eslint
98
99
      };
  </script>