import { RightOutlined } from '@ant-design/icons'; import { Button, Checkbox, Col, Empty, Row, Spin } from 'antd'; import _ from 'lodash'; import React, { useEffect, useRef, useState } from 'react'; import TableHeader from './components/table-header'; import TableRow from './components/table-row'; import './styles/index.less'; import { SealColumnProps, SealTableProps } from './types'; const SealTable: React.FC = (props) => { const { children, rowKey, onExpand, loading, expandable, pollingChildren, watchChildren, rowSelection, renderChildren, loadChildren, loadChildrenAPI } = props; console.log('sealtable===='); const [selectAll, setSelectAll] = useState(false); const [indeterminate, setIndeterminate] = useState(false); const tableContent = useRef(null); useEffect(() => { if (rowSelection) { const { selectedRowKeys } = rowSelection; if (selectedRowKeys.length === 0) { setSelectAll(false); setIndeterminate(false); } else if (selectedRowKeys.length === props.dataSource.length) { setSelectAll(true); setIndeterminate(false); } else { setSelectAll(false); setIndeterminate(true); } } }, [rowSelection]); const handleSelectAllChange = (e: any) => { if (e.target.checked) { // update selectedRowKeys rowSelection?.onChange(props.dataSource.map((record) => record[rowKey])); setSelectAll(true); setIndeterminate(false); } else { // update selectedRowKeys rowSelection?.onChange([]); setSelectAll(false); setIndeterminate(false); } }; const renderHeaderPrefix = () => { if (expandable && rowSelection) { return (
); } if (expandable) { return (
{_.isBoolean(expandable) ? ( ) : ( expandable )}
); } if (rowSelection) { return (
{}
); } return null; }; const renderHeader = () => { return (
{renderHeaderPrefix()} {React.Children.map(props.children, (child, i) => { const { props: columnProps } = child as any; const { title, align, span, headerStyle } = columnProps as SealColumnProps; if (React.isValidElement(child)) { return ( ); } return null; })}
); }; const renderContent = () => { if (!props.dataSource.length) { return (
); } return (
{props.dataSource.map((item, index) => { return ( ); })}
); }; return (
{renderHeader()} {loading ? (
) : ( renderContent() )}
); }; export default React.memo(SealTable);