Files
blog/src/components/Post/Pagination.astro
2026-08-14 22:40:26 +08:00

68 lines
1.5 KiB
Plaintext

---
interface Props {
page: number
totalPage: number
}
const {page, totalPage} = Astro.props
---
<!--分页器-->
{totalPage > 1 &&
<nav class="pagination" aria-label="分页">
{page > 1 ? <a href={`/page/${page - 1}`} class="link">« 上一页</a> : <span class="link disabled">« 上一页</span>}
{Array.from({length: totalPage}).map((_, index) => {
if (page === index + 1) {
return <span class="link current">{index + 1}</span>
}
return <a class="link" href={`/page/${index + 1}`}>{index + 1}</a>
})}
{page < totalPage ? <a href={`/page/${page + 1}`} class="link">下一页 »</a> :
<span class="link disabled">下一页 »</span>}
</nav>}
<style>
/* ========== 分页 ========== */
.pagination {
width: 100%;
text-align: center;
white-space: nowrap;
overflow-x: auto;
}
.link {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 38px;
height: 38px;
padding: 0 12px;
border-radius: 8px;
background: var(--card-bg);
border: 1px solid var(--border);
font-size: 14px;
color: var(--text-secondary);
transition: all 0.2s;
white-space: nowrap;
margin-left: 8px;
}
.link:first-child {
margin-left: 0;
}
.link:hover,
.link.current {
background: var(--primary);
border-color: var(--primary);
color: #fff;
}
.link.disabled {
color: var(--text-secondary);
background: var(--card-bg);
border-color: var(--border);
cursor: not-allowed;
}
</style>