123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import { scrollAnimation } from '@/util/scroll'
- import { ElPagination } from 'element-plus'
- import { defineComponent } from 'vue'
- import styles from './index.module.less'
- export default defineComponent({
- name: 'pagination',
- props: {
- total: {
- required: true,
- type: Number
- },
- page: {
- type: Number,
- default: 1
- },
- limit: {
- type: Number,
- default: 10
- },
- pageSizes: {
- type: Array,
- default: [5, 10, 20, 30, 50]
- },
- // , jumper
- layout: {
- type: String,
- default: 'total, sizes, prev, pager, next'
- },
- showMuitiple: {
- type: Number,
- default: 10
- },
- hideOnSinglePage: {
- type: Boolean,
- default: true
- },
- background: {
- type: Boolean,
- default: true
- },
- autoScroll: {
- type: Boolean,
- default: true
- },
- hidden: {
- type: Boolean,
- default: false
- },
- sync: {
- type: Boolean,
- default: false
- },
- saveKey: {
- type: String,
- default: ''
- },
- pagination: {
- type: Function,
- default: () => {}
- }
- },
- methods: {
- handleSizeChange(val: number) {
- this.$emit('update:page', 1)
- this.$emit('update:limit', val)
- this.pagination()
- if (this.autoScroll) {
- const currentY =
- document.documentElement.scrollTop || document.body.scrollTop
- scrollAnimation(currentY, 0)
- }
- },
- handleCurrentChange(val: number) {
- this.$emit('update:page', val)
- this.$emit('update:limit', this.limit)
- this.pagination()
- if (this.autoScroll) {
- const currentY =
- document.documentElement.scrollTop || document.body.scrollTop
- scrollAnimation(currentY, 0)
- }
- }
- },
- render() {
- return (
- <div
- class={[styles['pagination-container'], this.hidden && styles.hidden]}
- >
- <ElPagination
- currentPage={this.page}
- pageSize={this.limit}
- // @ts-ignore
- onUpdate:currentPage={(val: number) => {}}
- onUpdate:pageSize={(val: number) => {
- this.handleSizeChange(val)
- }}
- pageSizes={this.pageSizes as number[]}
- total={this.total}
- hideOnSinglePage={
- this.total > this.showMuitiple ? false : this.hideOnSinglePage
- }
- background={this.background}
- layout={this.layout}
- onSise-change={this.handleSizeChange}
- onCurrent-change={this.handleCurrentChange}
- />
- </div>
- )
- }
- })
|