From 92806b68b41747a288209b3282a8568ee7152ebb Mon Sep 17 00:00:00 2001 From: AC-0308 Date: Sat, 30 Nov 2024 21:05:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(pagination):=20=E4=BF=AE=E5=A4=8DPagination?= =?UTF-8?q?=E7=9A=84pageSize=E5=8F=8C=E5=90=91=E7=BB=91=E5=AE=9A=E3=80=81?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E4=BA=86=E4=BC=A0=E5=85=A5pageSize=E4=B8=8D?= =?UTF-8?q?=E5=86=8D=E5=88=86=E9=A1=B5=E6=95=B0=E7=BB=84=E4=B8=AD=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E8=A1=A8=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../opendesign/src/pagination/OPagination.vue | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/packages/opendesign/src/pagination/OPagination.vue b/packages/opendesign/src/pagination/OPagination.vue index ed612eb2..a5fb5148 100644 --- a/packages/opendesign/src/pagination/OPagination.vue +++ b/packages/opendesign/src/pagination/OPagination.vue @@ -14,6 +14,14 @@ import { useI18n } from '../locale'; import { OVirtualList } from '../virtual-list'; const props = defineProps(paginationProps); +const currentPageSize = defineModel('pageSize' ); +if (currentPageSize.value === undefined || !props.pageSizes.includes(currentPageSize.value) ) { + if (currentPageSize.value !== undefined ) { + console.warn(`pageSize ${currentPageSize.value} 不在pageSizes ${props.pageSizes} 可选项中,自动替换成可选项第一位`); + } + currentPageSize.value = props.pageSizes[0]; +} + const round = getRoundClass(props, 'pagination'); @@ -26,12 +34,10 @@ const emits = defineEmits<{ const { t } = useI18n(); const simpleLayout = ['pager']; - -let currentPageSize = ref(props.pageSize || props.pageSizes[0]); let currentPage = ref(Math.round(props.page)); const pageSizeList = computed(() => { - return getSizeOptions(currentPageSize.value, props.pageSizes, t('pagination.countPerPage')); + return getSizeOptions(currentPageSize.value!, props.pageSizes, t('pagination.countPerPage')); }); const defaultSizeLabel = computed(() => currentPageSize.value + t('pagination.countPerPage')); @@ -40,7 +46,7 @@ const layout = computed(() => { return props.simple ? simpleLayout : props.layout; }); -const totalPage = computed(() => Math.ceil(props.total / currentPageSize.value)); +const totalPage = computed(() => Math.ceil(props.total / currentPageSize.value!)); const pages = ref(getPagerList(totalPage.value, currentPage.value, props.showPageCount)); @@ -71,7 +77,7 @@ const updateCurrentPage = (page: number) => { emits('update:page', currentPage.value); emits('change', { page: currentPage.value, - pageSize: currentPageSize.value, + pageSize: currentPageSize.value!, }); }; @@ -115,21 +121,20 @@ const parseJumperVal = (val: string | number) => { const pageSizeChange = (val: SelectValueT) => { // updateCurrentPage(Number(val)); - const currentIndex = currentPageSize.value * (currentPage.value - 1); + const currentIndex = currentPageSize.value! * (currentPage.value - 1); const oldPage = currentPage.value; currentPageSize.value = Number(val); nextTick(() => { - currentPage.value = Math.floor(currentIndex / currentPageSize.value) + 1; + currentPage.value = Math.floor(currentIndex / currentPageSize.value!) + 1; pages.value = getPagerList(totalPage.value, currentPage.value, props.showPageCount); if (oldPage !== currentPage.value) { emits('update:page', currentPage.value); } - emits('update:pageSize', currentPageSize.value); emits('change', { page: currentPage.value, - pageSize: currentPageSize.value, + pageSize: currentPageSize.value!, }); }); }; -- Gitee