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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import _extends from 'babel-runtime/helpers/extends';
import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
import T from './Table';
import { getOptionProps, getKey, getClass, getStyle, getEvents, getSlotOptions, camelize, getSlots } from '../_util/props-util';
var Table = {
name: 'ATable',
Column: T.Column,
ColumnGroup: T.ColumnGroup,
props: T.props,
methods: {
normalize: function normalize() {
var _this = this;
var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var columns = [];
elements.forEach(function (element) {
if (!element.tag) {
return;
}
var key = getKey(element);
var style = getStyle(element);
var cls = getClass(element);
var props = getOptionProps(element);
var events = getEvents(element);
var listeners = {};
Object.keys(events).forEach(function (e) {
var k = 'on-' + e;
listeners[camelize(k)] = events[e];
});
var _getSlots = getSlots(element),
children = _getSlots['default'],
restSlots = _objectWithoutProperties(_getSlots, ['default']);
var column = _extends({}, restSlots, props, { style: style, 'class': cls }, listeners);
if (key) {
column.key = key;
}
if (getSlotOptions(element).__ANT_TABLE_COLUMN_GROUP) {
column.children = _this.normalize(children);
} else {
var customRender = element.data && element.data.scopedSlots && element.data.scopedSlots['default'];
column.customRender = column.customRender || customRender;
}
columns.push(column);
});
return columns;
},
updateColumns: function updateColumns() {
var _this2 = this;
var cols = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
var columns = [];
var $slots = this.$slots,
$scopedSlots = this.$scopedSlots;
cols.forEach(function (col) {
var _col$slots = col.slots,
slots = _col$slots === undefined ? {} : _col$slots,
_col$scopedSlots = col.scopedSlots,
scopedSlots = _col$scopedSlots === undefined ? {} : _col$scopedSlots,
restProps = _objectWithoutProperties(col, ['slots', 'scopedSlots']);
var column = _extends({}, restProps);
Object.keys(slots).forEach(function (key) {
var name = slots[key];
if (column[key] === undefined && $slots[name]) {
column[key] = $slots[name].length === 1 ? $slots[name][0] : $slots[name];
}
});
Object.keys(scopedSlots).forEach(function (key) {
var name = scopedSlots[key];
if (column[key] === undefined && $scopedSlots[name]) {
column[key] = $scopedSlots[name];
}
});
// if (slotScopeName && $scopedSlots[slotScopeName]) {
// column.customRender = column.customRender || $scopedSlots[slotScopeName]
// }
if (col.children) {
column.children = _this2.updateColumns(column.children);
}
columns.push(column);
});
return columns;
}
},
render: function render() {
var h = arguments[0];
var $listeners = this.$listeners,
$slots = this.$slots,
normalize = this.normalize,
$scopedSlots = this.$scopedSlots;
var props = getOptionProps(this);
var columns = props.columns ? this.updateColumns(props.columns) : normalize($slots['default']);
var title = props.title,
footer = props.footer;
var slotTitle = $scopedSlots.title,
slotFooter = $scopedSlots.footer,
_$scopedSlots$expande = $scopedSlots.expandedRowRender,
expandedRowRender = _$scopedSlots$expande === undefined ? props.expandedRowRender : _$scopedSlots$expande;
title = title || slotTitle;
footer = footer || slotFooter;
var tProps = {
props: _extends({}, props, {
columns: columns,
title: title,
footer: footer,
expandedRowRender: expandedRowRender
}),
on: $listeners
};
return h(T, tProps);
}
};
/* istanbul ignore next */
Table.install = function (Vue) {
Vue.component(Table.name, Table);
Vue.component(Table.Column.name, Table.Column);
Vue.component(Table.ColumnGroup.name, Table.ColumnGroup);
};
export default Table;