fix: small screen page style
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-between gap-2">
|
<div class="flex items-center justify-between gap-2 w-full">
|
||||||
<!-- 统计信息 -->
|
<!-- 统计信息 -->
|
||||||
<div class="text-xs sm:text-sm text-muted-foreground shrink-0">
|
<div class="text-xs sm:text-sm text-muted-foreground shrink-0">
|
||||||
<span>共 {{ total }} 条</span>
|
<span>共 {{ total }} 条</span>
|
||||||
@@ -7,16 +7,16 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 分页控件 -->
|
<!-- 分页控件 -->
|
||||||
<Pagination
|
<div class="flex justify-end shrink-0">
|
||||||
:total="total"
|
<Pagination
|
||||||
:items-per-page="pageSize"
|
:total="total"
|
||||||
:sibling-count="1"
|
:items-per-page="pageSize"
|
||||||
:show-edges="true"
|
:sibling-count="1"
|
||||||
:default-page="currentPage"
|
:show-edges="true"
|
||||||
:page="currentPage"
|
:default-page="currentPage"
|
||||||
@update:page="handlePageChange"
|
:page="currentPage"
|
||||||
class="shrink-0"
|
@update:page="handlePageChange"
|
||||||
>
|
>
|
||||||
<PaginationContent class="gap-0.5 sm:gap-1">
|
<PaginationContent class="gap-0.5 sm:gap-1">
|
||||||
<PaginationItem :value="currentPage - 1">
|
<PaginationItem :value="currentPage - 1">
|
||||||
<PaginationPrevious
|
<PaginationPrevious
|
||||||
@@ -65,7 +65,8 @@
|
|||||||
</PaginationNext>
|
</PaginationNext>
|
||||||
</PaginationItem>
|
</PaginationItem>
|
||||||
</PaginationContent>
|
</PaginationContent>
|
||||||
</Pagination>
|
</Pagination>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -101,81 +102,79 @@ type PaginationItem =
|
|||||||
| { type: 'page'; value: number }
|
| { type: 'page'; value: number }
|
||||||
| { type: 'ellipsis' }
|
| { type: 'ellipsis' }
|
||||||
|
|
||||||
// 生成分页项目
|
// 响应式显示项目(根据屏幕大小使用不同逻辑)
|
||||||
const items = computed((): PaginationItem[] => {
|
|
||||||
const pages: PaginationItem[] = []
|
|
||||||
const total = totalPages.value
|
|
||||||
const current = props.currentPage
|
|
||||||
|
|
||||||
if (total <= 7) {
|
|
||||||
// 如果总页数小于等于7,显示所有页码
|
|
||||||
for (let i = 1; i <= total; i++) {
|
|
||||||
pages.push({ type: 'page', value: i })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 复杂分页逻辑
|
|
||||||
if (current <= 2) {
|
|
||||||
// 当前页在前面
|
|
||||||
for (let i = 1; i <= 3; i++) {
|
|
||||||
pages.push({ type: 'page', value: i })
|
|
||||||
}
|
|
||||||
pages.push({ type: 'ellipsis' })
|
|
||||||
pages.push({ type: 'page', value: total })
|
|
||||||
} else if (current >= total - 3) {
|
|
||||||
// 当前页在后面
|
|
||||||
pages.push({ type: 'page', value: 1 })
|
|
||||||
pages.push({ type: 'ellipsis' })
|
|
||||||
for (let i = total - 4; i <= total; i++) {
|
|
||||||
pages.push({ type: 'page', value: i })
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 当前页在中间
|
|
||||||
pages.push({ type: 'page', value: 1 })
|
|
||||||
pages.push({ type: 'ellipsis' })
|
|
||||||
for (let i = current - 1; i <= current + 1; i++) {
|
|
||||||
pages.push({ type: 'page', value: i })
|
|
||||||
}
|
|
||||||
pages.push({ type: 'ellipsis' })
|
|
||||||
pages.push({ type: 'page', value: total })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pages
|
|
||||||
})
|
|
||||||
|
|
||||||
// 小屏显示项目(更少的页码)
|
|
||||||
const displayItems = computed((): PaginationItem[] => {
|
const displayItems = computed((): PaginationItem[] => {
|
||||||
|
const pages: PaginationItem[] = []
|
||||||
const total = totalPages.value
|
const total = totalPages.value
|
||||||
const current = props.currentPage
|
const current = props.currentPage
|
||||||
const pages: PaginationItem[] = []
|
|
||||||
|
|
||||||
if (total <= 5) {
|
// 使用媒体查询判断是否为小屏
|
||||||
// 总页数少,显示所有
|
const isSmallScreen = typeof window !== 'undefined' && window.innerWidth < 640
|
||||||
for (let i = 1; i <= total; i++) {
|
|
||||||
pages.push({ type: 'page', value: i })
|
if (isSmallScreen) {
|
||||||
|
// 小屏逻辑:只显示关键页码
|
||||||
|
if (total <= 5) {
|
||||||
|
// 总页数少,显示所有
|
||||||
|
for (let i = 1; i <= total; i++) {
|
||||||
|
pages.push({ type: 'page', value: i })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 只显示当前页和首尾页
|
||||||
|
if (current === 1) {
|
||||||
|
pages.push({ type: 'page', value: 1 })
|
||||||
|
pages.push({ type: 'page', value: 2 })
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
pages.push({ type: 'page', value: total })
|
||||||
|
} else if (current === total) {
|
||||||
|
pages.push({ type: 'page', value: 1 })
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
pages.push({ type: 'page', value: total - 1 })
|
||||||
|
pages.push({ type: 'page', value: total })
|
||||||
|
} else {
|
||||||
|
pages.push({ type: 'page', value: 1 })
|
||||||
|
if (current > 2) {
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
}
|
||||||
|
pages.push({ type: 'page', value: current })
|
||||||
|
if (current < total - 1) {
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
}
|
||||||
|
pages.push({ type: 'page', value: total })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 只显示当前页和相邻页
|
// 大屏逻辑:显示更多页码
|
||||||
if (current === 1) {
|
if (total <= 7) {
|
||||||
pages.push({ type: 'page', value: 1 })
|
// 如果总页数小于等于7,显示所有页码
|
||||||
pages.push({ type: 'page', value: 2 })
|
for (let i = 1; i <= total; i++) {
|
||||||
pages.push({ type: 'ellipsis' })
|
pages.push({ type: 'page', value: i })
|
||||||
pages.push({ type: 'page', value: total })
|
}
|
||||||
} else if (current === total) {
|
|
||||||
pages.push({ type: 'page', value: 1 })
|
|
||||||
pages.push({ type: 'ellipsis' })
|
|
||||||
pages.push({ type: 'page', value: total - 1 })
|
|
||||||
pages.push({ type: 'page', value: total })
|
|
||||||
} else {
|
} else {
|
||||||
pages.push({ type: 'page', value: 1 })
|
// 复杂分页逻辑
|
||||||
if (current > 2) {
|
if (current <= 2) {
|
||||||
|
// 当前页在前面
|
||||||
|
for (let i = 1; i <= 3; i++) {
|
||||||
|
pages.push({ type: 'page', value: i })
|
||||||
|
}
|
||||||
pages.push({ type: 'ellipsis' })
|
pages.push({ type: 'ellipsis' })
|
||||||
}
|
pages.push({ type: 'page', value: total })
|
||||||
pages.push({ type: 'page', value: current })
|
} else if (current >= total - 3) {
|
||||||
if (current < total - 1) {
|
// 当前页在后面
|
||||||
|
pages.push({ type: 'page', value: 1 })
|
||||||
pages.push({ type: 'ellipsis' })
|
pages.push({ type: 'ellipsis' })
|
||||||
|
for (let i = total - 4; i <= total; i++) {
|
||||||
|
pages.push({ type: 'page', value: i })
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 当前页在中间
|
||||||
|
pages.push({ type: 'page', value: 1 })
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
for (let i = current - 1; i <= current + 1; i++) {
|
||||||
|
pages.push({ type: 'page', value: i })
|
||||||
|
}
|
||||||
|
pages.push({ type: 'ellipsis' })
|
||||||
|
pages.push({ type: 'page', value: total })
|
||||||
}
|
}
|
||||||
pages.push({ type: 'page', value: total })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user