Blame view

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