You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
LiaoNingDangAn/src/components/Pagination/index.vue

129 lines
2.6 KiB

2 years ago
<template>
2 years ago
<div :class="{ hidden: hidden }" class="paginBox">
<div class="leftBox">
总共{{ this.total }} :显示{{
this.currentPage == 1 ? "1" : (this.currentPage - 1) * this.pageSize
}}-{{
this.total <= this.pageSize
? this.total
: this.currentPage * this.pageSize > this.total
? this.total
: this.currentPage * this.pageSize
}}
</div>
<div class="rightBox">
<el-pagination
:background="background"
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="layout"
:page-sizes="pageSizes"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
2 years ago
</div>
</template>
<script>
2 years ago
import { scrollTo } from "@/utils/scroll-to";
2 years ago
export default {
2 years ago
name: "Pagination",
2 years ago
props: {
total: {
required: true,
2 years ago
type: Number,
2 years ago
},
page: {
type: Number,
2 years ago
default: 1,
2 years ago
},
limit: {
type: Number,
2 years ago
default: 20,
2 years ago
},
pageSizes: {
type: Array,
default() {
2 years ago
return [10, 20, 30, 50];
},
2 years ago
},
// 移动端页码按钮的数量端默认值5
2 years ago
// pagerCount: {
// type: Number,
// default: document.body.clientWidth < 992 ? 5 : 7
// },
2 years ago
layout: {
type: String,
2 years ago
default: " sizes, prev, pager, next, jumper",
2 years ago
},
background: {
type: Boolean,
2 years ago
default: true,
2 years ago
},
autoScroll: {
type: Boolean,
2 years ago
default: true,
2 years ago
},
hidden: {
type: Boolean,
2 years ago
default: false,
},
2 years ago
},
data() {
2 years ago
return {};
2 years ago
},
computed: {
currentPage: {
get() {
2 years ago
return this.page;
2 years ago
},
set(val) {
2 years ago
this.$emit("update:page", val);
},
2 years ago
},
pageSize: {
get() {
2 years ago
return this.limit;
2 years ago
},
set(val) {
2 years ago
this.$emit("update:limit", val);
},
},
2 years ago
},
methods: {
handleSizeChange(val) {
if (this.currentPage * val > this.total) {
2 years ago
this.currentPage = 1;
2 years ago
}
2 years ago
this.$emit("pagination", { page: this.currentPage, limit: val });
2 years ago
if (this.autoScroll) {
2 years ago
scrollTo(0, 800);
2 years ago
}
},
handleCurrentChange(val) {
2 years ago
this.$emit("pagination", { page: val, limit: this.pageSize });
2 years ago
if (this.autoScroll) {
2 years ago
scrollTo(0, 800);
2 years ago
}
2 years ago
},
},
};
2 years ago
</script>
<style scoped>
2 years ago
.paginBox {
display: flex;
justify-content: space-between;
align-items: center;
margin-top: 10px;
2 years ago
}
2 years ago
2 years ago
.pagination-container.hidden {
display: none;
}
</style>