forked from wudengyao/admin_vue3_vite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,108 +1,114 @@ | ||
<template> | ||
<div :class="{ 'hidden': hidden }" class="pagination-container"> | ||
<div :class="{'hidden':hidden}" class="pagination-container"> | ||
<el-pagination | ||
v-model:current-page="currentPage" | ||
v-model:page-size="pageSize" | ||
:background="background" | ||
:current-page.sync="currentPage" | ||
:page-size.sync="pageSize" | ||
:layout="layout" | ||
:page-sizes="pageSizes" | ||
:pager-count="pagerCount" | ||
:total="total" | ||
v-bind="$attrs" | ||
@size-change="handleSizeChange" | ||
@current-change="handleCurrentChange" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style scoped> | ||
.pagination-container { | ||
display: flex; | ||
justify-content: end; | ||
margin-top: 20px; | ||
background: #fff; | ||
} | ||
.pagination-container.hidden { | ||
display: none; | ||
} | ||
</style> | ||
.pagination-container { | ||
padding: 32px 16px; | ||
background: #fff; | ||
} | ||
.pagination-container.hidden { | ||
display: none; | ||
} | ||
</style> | ||
|
||
<script setup> | ||
<script> | ||
import { scrollTo } from "@/utils/scroll-to"; | ||
import { computed } from "vue"; | ||
const props = defineProps( | ||
total: { | ||
required: true, | ||
type: Number, | ||
export default { | ||
name: "pagination", | ||
props: { | ||
total: { | ||
required: true, | ||
type: Number | ||
}, | ||
page: { | ||
type: Number, | ||
default: 1 | ||
}, | ||
limit: { | ||
type: Number, | ||
default: 20 | ||
}, | ||
pageSizes: { | ||
type: Array, | ||
default() { | ||
return [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 | ||
} | ||
}, | ||
page: { | ||
type: Number, | ||
default: 1 | ||
data() { | ||
return { | ||
}; | ||
}, | ||
limit: { | ||
type: Number, | ||
default: 20 | ||
computed: { | ||
currentPage: { | ||
get() { | ||
return this.page; | ||
}, | ||
set(val) { | ||
this.$emit("update:page", val); | ||
} | ||
}, | ||
pageSize: { | ||
get() { | ||
return this.limit; | ||
}, | ||
set(val) { | ||
this.$emit("update:limit", val); | ||
} | ||
} | ||
}, | ||
pageSizes: { | ||
type: Array, | ||
default() { | ||
return [10, 20, 30, 40, 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 | ||
} | ||
}); | ||
const emit = defineEmits(); | ||
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; | ||
methods: { | ||
handleSizeChange(val) { | ||
if (this.currentPage * val > this.total) { | ||
this.currentPage = 1; | ||
} | ||
this.$emit("pagination", { page: this.currentPage, limit: val }); | ||
if (this.autoScroll) { | ||
scrollTo(0, 800); | ||
} | ||
}, | ||
handleCurrentChange(val) { | ||
this.$emit("pagination", { page: val, limit: this.pageSize }); | ||
if (this.autoScroll) { | ||
scrollTo(0, 800); | ||
} | ||
} | ||
} | ||
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); | ||
} | ||
} | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters