32 lines
767 B
JavaScript
32 lines
767 B
JavaScript
import React, { useState } from 'react'
|
|
import './index.scss'
|
|
function noop() { }
|
|
|
|
export default ({ current, defaultCurrent, total, pageSize, onChange = noop }) => {
|
|
const maxPage = Math.ceil(total / pageSize)
|
|
const [page, setPage] = useState(current || defaultCurrent)
|
|
|
|
function next() {
|
|
if (page < maxPage) {
|
|
let value = page + 1
|
|
setPage(value)
|
|
onChange(value)
|
|
}
|
|
}
|
|
|
|
function prev() {
|
|
if (page > 1) {
|
|
let value = page - 1
|
|
setPage(value)
|
|
onChange(value)
|
|
}
|
|
}
|
|
|
|
return (
|
|
<div className="mini-pagination">
|
|
<a className={page === 1 ? 'disabled' : 'normal'} onClick={prev}>上一页</a>
|
|
<a className={page === maxPage ? 'disabled' : 'normal'} onClick={next} >下一页</a>
|
|
</div>
|
|
)
|
|
|
|
} |