import React, { useEffect, useMemo, useState } from "react"; import { Col, Row, Spin, Empty, theme, Button, Grid } from "antd"; import { VerticalLeftOutlined } from "@ant-design/icons"; import { CardListConfig } from "../../tmpl/interface"; import CardListItem from "./card-list-item"; import "./index.less"; const { useToken } = theme; const { useBreakpoint } = Grid; type Props = { cardListConfig?: CardListConfig; dataSource?: object[]; columns?: any[]; serverKey?: string; sourceId?: string; loading?: boolean; errorText?: string; total?: number; pageInfo?: { pageNo: number, pageSize: number }; onChangePage?: (pageNo: number, pageSize: number) => void; }; const Index = (props: Props) => { const { cardListConfig, dataSource, columns, serverKey, sourceId, loading, errorText, total, pageInfo, onChangePage } = props; const [showNextPage, setShowNextPage] = useState(false); const { token } = useToken(); const screens = useBreakpoint(); const renderOpt = (item: unknown) => { const actionCol = columns.find(col => col["操作"] == 1); return actionCol?.render(item, item); } const colFlex = useMemo(() => { const rowCardCount = cardListConfig?.rowCardCount || 5; const flex = Math.floor((100 / rowCardCount) * 100) / 100; return `${flex}%`; }, [cardListConfig]); // 判断是否显示下一页卡片 const handleShowNextPage = () => { const { pageNo, pageSize } = pageInfo; const isNextPage = pageNo * pageSize < total; const col = { xl: Number(colFlex.split("%")[0]), lg: 25, sm: 50 }; if (isNextPage) { const rowCount = Math.round(100 / (screens.xl ? col.xl : (screens.lg ? col.lg : col.sm))); const temShow = pageSize % rowCount !== 0; setShowNextPage(temShow); } else { setShowNextPage(false); } } useEffect(() => { if (onChangePage && total && pageInfo && colFlex) { handleShowNextPage(); } else { setShowNextPage(false); } }, [pageInfo, total, colFlex, screens]); // 显示下一页卡片 const renderNextPage = () => { return ; } return (
{!dataSource?.length ? : {dataSource?.map((item, index) => )} {showNextPage ? {renderNextPage()} : ""} }
); }; export default Index;