index.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import _extends from 'babel-runtime/helpers/extends';
  2. // base rc-table 6.10.9
  3. import T from './src/Table';
  4. import Column from './src/Column';
  5. import ColumnGroup from './src/ColumnGroup';
  6. import { getOptionProps, getKey, getClass, getStyle, getEvents, getSlotOptions, camelize, getSlots, getListeners } from '../_util/props-util';
  7. import { INTERNAL_COL_DEFINE } from './src/utils';
  8. var Table = {
  9. name: 'Table',
  10. Column: Column,
  11. ColumnGroup: ColumnGroup,
  12. props: T.props,
  13. methods: {
  14. getTableNode: function getTableNode() {
  15. return this.$refs.table.tableNode;
  16. },
  17. getBodyTable: function getBodyTable() {
  18. return this.$refs.table.ref_bodyTable;
  19. },
  20. normalize: function normalize() {
  21. var _this = this;
  22. var elements = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  23. var columns = [];
  24. elements.forEach(function (element) {
  25. if (!element.tag) {
  26. return;
  27. }
  28. var key = getKey(element);
  29. var style = getStyle(element);
  30. var cls = getClass(element);
  31. var props = getOptionProps(element);
  32. var events = getEvents(element);
  33. var listeners = {};
  34. Object.keys(events).forEach(function (e) {
  35. var k = 'on-' + e;
  36. listeners[camelize(k)] = events[e];
  37. });
  38. var _getSlots = getSlots(element),
  39. children = _getSlots['default'],
  40. title = _getSlots.title;
  41. var column = _extends({ title: title }, props, { style: style, 'class': cls }, listeners);
  42. if (key) {
  43. column.key = key;
  44. }
  45. if (getSlotOptions(element).isTableColumnGroup) {
  46. column.children = _this.normalize(typeof children === 'function' ? children() : children);
  47. } else {
  48. var customRender = element.data && element.data.scopedSlots && element.data.scopedSlots['default'];
  49. column.customRender = column.customRender || customRender;
  50. }
  51. columns.push(column);
  52. });
  53. return columns;
  54. }
  55. },
  56. render: function render() {
  57. var h = arguments[0];
  58. var $slots = this.$slots,
  59. normalize = this.normalize;
  60. var props = getOptionProps(this);
  61. var columns = props.columns || normalize($slots['default']);
  62. var tProps = {
  63. props: _extends({}, props, {
  64. columns: columns
  65. }),
  66. on: getListeners(this),
  67. ref: 'table'
  68. };
  69. return h(T, tProps);
  70. }
  71. };
  72. export default Table;
  73. export { Column, ColumnGroup, INTERNAL_COL_DEFINE };