import * as React from 'react'; import { PureComponent } from 'react'; import * as ReactDOM from 'react-dom'; import { Checkbox, LitePagination, MiniPagination, Pagination } from 'zent'; import isNil from 'zent/es/utils/isNil'; import { PaginationChangeHandler, BasePagination, } from 'zent/es/pagination/impl/BasePagination'; import { Class } from 'utility-types'; import helper from '../helper'; import { TablePaginationType, ITablePageInfo } from '../Table'; export interface ITableFootProps { pageInfo: ITablePageInfo; paginationType: TablePaginationType; batchComponentsFixed: boolean; onPageChange: PaginationChangeHandler; selection: { needSelect: boolean; isSingleSelection: boolean; onSelectAll: (isSelectAll: boolean) => any; selectedRows: any[]; isSelectAll: boolean; isSelectPart: boolean; }; batchComponents: any[]; current: number; } export default class Foot extends PureComponent { footStyleFixed: React.CSSProperties; batch: HTMLDivElement | null = null; // 拿到所有的选中的item renderBatchComps(selectedRows, batchComponents) { return batchComponents.map((comp, index) => { let subComponent; if (helper.isReactComponent(comp)) { const Comp = comp; subComponent = ; } else if (typeof comp === 'function') { subComponent = comp(selectedRows, index); } else { subComponent = comp; } return (
{subComponent}
); }); } // 等重构再删了吧,改不动 // eslint-disable-next-line react/no-deprecated componentWillReceiveProps(nextProps) { if (nextProps.batchComponentsFixed) { this.footStyleFixed = { height: (ReactDOM.findDOMNode( this.batch ) as Element).getBoundingClientRect().height, }; } else { this.footStyleFixed = {}; } } onSelect = e => { let isChecked = false; if (e.target.checked) { isChecked = true; } this.props.selection.onSelectAll(isChecked); }; render() { const { onPageChange, paginationType, batchComponents, selection, current, } = this.props; const pageInfo = this.props.pageInfo || {}; const { // tslint:disable-next-line:deprecation totalItem, pageSize, total, // tslint:disable-next-line:deprecation limit, current: _, ...restPageInfo } = pageInfo; const { needSelect, selectedRows } = selection; let batchClassName = 'tfoot__batchcomponents'; const shouldRenderFoot = (batchComponents && batchComponents.length > 0) || Object.keys(pageInfo).length !== 0; if (batchComponents && batchComponents.length > 0) { batchClassName += ' tfoot__batchcomponents--has-children'; } if (this.props.batchComponentsFixed) { batchClassName += ' tfoot__batchcomponents--fixed'; } // 判断使用哪种 Pagination let PaginationComp: Class>; switch (paginationType) { case 'mini': PaginationComp = MiniPagination; break; case 'lite': PaginationComp = LitePagination; break; case 'default': PaginationComp = Pagination; break; default: PaginationComp = Pagination; break; } return ( shouldRenderFoot && (
(this.batch = c)}> {needSelect && batchComponents && batchComponents.length > 0 && ( )} {batchComponents && batchComponents.length > 0 && this.renderBatchComps(selectedRows, batchComponents)}
{Object.keys(pageInfo).length > 0 && ( )}
) ); } }