This commit is contained in:
2026-08-21 17:20:40 +08:00
parent 465be7c8f3
commit c972ad408a
14 changed files with 504 additions and 118 deletions
+9 -5
View File
@@ -30,6 +30,13 @@ export function normalizePage(value: number, pageCount: number) {
return Math.min(Math.max(Math.trunc(value), 1), maximum)
}
export function normalizeTotal(value: unknown) {
const numericValue = typeof value === 'string' && value.trim() !== '' ? Number(value) : value
return typeof numericValue === 'number' && Number.isFinite(numericValue) && numericValue > 0
? Math.trunc(numericValue)
: 0
}
export function createPaginationItems(page: number, pageCount: number): PaginationItem[] {
if (pageCount <= 0) return []
if (pageCount <= 7) return Array.from({ length: pageCount }, (_, index) => index + 1)
@@ -60,7 +67,7 @@ const props = withDefaults(defineProps<{
columns: DataTableColumn[]
loading?: boolean
emptyText?: string
total?: number
total?: number | string
pageSizes?: number[]
preferenceKey?: string
columnSettingsMode?: 'auto' | 'show' | 'hide'
@@ -208,10 +215,7 @@ function resetPreference() {
watch(visibleColumns, () => {
void nextTick(() => tableRef.value?.doLayout())
})
const normalizedTotal = computed(() => {
const value = props.total ?? 0
return Number.isFinite(value) && value > 0 ? Math.trunc(value) : 0
})
const normalizedTotal = computed(() => normalizeTotal(props.total))
const normalizedPageSizes = computed(() => normalizePageSizes(props.pageSizes))
const effectivePageSize = computed(() => (
normalizedPageSizes.value.includes(pageSize.value) ? pageSize.value : normalizedPageSizes.value[0]