a3547c1b
梁灏
update Table
|
1
|
<template>
|
3ef4dfb9
梁灏
update Table
|
2
|
<div :class="classes">
|
741b987a
梁灏
update Table
|
3
|
<template v-if="renderType === 'index'">{{naturalIndex + 1}}</template>
|
3ef4dfb9
梁灏
update Table
|
4
|
<template v-if="renderType === 'selection'">
|
486d4fda
梁灏
update Table
|
5
|
<Checkbox :value="checked" @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>
|
a3547c1b
梁灏
update Table
|
8
9
10
|
</div>
</template>
<script>
|
486d4fda
梁灏
update Table
|
11
|
import Vue from 'vue';
|
3ef4dfb9
梁灏
update Table
|
12
13
|
import Checkbox from '../checkbox/checkbox.vue';
|
a3547c1b
梁灏
update Table
|
14
|
export default {
|
486d4fda
梁灏
update Table
|
15
|
name: 'TableCell',
|
3ef4dfb9
梁灏
update Table
|
16
|
components: { Checkbox },
|
a3547c1b
梁灏
update Table
|
17
18
19
20
|
props: {
prefixCls: String,
row: Object,
column: Object,
|
741b987a
梁灏
update Table
|
21
22
|
naturalIndex: Number, // index of rebuildData
index: Number, // _index of data
|
7f34c510
梁灏
update Table
|
23
|
checked: Boolean,
|
87379c82
leonine
去掉禁用行的 tr>td 的dis...
|
24
|
disabled: Boolean,
|
5d0499ce
梁灏
update Table
|
25
26
27
28
|
fixed: {
type: [Boolean, String],
default: false
}
|
a3547c1b
梁灏
update Table
|
29
30
31
32
|
},
data () {
return {
renderType: '',
|
d0e206c5
梁灏
Table add content...
|
33
|
uid: -1,
|
486d4fda
梁灏
update Table
|
34
|
content: this.$parent.$parent.currentContent
|
b0893113
jingsam
add eslint
|
35
|
};
|
a3547c1b
梁灏
update Table
|
36
|
},
|
3ef4dfb9
梁灏
update Table
|
37
38
39
40
41
|
computed: {
classes () {
return [
`${this.prefixCls}-cell`,
{
|
eedcba58
Rijn
Added ellipsis pr...
|
42
43
|
[`${this.prefixCls}-hidden`]: !this.fixed && this.column.fixed && (this.column.fixed === 'left' || this.column.fixed === 'right'),
[`${this.prefixCls}-cell-ellipsis`]: this.column.ellipsis || false
|
3ef4dfb9
梁灏
update Table
|
44
|
}
|
b0893113
jingsam
add eslint
|
45
|
];
|
3ef4dfb9
梁灏
update Table
|
46
47
|
}
},
|
a3547c1b
梁灏
update Table
|
48
49
50
|
methods: {
compile () {
if (this.column.render) {
|
d0e206c5
梁灏
Table add content...
|
51
|
const $parent = this.content;
|
a3547c1b
梁灏
update Table
|
52
53
54
|
const template = this.column.render(this.row, this.column, this.index);
const cell = document.createElement('div');
cell.innerHTML = template;
|
7f34c510
梁灏
update Table
|
55
|
const _oldParentChildLen = $parent.$children.length;
|
486d4fda
梁灏
update Table
|
56
|
// $parent.$compile(cell); // todo 这里无法触发 ready 钩子
|
7f34c510
梁灏
update Table
|
57
|
const _newParentChildLen = $parent.$children.length;
|
a3547c1b
梁灏
update Table
|
58
59
|
if (_oldParentChildLen !== _newParentChildLen) { // if render normal html node, do not tag
|
7f34c510
梁灏
update Table
|
60
|
this.uid = $parent.$children[$parent.$children.length - 1]._uid; // tag it, and delete when data or columns update
|
a3547c1b
梁灏
update Table
|
61
62
|
}
this.$el.innerHTML = '';
|
486d4fda
梁灏
update Table
|
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// this.$el.appendChild(cell);
let methods = {};
let $_parent = this.$parent;
while($_parent != null && $_parent._name != '<Table>'){
$_parent = $_parent.$parent;
}
if ($_parent) {
Object.keys($_parent).forEach(key => {
const func = this.$parent.$parent.$parent[`${key}`];
if(typeof(func) === 'function' &&func.name === 'boundFn'){
methods[`${key}`] = func;
}
});
}
const res = Vue.compile(cell.outerHTML);
const compt = new Vue({
render: res.render,
staticRenderFns: res.staticRenderFns,
methods: methods
});
compt.$mount(this.$el);
|
a3547c1b
梁灏
update Table
|
84
85
86
|
}
},
destroy () {
|
d0e206c5
梁灏
Table add content...
|
87
|
const $parent = this.content;
|
7f34c510
梁灏
update Table
|
88
89
90
|
for (let i = 0; i < $parent.$children.length; i++) {
if ($parent.$children[i]._uid === this.uid) {
$parent.$children[i].$destroy();
|
a3547c1b
梁灏
update Table
|
91
92
|
}
}
|
3ef4dfb9
梁灏
update Table
|
93
|
},
|
741b987a
梁灏
update Table
|
94
95
|
toggleSelect () {
this.$parent.$parent.toggleSelect(this.index);
|
a3547c1b
梁灏
update Table
|
96
97
|
}
},
|
486d4fda
梁灏
update Table
|
98
|
created () {
|
a3547c1b
梁灏
update Table
|
99
100
|
if (this.column.type === 'index') {
this.renderType = 'index';
|
3ef4dfb9
梁灏
update Table
|
101
102
|
} else if (this.column.type === 'selection') {
this.renderType = 'selection';
|
a3547c1b
梁灏
update Table
|
103
104
105
106
107
108
|
} else if (this.column.render) {
this.renderType = 'render';
} else {
this.renderType = 'normal';
}
},
|
486d4fda
梁灏
update Table
|
109
110
111
112
|
mounted () {
this.$nextTick(() => {
this.compile();
});
|
a3547c1b
梁灏
update Table
|
113
114
115
116
117
|
},
beforeDestroy () {
this.destroy();
},
watch: {
|
741b987a
梁灏
update Table
|
118
|
naturalIndex () {
|
a3547c1b
梁灏
update Table
|
119
120
121
122
|
this.destroy();
this.compile();
}
}
|
b0893113
jingsam
add eslint
|
123
124
|
};
</script>
|