import React, { FC } from 'react' import SVGLeftSmall from '../../svg/left-small.svg' import SVGRightSmall from '../../svg/right-small.svg' import { Flex } from '../flex' import classNames from 'classnames' import _ from 'lodash' import { getIndex } from './util' import { PaginationProps } from './types' const PageWithoutCount: FC = ({ paging, onChange }) => { const index = getIndex(paging) // 往前显示4个页码 const begin = Math.max(1, index - 4) // 往后显示的页码, // 最后一页不显示,属于 ...,所以 -1 // 最多4页 const end = paging.has_more ? index + 1 : index const handlePage = (_index: number) => { onChange({ ...paging, offset: (_index - 1) * paging.limit, }) } return (
handlePage(index - 1)} >
{_.map(_.range(begin, end + 1), (page, i) => (
handlePage(page)} > {page}
))} {paging.has_more && ···}
handlePage(index + 1)} >
) } export default PageWithoutCount