diff --git a/packages/opendesign/src/pagination/OPagination.vue b/packages/opendesign/src/pagination/OPagination.vue index ed612eb28c3bd7083740e2fa39c63cbcb14c1d19..a5fb5148436295393c498c78c505729db3c2bd5f 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!, }); }); };