cell.vue
4.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div :class="classes" ref="cell">
<template v-if="renderType === 'index'"><span>{{ column.indexMethod ? column.indexMethod(row) : (naturalIndex + 1) }}</span></template>
<template v-if="renderType === 'selection'">
<Checkbox :value="checked" @click.native.stop="handleClick" @on-change="toggleSelect" :disabled="disabled"></Checkbox>
</template>
<template v-if="renderType === 'html'"><span v-html="row[column.key]"></span></template>
<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>
<template v-if="renderType === 'expand' && !row._disableExpand">
<div :class="expandCls" @click="toggleExpand">
<Icon type="ios-arrow-forward"></Icon>
</div>
</template>
<Cell
v-if="renderType === 'render'"
:row="row"
:column="column"
:index="index"
:render="column.render"></Cell>
</div>
</template>
<script>
import Cell from './expand';
import Icon from '../icon/icon.vue';
import Checkbox from '../checkbox/checkbox.vue';
import Tooltip from '../tooltip/tooltip.vue';
export default {
name: 'TableCell',
components: { Icon, Checkbox, Cell, Tooltip },
props: {
prefixCls: String,
row: Object,
column: Object,
naturalIndex: Number, // index of rebuildData
index: Number, // _index of data
checked: Boolean,
disabled: Boolean,
expanded: Boolean,
fixed: {
type: [Boolean, String],
default: false
}
},
data () {
return {
renderType: '',
uid: -1,
context: this.$parent.$parent.$parent.currentContext,
showTooltip: false, // 鼠标滑过overflow文本时,再检查是否需要显示
};
},
computed: {
classes () {
return [
`${this.prefixCls}-cell`,
{
[`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
[`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false,
[`${this.prefixCls}-cell-with-expand`]: this.renderType === 'expand',
[`${this.prefixCls}-cell-with-selection`]: this.renderType === 'selection'
}
];
},
expandCls () {
return [
`${this.prefixCls}-cell-expand`,
{
[`${this.prefixCls}-cell-expand-expanded`]: this.expanded
}
];
}
},
methods: {
toggleSelect () {
this.$parent.$parent.$parent.toggleSelect(this.index);
},
toggleExpand () {
this.$parent.$parent.$parent.toggleExpand(this.index);
},
handleClick () {
// 放置 Checkbox 冒泡
},
handleTooltipIn () {
const $content = this.$refs.content;
this.showTooltip = $content.scrollWidth > $content.offsetWidth;
},
handleTooltipOut () {
this.showTooltip = false;
}
},
created () {
if (this.column.type === 'index') {
this.renderType = 'index';
} else if (this.column.type === 'selection') {
this.renderType = 'selection';
} else if (this.column.type === 'html') {
this.renderType = 'html';
} else if (this.column.type === 'expand') {
this.renderType = 'expand';
} else if (this.column.render) {
this.renderType = 'render';
} else {
this.renderType = 'normal';
}
}
};
</script>