🌐 AI搜索 & 代理 主页
Skip to content

Commit 56cec84

Browse files
authored
chore(pagination): tweaks to pagination PR #4622
1 parent c0d5696 commit 56cec84

File tree

1 file changed

+81
-69
lines changed

1 file changed

+81
-69
lines changed

src/mixins/pagination.js

Lines changed: 81 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -225,22 +225,23 @@ export default {
225225
numberOfLinks = numberOfPages
226226
} else if (currentPage < limit - 1 && limit > ELLIPSIS_THRESHOLD) {
227227
// We are near the beginning of the page list
228-
if (!hideEllipsis) {
228+
if (!hideEllipsis || this.lastNumber) {
229229
showLastDots = true
230230
numberOfLinks = limit - 1
231231
}
232232
} else if (numberOfPages - currentPage + 2 < limit && limit > ELLIPSIS_THRESHOLD) {
233233
// We are near the end of the list
234-
if (!hideEllipsis) {
234+
if (!hideEllipsis || this.firstNumber) {
235235
numberOfLinks = limit - 1
236236
showFirstDots = true
237237
}
238238
startNumber = numberOfPages - numberOfLinks + 1
239239
} else {
240240
// We are somewhere in the middle of the page list
241-
if (limit > ELLIPSIS_THRESHOLD && !hideEllipsis) {
241+
if (limit > ELLIPSIS_THRESHOLD) {
242242
numberOfLinks = limit - 2
243-
showFirstDots = showLastDots = true
243+
showFirstDots = !!(!hideEllipsis || this.firstNumber)
244+
showLastDots = !!(!hideEllipsis || this.lastNumber)
244245
}
245246
startNumber = currentPage - Math.floor(numberOfLinks / 2)
246247
}
@@ -469,44 +470,8 @@ export default {
469470
)
470471
}
471472

472-
// Goto first page button bookend
473-
// Don't render button when `hideGotoEndButtons` is set or when
474-
// `firstNumber` is enabled and the first page is in the page list
475-
const $firstPageBtn =
476-
this.hideGotoEndButtons || (this.firstNumber && pageNumbers.indexOf(1) !== -1)
477-
? h()
478-
: makeEndBtn(
479-
1,
480-
this.labelFirstPage,
481-
'first-text',
482-
this.firstNumber ? '1' : this.firstText,
483-
this.firstClass,
484-
1,
485-
'bookend-goto-first'
486-
)
487-
488-
// Goto previous page button bookend
489-
const $prevPageBtn = makeEndBtn(
490-
currentPage - 1,
491-
this.labelPrevPage,
492-
'prev-text',
493-
this.prevText,
494-
this.prevClass,
495-
1,
496-
'bookend-goto-prev'
497-
)
498-
499-
// When `firstNumber` prop is set we move the previous page button
500-
// before the first page button
501-
buttons.push(
502-
...(this.firstNumber ? [$prevPageBtn, $firstPageBtn] : [$firstPageBtn, $prevPageBtn])
503-
)
504-
505-
// First Ellipsis Bookend
506-
buttons.push(showFirstDots ? makeEllipsis(false) : h())
507-
508-
// Individual page links
509-
this.pageList.forEach((page, idx) => {
473+
// Page button factory
474+
const makePageButton = (page, idx) => {
510475
const active = isActivePage(page.number) && !noCurrentPage
511476
// Active page will have tabindex of 0, or if no current page and first page button
512477
const tabIndex = disabled ? null : active || (noCurrentPage && idx === 0) ? '0' : '-1'
@@ -548,23 +513,72 @@ export default {
548513
},
549514
[this.normalizeSlot('page', scope) || btnContent]
550515
)
551-
buttons.push(
552-
h(
553-
'li',
554-
{
555-
key: `page-${page.number}`,
556-
staticClass: 'page-item',
557-
class: [{ disabled, active, 'flex-fill': fill }, page.classes, this.pageClass],
558-
attrs: { role: 'presentation' }
559-
},
560-
[inner]
561-
)
516+
return h(
517+
'li',
518+
{
519+
key: `page-${page.number}`,
520+
staticClass: 'page-item',
521+
class: [{ disabled, active, 'flex-fill': fill }, page.classes, this.pageClass],
522+
attrs: { role: 'presentation' }
523+
},
524+
[inner]
562525
)
526+
}
527+
528+
// Goto first page button bookend
529+
// Don't render button when `hideGotoEndButtons` is set or when
530+
// `firstNumber` is enabled and the first page is in the page list
531+
let $firstPageBtn = h()
532+
if (!this.firstNumber && !this.hideGotoEndButtons) {
533+
$firstPageBtn = makeEndBtn(
534+
1,
535+
this.labelFirstPage,
536+
'first-text',
537+
this.firstText,
538+
this.firstClass,
539+
1,
540+
'bookend-goto-first'
541+
)
542+
}
543+
buttons.push($firstPageBtn)
544+
545+
// Goto previous page button bookend
546+
const $prevPageBtn = makeEndBtn(
547+
currentPage - 1,
548+
this.labelPrevPage,
549+
'prev-text',
550+
this.prevText,
551+
this.prevClass,
552+
1,
553+
'bookend-goto-prev'
554+
)
555+
buttons.push($prevPageBtn)
556+
557+
// Page 1 button if this.firstNumber and ellipsis showing
558+
if (this.firstNumber && showFirstDots) {
559+
buttons.push(makePageButton({ number: 1, classes: '' }, 0))
560+
} else {
561+
buttons.push(h())
562+
}
563+
564+
// First Ellipsis Bookend
565+
buttons.push(showFirstDots ? makeEllipsis(false) : h())
566+
567+
// Individual page links
568+
this.pageList.forEach((page, idx) => {
569+
buttons.push(makePageButton(page, idx + (showFirstDots && this.firstNumber ? 1 : 0)))
563570
})
564571

565572
// Last ellipsis bookend
566573
buttons.push(showLastDots ? makeEllipsis(true) : h())
567574

575+
// Page N button if this.lastNumber and ellipsis showing
576+
if (this.lastNumber && showLastDots) {
577+
buttons.push(makePageButton({ number: numberOfPages, classes: '' }, -1))
578+
} else {
579+
buttons.push(h())
580+
}
581+
568582
// Goto next page button bookend
569583
const $nextPageBtn = makeEndBtn(
570584
currentPage + 1,
@@ -575,26 +589,24 @@ export default {
575589
numberOfPages,
576590
'bookend-goto-next'
577591
)
592+
buttons.push($nextPageBtn)
578593

579594
// Goto last page button bookend
580595
// Don't render button when `hideGotoEndButtons` is set or when
581596
// `lastNumber` is enabled and the last page is in the page list
582-
const $lastPageBtn =
583-
this.hideGotoEndButtons || (this.lastNumber && pageNumbers.indexOf(numberOfPages) !== -1)
584-
? h()
585-
: makeEndBtn(
586-
numberOfPages,
587-
this.labelLastPage,
588-
'last-text',
589-
this.lastNumber ? toString(numberOfPages) : this.lastText,
590-
this.lastClass,
591-
numberOfPages,
592-
'bookend-goto-last'
593-
)
594-
595-
// When `lastNumber` prop is set we move the next page button
596-
// after the last page button
597-
buttons.push(...(this.lastNumber ? [$lastPageBtn, $nextPageBtn] : [$nextPageBtn, $lastPageBtn]))
597+
let $lastPageBtn = h()
598+
if (!this.lastNumber && !this.hideGotoEndButtons) {
599+
$lastPageBtn = makeEndBtn(
600+
numberOfPages,
601+
this.labelLastPage,
602+
'last-text',
603+
this.lastText,
604+
this.lastClass,
605+
numberOfPages,
606+
'bookend-goto-last'
607+
)
608+
}
609+
buttons.push($lastPageBtn)
598610

599611
// Assemble the pagination buttons
600612
const pagination = h(

0 commit comments

Comments
 (0)