Files
FileCodeBoxFronted2026/src/components/common/DataPagination.vue
T
orion 9b22534e2b ✨ feat: 重构管理后台并增强组件系统与回收站功能
* 新增自适应数值与窗口分析工具,提升交互体验
* 优化回收站模块逻辑,增加展示与选择功能
* 引入 Macaron 主题配置文件并更新 Tailwind 配置
* 精简基础组件代码,移除冗余样式与设置项
* 完善测试用例,覆盖 UI 系统与回收站工作流
* 更新多语言配置,支持功能变更后的文案需求
2026-09-18 10:18:07 +08:00

131 lines
5.2 KiB
Vue

<template>
<nav
class="fcb-pagination mt-3 flex flex-col gap-2 border-t px-3 py-3 sm:flex-row sm:items-center sm:justify-between sm:px-6"
:class="[isDarkMode ? 'border-[#495765]' : 'border-[#c8d7da]']"
:aria-label="t('components.pagination.navigation')"
>
<div class="text-xs sm:text-sm" :class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']">
{{ t('components.pagination.range', { start: rangeStart, end: rangeEnd, total }) }}
</div>
<div class="fcb-pagination-controls grid grid-cols-[minmax(0,1fr)_auto_auto_auto] items-center gap-2 sm:flex sm:flex-wrap">
<select
:value="pageSize"
class="fcb-page-size min-h-9 rounded-2xl border px-3 text-sm shadow-sm transition-colors lg:min-h-9"
:class="[
isDarkMode
? 'border-[#495765] bg-[#2c3440] text-[#d8e3e5] hover:border-[#7199a8]'
: 'border-[#c8d8dc] bg-[#edf4f5] text-[#415d66] hover:border-[#9db6bd]'
]"
:aria-label="t('components.pagination.pageSize')"
@change="$emit('page-size-change', Number(($event.target as HTMLSelectElement).value))"
>
<option v-for="size in pageSizeOptions" :key="size" :value="size">
{{ t('components.pagination.perPage', { size }) }}
</option>
</select>
<button
type="button"
:disabled="currentPage === 1"
class="fcb-action fcb-page-nav inline-flex min-h-11 items-center justify-center rounded-2xl px-3 py-1.5 shadow-sm transition-all duration-200 hover:shadow-md lg:min-h-9"
:class="buttonClass(currentPage === 1)"
@click="$emit('page-change', currentPage - 1)"
>
<ChevronLeftIcon class="h-4 w-4" aria-hidden="true" />
<span class="sr-only sm:not-sr-only">{{ t('common.previous') }}</span>
</button>
<span class="fcb-page-counter text-center text-sm font-medium tabular-nums sm:hidden" :class="[isDarkMode ? 'text-gray-200' : 'text-gray-700']">
{{ currentPage }} / {{ totalPages }}
</span>
<div class="hidden items-center gap-1 sm:flex">
<template v-for="pageNum in displayedPages" :key="pageNum">
<button
v-if="pageNum !== '...'"
type="button"
class="fcb-action inline-flex min-h-11 min-w-11 items-center justify-center rounded-2xl px-3 py-1.5 shadow-sm transition-all duration-200 hover:shadow-md lg:min-h-9 lg:min-w-9"
:class="[
currentPage === pageNum
? 'bg-[#5f8796] text-white shadow-[#9fb8bf]/35'
: isDarkMode
? 'bg-[#2c3440] text-[#d8e3e5] hover:bg-[#384452]'
: 'bg-[#edf4f5] text-[#415d66] hover:bg-[#e2ecee]'
]"
:aria-label="t('components.pagination.goToPage', { page: pageNum })"
:aria-current="currentPage === pageNum ? 'page' : undefined"
@click="$emit('page-change', pageNum as number)"
>
{{ pageNum }}
</button>
<span v-else class="px-1" :class="[isDarkMode ? 'text-gray-300' : 'text-gray-600']">…</span>
</template>
</div>
<button
type="button"
:disabled="currentPage >= totalPages"
class="fcb-action fcb-page-nav inline-flex min-h-11 items-center justify-center rounded-2xl px-3 py-1.5 shadow-sm transition-all duration-200 hover:shadow-md lg:min-h-9"
:class="buttonClass(currentPage >= totalPages)"
@click="$emit('page-change', currentPage + 1)"
>
<span class="sr-only sm:not-sr-only">{{ t('common.next') }}</span>
<ChevronRightIcon class="h-4 w-4" aria-hidden="true" />
</button>
</div>
</nav>
</template>
<script setup lang="ts">
import { computed, inject, type Ref } from 'vue'
import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-vue-next'
import { useI18n } from 'vue-i18n'
interface Props {
currentPage: number
pageSize: number
total: number
pageSizeOptions?: number[]
}
const props = withDefaults(defineProps<Props>(), {
pageSizeOptions: () => [5, 10, 20, 50, 100]
})
defineEmits<{
'page-change': [page: number]
'page-size-change': [size: number]
}>()
const isDarkMode = inject<Ref<boolean>>('isDarkMode', computed(() => false))
const { t } = useI18n()
const totalPages = computed(() => Math.max(1, Math.ceil(props.total / props.pageSize)))
const rangeStart = computed(() => (props.total ? (props.currentPage - 1) * props.pageSize + 1 : 0))
const rangeEnd = computed(() => Math.min(props.currentPage * props.pageSize, props.total))
const displayedPages = computed(() => {
const current = props.currentPage
const total = totalPages.value
const pages: (number | string)[] = [1]
const left = Math.max(2, current - 2)
const right = Math.min(total - 1, current + 2)
if (left > 2) pages.push('...')
for (let i = left; i <= right; i++) pages.push(i)
if (right < total - 1) pages.push('...')
if (total > 1) pages.push(total)
return pages
})
const buttonClass = (disabled: boolean) => {
if (isDarkMode.value) {
return disabled
? 'cursor-not-allowed bg-[#223039] text-[#71878d]'
: 'bg-[#2c3440] text-[#d8e3e5] hover:bg-[#384452]'
}
return disabled
? 'cursor-not-allowed bg-[#e8eeee] text-[#7d8d91]'
: 'bg-[#edf4f5] text-[#415d66] hover:bg-[#e2ecee]'
}
</script>