import type { GetRowKey, Key, GetComponentProps } from '../interface'; import ExpandedRow from './ExpandedRow'; import { getColumnsKey } from '../utils/valueUtil'; import MeasureCell from './MeasureCell'; import BodyRow from './BodyRow'; import useFlattenRecords from '../hooks/useFlattenRecords'; import { defineComponent, toRef } from 'vue'; import { useInjectResize } from '../context/ResizeContext'; import { useInjectTable } from '../context/TableContext'; import { useInjectBody } from '../context/BodyContext'; export interface BodyProps { data: RecordType[]; getRowKey: GetRowKey; measureColumnWidth: boolean; expandedKeys: Set; customRow: GetComponentProps; rowExpandable: (record: RecordType) => boolean; childrenColumnName: string; } export default defineComponent>({ name: 'Body', props: [ 'data', 'getRowKey', 'measureColumnWidth', 'expandedKeys', 'customRow', 'rowExpandable', 'childrenColumnName', ] as any, slots: ['emptyNode'], setup(props, { slots }) { const resizeContext = useInjectResize(); const tableContext = useInjectTable(); const bodyContext = useInjectBody(); const flattenData = useFlattenRecords( toRef(props, 'data'), toRef(props, 'childrenColumnName'), toRef(props, 'expandedKeys'), toRef(props, 'getRowKey'), ); return () => { const { data, getRowKey, measureColumnWidth, expandedKeys, customRow, rowExpandable, childrenColumnName, } = props; const { onColumnResize } = resizeContext; const { prefixCls, getComponent } = tableContext; const { fixHeader, horizonScroll, flattenColumns, componentWidth } = bodyContext; const WrapperComponent = getComponent(['body', 'wrapper'], 'tbody'); const trComponent = getComponent(['body', 'row'], 'tr'); const tdComponent = getComponent(['body', 'cell'], 'td'); let rows; if (data.length) { rows = flattenData.value.map((item, index) => { const { record, indent } = item; const key = getRowKey(record, index); return ( ); }); } else { rows = ( {slots.emptyNode?.()} ); } const columnsKey = getColumnsKey(flattenColumns); return ( {/* Measure body column width with additional hidden col */} {measureColumnWidth && ( {columnsKey.map(columnKey => ( ))} )} {rows} ); }; }, });