a3547c1b
梁灏
update Table
|
1
|
<template>
|
3ef4dfb9
梁灏
update Table
|
2
|
<div :class="classes">
|
a3547c1b
梁灏
update Table
|
3
|
<template v-if="renderType === 'index'">{{index + 1}}</template>
|
3ef4dfb9
梁灏
update Table
|
4
5
6
|
<template v-if="renderType === 'selection'">
<Checkbox :checked="checked" @on-change="toggleSelect(index)"></Checkbox>
</template>
|
a3547c1b
梁灏
update Table
|
7
8
9
10
|
<template v-if="renderType === 'normal'">{{{ row[column.key] }}}</template>
</div>
</template>
<script>
|
3ef4dfb9
梁灏
update Table
|
11
12
|
import Checkbox from '../checkbox/checkbox.vue';
|
a3547c1b
梁灏
update Table
|
13
|
export default {
|
3ef4dfb9
梁灏
update Table
|
14
|
components: { Checkbox },
|
a3547c1b
梁灏
update Table
|
15
16
17
18
|
props: {
prefixCls: String,
row: Object,
column: Object,
|
3ef4dfb9
梁灏
update Table
|
19
20
|
index: Number,
checked: Boolean
|
a3547c1b
梁灏
update Table
|
21
22
23
24
25
26
27
|
},
data () {
return {
renderType: '',
uid: -1
}
},
|
3ef4dfb9
梁灏
update Table
|
28
29
30
31
32
33
34
35
36
37
|
computed: {
classes () {
return [
`${this.prefixCls}-cell`,
{
[`${this.prefixCls}-hidden`]: this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right')
}
]
}
},
|
a3547c1b
梁灏
update Table
|
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
methods: {
compile () {
if (this.column.render) {
const template = this.column.render(this.row, this.column, this.index);
const cell = document.createElement('div');
cell.innerHTML = template;
const _oldParentChildLen = this.$parent.$parent.$children.length;
this.$parent.$parent.$compile(cell);
const _newParentChildLen = this.$parent.$parent.$children.length;
if (_oldParentChildLen !== _newParentChildLen) { // if render normal html node, do not tag
this.uid = this.$parent.$parent.$children[this.$parent.$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update
}
this.$el.innerHTML = '';
this.$el.appendChild(cell);
}
},
destroy () {
for (let i = 0; i < this.$parent.$parent.$children.length; i++) {
if (this.$parent.$parent.$children[i]._uid === this.uid) {
this.$parent.$parent.$children[i].$destroy();
}
}
|
3ef4dfb9
梁灏
update Table
|
61
62
63
|
},
toggleSelect (index) {
this.$parent.toggleSelect(index);
|
a3547c1b
梁灏
update Table
|
64
65
66
67
68
|
}
},
compiled () {
if (this.column.type === 'index') {
this.renderType = 'index';
|
3ef4dfb9
梁灏
update Table
|
69
70
|
} else if (this.column.type === 'selection') {
this.renderType = 'selection';
|
a3547c1b
梁灏
update Table
|
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
} else if (this.column.render) {
this.renderType = 'render';
} else {
this.renderType = 'normal';
}
},
ready () {
this.compile();
},
beforeDestroy () {
this.destroy();
},
watch: {
index () {
this.destroy();
this.compile();
}
}
}
</script>
|