import { RightOutlined } from '@ant-design/icons'; import { Button, Checkbox, Empty, Pagination, Spin, type PaginationProps } from 'antd'; import _ from 'lodash'; import React, { useEffect, useMemo, useRef, useState } from 'react'; import Header from './components/header'; import TableRow from './components/table-row'; import './styles/index.less'; import { SealTableProps } from './types'; const SealTable: React.FC = ( props ) => { const { children, rowKey, childParentKey, onExpand, onSort, expandedRowKeys, loading, expandable, pollingChildren, watchChildren, rowSelection, pagination, 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) { rowSelection?.onChange(props.dataSource.map((record) => record[rowKey])); setSelectAll(true); setIndeterminate(false); } else { rowSelection?.onChange([]); setSelectAll(false); setIndeterminate(false); } }; const handlePageChange = (page: number, pageSize: number) => { pagination?.onChange?.(page, pageSize); }; const handlePageSizeChange = (current: number, size: number) => { pagination?.onShowSizeChange?.(current, size); }; const renderHeaderPrefix = useMemo(() => { if (expandable && rowSelection) { return (
); } if (expandable) { return (
{_.isBoolean(expandable) ? ( ) : ( expandable )}
); } if (rowSelection) { return (
{}
); } return null; }, [expandable, rowSelection, selectAll, indeterminate]); const renderContent = useMemo(() => { if (!props.dataSource.length) { return (
); } return (
{props.dataSource.map((item, index) => { return ( ); })}
); }, [props.dataSource, expandedRowKeys, rowSelection, children]); return ( <>
{
{renderHeaderPrefix}
{children}
} {renderContent}
{pagination && (
)} ); }; export default React.memo(SealTable);