Blame view

src/components/table/cell.vue 4.79 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
10
11
12
13
14
15
          <template v-if="renderType === 'normal'">
              <template v-if="column.tooltip">
                  <Tooltip transfer :content="row[column.key]" :disabled="!showTooltip" :max-width="300" class="ivu-table-cell-tooltip">
                      <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 },
a3547c1b   梁灏   update Table
44
45
46
47
          props: {
              prefixCls: String,
              row: Object,
              column: Object,
741b987a   梁灏   update Table
48
49
              naturalIndex: Number,    // index of rebuildData
              index: Number,           // _index of data
7f34c510   梁灏   update Table
50
              checked: Boolean,
87379c82   leonine   去掉禁用行的 tr>td 的dis...
51
              disabled: Boolean,
08fd628d   Aresn   Table support expand
52
              expanded: Boolean,
5d0499ce   梁灏   update Table
53
54
55
56
              fixed: {
                  type: [Boolean, String],
                  default: false
              }
a3547c1b   梁灏   update Table
57
58
59
60
          },
          data () {
              return {
                  renderType: '',
d0e206c5   梁灏   Table add content...
61
                  uid: -1,
8c51d57d   梁灏   Table Column add ...
62
63
                  context: this.$parent.$parent.$parent.currentContext,
                  showTooltip: false,  // 鼠标滑过overflow文本时,再检查是否需要显示
b0893113   jingsam   :art: add eslint
64
              };
a3547c1b   梁灏   update Table
65
          },
3ef4dfb9   梁灏   update Table
66
67
68
69
70
          computed: {
              classes () {
                  return [
                      `${this.prefixCls}-cell`,
                      {
eedcba58   Rijn   Added ellipsis pr...
71
                          [`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
08fd628d   Aresn   Table support expand
72
                          [`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false,
fc3e16cf   梁灏   update Table sele...
73
74
                          [`${this.prefixCls}-cell-with-expand`]: this.renderType === 'expand',
                          [`${this.prefixCls}-cell-with-selection`]: this.renderType === 'selection'
3ef4dfb9   梁灏   update Table
75
                      }
b0893113   jingsam   :art: add eslint
76
                  ];
08fd628d   Aresn   Table support expand
77
78
79
80
81
82
83
              },
              expandCls () {
                  return [
                      `${this.prefixCls}-cell-expand`,
                      {
                          [`${this.prefixCls}-cell-expand-expanded`]: this.expanded
                      }
af6e81cd   Aresn   update Table
84
                  ];
3ef4dfb9   梁灏   update Table
85
86
              }
          },
a3547c1b   梁灏   update Table
87
          methods: {
741b987a   梁灏   update Table
88
              toggleSelect () {
e40c5352   Aresn   fixed #1195
89
                  this.$parent.$parent.$parent.toggleSelect(this.index);
08fd628d   Aresn   Table support expand
90
91
              },
              toggleExpand () {
e40c5352   Aresn   fixed #1195
92
                  this.$parent.$parent.$parent.toggleExpand(this.index);
afea484f   梁灏   fixed #1271
93
94
95
              },
              handleClick () {
                  // 放置 Checkbox 冒泡
8c51d57d   梁灏   Table Column add ...
96
97
98
99
100
101
102
              },
              handleTooltipIn () {
                  const $content = this.$refs.content;
                  this.showTooltip = $content.scrollWidth > $content.offsetWidth;
              },
              handleTooltipOut () {
                  this.showTooltip = false;
a3547c1b   梁灏   update Table
103
104
              }
          },
486d4fda   梁灏   update Table
105
          created () {
a3547c1b   梁灏   update Table
106
107
              if (this.column.type === 'index') {
                  this.renderType = 'index';
3ef4dfb9   梁灏   update Table
108
109
              } else if (this.column.type === 'selection') {
                  this.renderType = 'selection';
b3dbdba9   anykno   impove table rend...
110
111
              } else if (this.column.type === 'html') {
                  this.renderType = 'html';
08fd628d   Aresn   Table support expand
112
113
              } else if (this.column.type === 'expand') {
                  this.renderType = 'expand';
a3547c1b   梁灏   update Table
114
115
              } else if (this.column.render) {
                  this.renderType = 'render';
8135a8c3   梁灏   init
116
117
              } else if (this.column.slot) {
                  this.renderType = 'slot';
a3547c1b   梁灏   update Table
118
119
120
              } else {
                  this.renderType = 'normal';
              }
a3547c1b   梁灏   update Table
121
          }
b0893113   jingsam   :art: add eslint
122
123
      };
  </script>