UNPKG

vue-admin-core

Version:
116 lines (113 loc) 2.43 kB
import { defineComponent, computed, h } from 'vue'; import '../../../utils/index.mjs'; import { ElPagination } from 'element-plus'; import { scrollTo } from '../../../utils/scrollTo.mjs'; var Pagination = defineComponent({ name: "VacPagination", inheritAttrs: false, props: { total: { type: Number, default: 0 }, page: { type: Number, default: 1 }, limit: { type: Number, default: 10 }, pageSizes: { type: Array, default: () => [10, 20, 30, 50] }, // 移动端页码按钮的数量端默认值5 pagerCount: { type: Number, default: document.body.clientWidth < 992 ? 5 : 7 }, layout: { type: String, default: "total, sizes, prev, pager, next, jumper" }, background: { type: Boolean, default: true }, autoScroll: { type: Boolean, default: true }, hidden: { type: Boolean, default: false }, float: { type: String, default: "right" } }, emits: ["update:page", "update:limit", "pagination"], setup(props, { attrs, emit }) { const currentPage = computed({ get() { return props.page; }, set(val) { emit("update:page", val); } }); const pageSize = computed({ get() { return props.limit; }, set(val) { emit("update:limit", val); } }); function handleSizeChange(val) { if (currentPage.value * val > props.total) { currentPage.value = 1; } emit("pagination", { page: currentPage.value, limit: val }); if (props.autoScroll) { scrollTo(0, 800); } } function handleCurrentChange(val) { emit("pagination", { page: val, limit: pageSize.value }); if (props.autoScroll) { scrollTo(0, 800); } } return () => h("div", { class: ["pagination-container", { hidden: props.hidden }] }, { default: () => [ // @ts-ignore h(ElPagination, { ...attrs, ...props, currentPage: currentPage.value, pageSize: pageSize.value, onSizeChange: handleSizeChange, onCurrentChange: handleCurrentChange }) ] }); } }); export { Pagination as default }; //# sourceMappingURL=index.mjs.map