pager.vue
3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<template>
<span class="v-page-pager">
<li @click.stop.prevent="jumpPage(1)" :class='[pageIndex === 1 ? "v-page-li-active":"","v-page-li"]'><a>1</a></li>
<li @click.stop.prevent="jumpPage(pageIndex - showPagingCount)" v-if="showJumpPrev"
:class="[pageIndex=== 1 ? 'disabled' :'','v-page-li','v-page-jump-prev']"
:title="'向前 '+showPagingCount+' 页'">
<a><i class="v-icon-angle-double-left"></i></a>
</li>
<li v-for="num in pagingCounts" @click.stop.prevent="jumpPage(num)"
:class='[num === pageIndex ? "v-page-li-active":"","v-page-li"]'><a>{{num}}</a></li>
<li @click.stop.prevent="jumpPage(pageIndex + showPagingCount)" v-if="showJumpNext"
class="v-page-li v-page-jump-next" :title="'向后 '+showPagingCount+' 页'"><a><i
class="v-icon-angle-double-right"></i></a>
<li v-if="pageCount >1" @click.stop.prevent="jumpPage(pageCount)"
:class='[pageIndex === pageCount ? "v-page-li-active":"","v-page-li"]'><a>{{pageCount}}</a></li>
</span>
</template>
<script>
export default{
props: {
pageCount: Number,
pageIndex: Number,
showPagingCount: Number
},
computed: {
numOffset(){
return Math.floor((this.showPagingCount + 2) / 2) - 1;
},
showJumpPrev(){
if (this.pageCount > this.showPagingCount + 2) {
if (this.pageIndex > this.showPagingCount) {
return true
}
}
return false
},
showJumpNext(){
if (this.pageCount > this.showPagingCount + 2) {
//if (this.pageIndex < this.pageCount - this.numOffset) {
if (this.pageIndex <= this.pageCount -this.showPagingCount) {
return true
}
}
return false
},
// 当前要显示的数字按钮集合
pagingCounts(){
let vm = this,
startNum,
result = [],
showJumpPrev = vm.showJumpPrev,
showJumpNext = vm.showJumpNext;
if (showJumpPrev && !showJumpNext) {
startNum = vm.pageCount - vm.showPagingCount;
for (let i = startNum; i < vm.pageCount; i++) {
result.push(i);
}
} else if (!showJumpPrev && showJumpNext) {
for (let i = 2; i < vm.showPagingCount + 2; i++) {
result.push(i);
}
} else if (showJumpPrev && showJumpNext) {
for (let i = vm.pageIndex - vm.numOffset; i <= vm.pageIndex + vm.numOffset; i++) {
result.push(i);
}
} else {
for (let i = 2; i < vm.pageCount; i++) {
result.push(i);
}
}
return result
}
},
methods: {
jumpPage(pageIndex){
this.$emit('jumpPageHandler', pageIndex)
},
},
created(){
}
}
</script>