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

72 lines
1.9 KiB
JavaScript
Raw Normal View History

2019-01-21 21:59:13 +08:00
// base rc-table 6.4.3
2019-01-12 11:33:27 +08: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,
2020-01-18 16:14:42 +08:00
getListeners,
2019-01-12 11:33:27 +08:00
} from '../_util/props-util';
2018-03-29 18:18:41 +08:00
const Table = {
name: 'Table',
Column,
ColumnGroup,
props: T.props,
methods: {
2019-01-12 11:33:27 +08:00
normalize(elements = []) {
const columns = [];
2018-03-29 18:18:41 +08:00
elements.forEach(element => {
if (!element.tag) {
2019-01-12 11:33:27 +08:00
return;
2018-03-29 18:18:41 +08:00
}
2019-01-12 11:33:27 +08: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 18:18:41 +08:00
Object.keys(events).forEach(e => {
2019-01-12 11:33:27 +08: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 18:18:41 +08:00
if (key) {
2019-01-12 11:33:27 +08:00
column.key = key;
2018-03-29 18:18:41 +08:00
}
if (getSlotOptions(element).isTableColumnGroup) {
2019-08-07 21:56:30 +08:00
column.children = this.normalize(typeof children === 'function' ? children() : children);
2018-03-29 18:18:41 +08:00
} else {
2019-01-12 11:33:27 +08:00
const customRender =
element.data && element.data.scopedSlots && element.data.scopedSlots.default;
column.customRender = column.customRender || customRender;
2018-03-29 18:18:41 +08:00
}
2019-01-12 11:33:27 +08:00
columns.push(column);
});
return columns;
2018-03-29 18:18:41 +08:00
},
},
2019-01-12 11:33:27 +08:00
render() {
2020-01-18 16:14:42 +08:00
const { $slots, normalize } = this;
2019-01-12 11:33:27 +08:00
const props = getOptionProps(this);
const columns = props.columns || normalize($slots.default);
2018-03-29 18:18:41 +08:00
const tProps = {
props: {
...props,
columns,
},
2020-01-18 16:14:42 +08:00
on: getListeners(this),
2019-01-12 11:33:27 +08:00
};
return <T {...tProps} />;
2018-03-29 18:18:41 +08:00
},
2019-01-12 11:33:27 +08:00
};
2018-03-24 22:02:24 +08:00
2019-01-12 11:33:27 +08:00
export default Table;
export { Column, ColumnGroup };