Blame view

src/components/table/cell.vue 4.85 KB
a3547c1b   梁灏   update Table
1
  <template>
87a400d8   梁灏   update Table
2
      <div :class="classes" ref="cell">
d9d1dbbd   梁灏   Table Column add ...
3
          <template v-if="renderType === 'index'"><span>{{ column.indexMethod ? column.indexMethod(row) : (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
          <template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template>
8c51d57d   梁灏   Table Column add ...
8
9
          <template v-if="renderType === 'normal'">
              <template v-if="column.tooltip">
847c0d43   梁灏   fixed #4158
10
                  <Tooltip transfer :content="row[column.key]" :theme="tableRoot.tooltipTheme" :disabled="!showTooltip" :max-width="300" class="ivu-table-cell-tooltip">
8c51d57d   梁灏   Table Column add ...
11
12
13
14
15
                      <span ref="content" @mouseenter="handleTooltipIn" @mouseleave="handleTooltipOut" class="ivu-table-cell-tooltip-content">{{ row[column.key] }}</span>
                  </Tooltip>
              </template>
              <span v-else>{{row[column.key]}}</span>
          </template>
e4e8711d   Aresn   Table support dis...
16
          <template v-if="renderType === 'expand' && !row._disableExpand">
08fd628d   Aresn   Table support expand
17
              <div :class="expandCls" @click="toggleExpand">
021bbec2   梁灏   update Table Icons
18
                  <Icon type="ios-arrow-forward"></Icon>
08fd628d   Aresn   Table support expand
19
20
              </div>
          </template>
b55f59c6   Rookie_Zoe   fix #4258
21
          <table-expand
4098c176   Aresn   update Table
22
23
24
25
              v-if="renderType === 'render'"
              :row="row"
              :column="column"
              :index="index"
b55f59c6   Rookie_Zoe   fix #4258
26
              :render="column.render"></table-expand>
8135a8c3   梁灏   init
27
28
29
30
31
          <table-slot
              v-if="renderType === 'slot'"
              :row="row"
              :column="column"
              :index="index"></table-slot>
a3547c1b   梁灏   update Table
32
33
34
      </div>
  </template>
  <script>
b55f59c6   Rookie_Zoe   fix #4258
35
      import TableExpand from './expand';
8135a8c3   梁灏   init
36
      import TableSlot from './slot';
08fd628d   Aresn   Table support expand
37
      import Icon from '../icon/icon.vue';
3ef4dfb9   梁灏   update Table
38
      import Checkbox from '../checkbox/checkbox.vue';
8c51d57d   梁灏   Table Column add ...
39
      import Tooltip from '../tooltip/tooltip.vue';
3ef4dfb9   梁灏   update Table
40
  
a3547c1b   梁灏   update Table
41
      export default {
486d4fda   梁灏   update Table
42
          name: 'TableCell',
8135a8c3   梁灏   init
43
          components: { Icon, Checkbox, TableExpand, TableSlot, Tooltip },
847c0d43   梁灏   fixed #4158
44
          inject: ['tableRoot'],
a3547c1b   梁灏   update Table
45
46
47
48
          props: {
              prefixCls: String,
              row: Object,
              column: Object,
741b987a   梁灏   update Table
49
50
              naturalIndex: Number,    // index of rebuildData
              index: Number,           // _index of data
7f34c510   梁灏   update Table
51
              checked: Boolean,
87379c82   leonine   去掉禁用行的 tr>td 的dis...
52
              disabled: Boolean,
08fd628d   Aresn   Table support expand
53
              expanded: Boolean,
5d0499ce   梁灏   update Table
54
55
56
57
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
a3547c1b   梁灏   update Table
58
59
60
61
          },
          data () {
              return {
                  renderType: '',
d0e206c5   梁灏   Table add content...
62
                  uid: -1,
8c51d57d   梁灏   Table Column add ...
63
64
                  context: this.$parent.$parent.$parent.currentContext,
                  showTooltip: false,  // 鼠标滑过overflow文本时,再检查是否需要显示
b0893113   jingsam   :art: add eslint
65
              };
a3547c1b   梁灏   update Table
66
          },
3ef4dfb9   梁灏   update Table
67
68
69
70
71
          computed: {
              classes () {
                  return [
                      `${this.prefixCls}-cell`,
                      {
eedcba58   Rijn   Added ellipsis pr...
72
                          [`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
08fd628d   Aresn   Table support expand
73
                          [`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false,
fc3e16cf   梁灏   update Table sele...
74
75
                          [`${this.prefixCls}-cell-with-expand`]: this.renderType === 'expand',
                          [`${this.prefixCls}-cell-with-selection`]: this.renderType === 'selection'
3ef4dfb9   梁灏   update Table
76
                      }
b0893113   jingsam   :art: add eslint
77
                  ];
08fd628d   Aresn   Table support expand
78
79
80
81
82
83
84
              },
              expandCls () {
                  return [
                      `${this.prefixCls}-cell-expand`,
                      {
                          [`${this.prefixCls}-cell-expand-expanded`]: this.expanded
                      }
af6e81cd   Aresn   update Table
85
                  ];
3ef4dfb9   梁灏   update Table
86
87
              }
          },
a3547c1b   梁灏   update Table
88
          methods: {
741b987a   梁灏   update Table
89
              toggleSelect () {
e40c5352   Aresn   fixed #1195
90
                  this.$parent.$parent.$parent.toggleSelect(this.index);
08fd628d   Aresn   Table support expand
91
92
              },
              toggleExpand () {
e40c5352   Aresn   fixed #1195
93
                  this.$parent.$parent.$parent.toggleExpand(this.index);
afea484f   梁灏   fixed #1271
94
95
96
              },
              handleClick () {
                  // 放置 Checkbox 冒泡
8c51d57d   梁灏   Table Column add ...
97
98
99
100
101
102
103
              },
              handleTooltipIn () {
                  const $content = this.$refs.content;
                  this.showTooltip = $content.scrollWidth > $content.offsetWidth;
              },
              handleTooltipOut () {
                  this.showTooltip = false;
a3547c1b   梁灏   update Table
104
105
              }
          },
486d4fda   梁灏   update Table
106
          created () {
a3547c1b   梁灏   update Table
107
108
              if (this.column.type === 'index') {
                  this.renderType = 'index';
3ef4dfb9   梁灏   update Table
109
110
              } else if (this.column.type === 'selection') {
                  this.renderType = 'selection';
b3dbdba9   anykno   impove table rend...
111
112
              } else if (this.column.type === 'html') {
                  this.renderType = 'html';
08fd628d   Aresn   Table support expand
113
114
              } else if (this.column.type === 'expand') {
                  this.renderType = 'expand';
a3547c1b   梁灏   update Table
115
116
              } else if (this.column.render) {
                  this.renderType = 'render';
8135a8c3   梁灏   init
117
118
              } else if (this.column.slot) {
                  this.renderType = 'slot';
a3547c1b   梁灏   update Table
119
120
121
              } else {
                  this.renderType = 'normal';
              }
a3547c1b   梁灏   update Table
122
          }
b0893113   jingsam   :art: add eslint
123
124
      };
  </script>