[修复]LayPage页码起止范围计算问题

This commit is contained in:
castle 2021-12-28 10:45:09 +08:00
parent 32b30edff1
commit e50ef83e83
2 changed files with 7 additions and 11 deletions

View File

@ -129,7 +129,7 @@ export default {
::: demo
<template>
<lay-page :limit="limit" :total="total" :limits="[10,50,100,200]"></lay-page>
<lay-page :limit="limit" :total="total" showCount showPage :limits="[10,50,100,200]" @limit="limit=$event"></lay-page>
</template>
<script>
@ -157,7 +157,7 @@ export default {
::: demo
<template>
<lay-page :limit="limit" :total="total" @limit="limit=$event" :show-limit="showLimit" ></lay-page>
<lay-page :limit="limit" showPage showCount :total="total" @limit="limit=$event" :show-limit="showLimit" ></lay-page>
<div>每页数量:{{limit}}</div>
</template>

View File

@ -87,15 +87,11 @@ const pages = props.pages / 2
const inlimit = computed({ get() { return props.limit }, set(v: number) { emit('limit', v) } })
const maxPage = ref(Math.ceil(props.total / props.limit));
const totalPage = computed(() => {
let r: number[] = [], end = maxPage.value
if (currentPage.value <= pages) {
end = props.pages + 1
} else if (currentPage.value + pages > end) {
} else {
end = currentPage.value + pages
let r: number[] = [], start = (maxPage.value <= props.pages ? 1 : currentPage.value > pages ? currentPage.value - pages : 1)
for (let i = start; ; i++) {
if (r.length >= props.pages || i > maxPage.value) {
break;
}
for (let i = currentPage.value > pages ? currentPage.value - pages : 1; i < end; i++) {
r.push(i)
}
return r;