normal.vue
2.4 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
<template>
<el-table :data="tableData" :size="tableSize" v-bind="bindProps" v-on="$listeners">
<slot name="left"></slot>
<template v-for="(item, index) in columns">
<el-table-column v-bind="item" :key="index">
<slot :name="`header-${item.prop}`" slot="header"></slot>
<template v-if="$scopedSlots[`cell-${item.prop}`]" #default="{ row, column, $index }">
<slot :name="`cell-${item.prop}`" :value="get(row, item.prop)" :row="row" :column="column" :index="$index"></slot>
</template>
<template v-else-if="item.render && typeof item.render === 'function'" #default="{ row, column, $index }">
<cell-render :item="item" :value="get(row, item.prop)" :row="row" :column="column" :index="$index"></cell-render>
</template>
</el-table-column>
</template>
<slot></slot>
<slot name="append"></slot>
</el-table>
</template>
<script>
import tableProps from './props';
import { get } from '../utils';
export default {
name: 'TableNormal',
components: {
CellRender: {
functional: true,
render(h, context) {
const props = context.props;
const item = props.item || {};
const content = item.render(props.value, props.row, h, props.index);
return typeof content === 'string' ? h('span', {}, [content]) : content;
},
},
},
inject: {
elForm: {
default: '',
},
elFormItem: {
default: '',
},
},
props: {
value: {
type: Array,
default() {
return [];
},
},
columns: {
type: Array,
default() {
return [];
},
},
...tableProps,
},
data() {
return {
tableData: this.value.length > 0 ? this.value : this.data,
};
},
watch: {
value(val) {
this.tableData = val || [];
},
data(val) {
this.tableData = val || [];
},
},
computed: {
_elFormItemSize() {
return (this.elFormItem || {}).elFormItemSize;
},
tableSize() {
return this.size || this._elFormItemSize || (this.elForm || {}).size || (this.$ELEMENT || {}).size;
},
bindProps() {
const tablePropsKeys = Object.keys(tableProps);
let props = {};
Object.keys(this._props).forEach(key => {
if (tablePropsKeys.includes(key)) {
props[key] = this._props[key];
}
});
return props;
},
},
methods: {
get,
},
};
</script>