2019-01-12 03:33:27 +00:00
|
|
|
import T from './Table';
|
2020-07-23 10:34:24 +00:00
|
|
|
import { getOptionProps, getKey, getPropsData, getSlot } from '../_util/props-util';
|
2020-03-07 11:45:13 +00:00
|
|
|
|
2018-04-01 04:52:27 +00:00
|
|
|
const Table = {
|
2018-04-08 13:17:20 +00:00
|
|
|
name: 'ATable',
|
2018-04-01 04:52:27 +00:00
|
|
|
Column: T.Column,
|
|
|
|
ColumnGroup: T.ColumnGroup,
|
|
|
|
props: T.props,
|
2020-07-23 10:34:24 +00:00
|
|
|
inheritAttrs: false,
|
2018-04-01 04:52:27 +00:00
|
|
|
methods: {
|
2019-01-12 03:33:27 +00:00
|
|
|
normalize(elements = []) {
|
|
|
|
const columns = [];
|
2018-04-01 04:52:27 +00:00
|
|
|
elements.forEach(element => {
|
2020-07-23 10:34:24 +00:00
|
|
|
if (!element) {
|
2019-01-12 03:33:27 +00:00
|
|
|
return;
|
2018-04-01 04:52:27 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
const key = getKey(element);
|
2020-07-23 10:34:24 +00:00
|
|
|
const style = element.props?.style || {};
|
|
|
|
const cls = element.props?.class || '';
|
|
|
|
const props = getPropsData(element);
|
|
|
|
const { default: children, ...restSlots } = element.children;
|
|
|
|
const column = { ...restSlots, ...props, style, class: cls };
|
2018-04-01 04:52:27 +00:00
|
|
|
if (key) {
|
2019-01-12 03:33:27 +00:00
|
|
|
column.key = key;
|
2018-04-01 04:52:27 +00:00
|
|
|
}
|
2020-07-23 10:34:24 +00:00
|
|
|
if (element.type?.__ANT_TABLE_COLUMN_GROUP) {
|
2019-08-07 13:56:30 +00:00
|
|
|
column.children = this.normalize(typeof children === 'function' ? children() : children);
|
2018-04-01 04:52:27 +00:00
|
|
|
} else {
|
2020-07-23 10:34:24 +00:00
|
|
|
const customRender = element.children?.default;
|
2019-01-12 03:33:27 +00:00
|
|
|
column.customRender = column.customRender || customRender;
|
2018-04-01 04:52:27 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
columns.push(column);
|
|
|
|
});
|
|
|
|
return columns;
|
2018-04-01 04:52:27 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
updateColumns(cols = []) {
|
|
|
|
const columns = [];
|
2020-07-23 10:34:24 +00:00
|
|
|
const { $slots } = this;
|
2018-04-01 04:52:27 +00:00
|
|
|
cols.forEach(col => {
|
2020-07-23 10:34:24 +00:00
|
|
|
const { slots = {}, ...restProps } = col;
|
2018-04-01 04:52:27 +00:00
|
|
|
const column = {
|
|
|
|
...restProps,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-04-02 01:48:03 +00:00
|
|
|
Object.keys(slots).forEach(key => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const name = slots[key];
|
2018-04-02 01:48:03 +00:00
|
|
|
if (column[key] === undefined && $slots[name]) {
|
2020-07-23 10:34:24 +00:00
|
|
|
column[key] = $slots[name];
|
2018-04-02 01:48:03 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-04-02 01:48:03 +00:00
|
|
|
// if (slotScopeName && $scopedSlots[slotScopeName]) {
|
|
|
|
// column.customRender = column.customRender || $scopedSlots[slotScopeName]
|
|
|
|
// }
|
2018-04-01 04:52:27 +00:00
|
|
|
if (col.children) {
|
2019-01-12 03:33:27 +00:00
|
|
|
column.children = this.updateColumns(column.children);
|
2018-04-01 04:52:27 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
columns.push(column);
|
|
|
|
});
|
|
|
|
return columns;
|
2018-04-01 04:52:27 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
2020-07-23 10:34:24 +00:00
|
|
|
const { normalize, $slots } = this;
|
|
|
|
const props = { ...getOptionProps(this), ...this.$attrs };
|
|
|
|
const columns = props.columns ? this.updateColumns(props.columns) : normalize(getSlot(this));
|
2019-01-12 03:33:27 +00:00
|
|
|
let { title, footer } = props;
|
2018-04-02 14:13:11 +00:00
|
|
|
const {
|
|
|
|
title: slotTitle,
|
|
|
|
footer: slotFooter,
|
|
|
|
expandedRowRender = props.expandedRowRender,
|
2020-07-23 10:34:24 +00:00
|
|
|
} = $slots;
|
2019-01-12 03:33:27 +00:00
|
|
|
title = title || slotTitle;
|
|
|
|
footer = footer || slotFooter;
|
2018-04-01 04:52:27 +00:00
|
|
|
const tProps = {
|
2020-07-23 10:34:24 +00:00
|
|
|
...props,
|
|
|
|
columns,
|
|
|
|
title,
|
|
|
|
footer,
|
|
|
|
expandedRowRender,
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
|
|
|
return <T {...tProps} />;
|
2018-04-01 04:52:27 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-09-19 05:21:57 +00:00
|
|
|
/* istanbul ignore next */
|
2020-07-23 10:34:24 +00:00
|
|
|
Table.install = function(app) {
|
|
|
|
app.component(Table.name, Table);
|
|
|
|
app.component(Table.Column.name, Table.Column);
|
|
|
|
app.component(Table.ColumnGroup.name, Table.ColumnGroup);
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-29 14:08:04 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
export default Table;
|