ant-design-vue/components/vc-table/index.js

71 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-01-01 14:30:06 +00:00
// base rc-table 6.4.2
2019-01-12 03:33:27 +00:00
import T from './src/Table';
import Column from './src/Column';
import ColumnGroup from './src/ColumnGroup';
import {
getOptionProps,
getKey,
getClass,
getStyle,
getEvents,
getSlotOptions,
camelize,
getSlots,
} from '../_util/props-util';
2018-03-29 10:18:41 +00:00
const Table = {
name: 'Table',
Column,
ColumnGroup,
props: T.props,
methods: {
2019-01-12 03:33:27 +00:00
normalize(elements = []) {
const columns = [];
2018-03-29 10:18:41 +00:00
elements.forEach(element => {
if (!element.tag) {
2019-01-12 03:33:27 +00:00
return;
2018-03-29 10:18:41 +00:00
}
2019-01-12 03:33:27 +00:00
const key = getKey(element);
const style = getStyle(element);
const cls = getClass(element);
const props = getOptionProps(element);
const events = getEvents(element);
const listeners = {};
2018-03-29 10:18:41 +00:00
Object.keys(events).forEach(e => {
2019-01-12 03:33:27 +00:00
const k = `on-${e}`;
listeners[camelize(k)] = events[e];
});
const { default: children, title } = getSlots(element);
const column = { title, ...props, style, class: cls, ...listeners };
2018-03-29 10:18:41 +00:00
if (key) {
2019-01-12 03:33:27 +00:00
column.key = key;
2018-03-29 10:18:41 +00:00
}
if (getSlotOptions(element).isTableColumnGroup) {
2019-01-12 03:33:27 +00:00
column.children = this.normalize(children);
2018-03-29 10:18:41 +00:00
} else {
2019-01-12 03:33:27 +00:00
const customRender =
element.data && element.data.scopedSlots && element.data.scopedSlots.default;
column.customRender = column.customRender || customRender;
2018-03-29 10:18:41 +00:00
}
2019-01-12 03:33:27 +00:00
columns.push(column);
});
return columns;
2018-03-29 10:18:41 +00:00
},
},
2019-01-12 03:33:27 +00:00
render() {
const { $listeners, $slots, normalize } = this;
const props = getOptionProps(this);
const columns = props.columns || normalize($slots.default);
2018-03-29 10:18:41 +00:00
const tProps = {
props: {
...props,
columns,
},
on: $listeners,
2019-01-12 03:33:27 +00:00
};
return <T {...tProps} />;
2018-03-29 10:18:41 +00:00
},
2019-01-12 03:33:27 +00:00
};
2018-03-24 14:02:24 +00:00
2019-01-12 03:33:27 +00:00
export default Table;
export { Column, ColumnGroup };