2016-07-27 06:15:02 +00:00
|
|
|
<template>
|
2016-07-29 09:46:16 +00:00
|
|
|
<ul @click="onPagerClick" class="el-pager">
|
2016-07-27 06:15:02 +00:00
|
|
|
<li
|
|
|
|
:class="{ active: currentPage === 1 }"
|
|
|
|
v-if="pageCount > 0"
|
|
|
|
class="number">1</li>
|
|
|
|
<li
|
2016-07-29 09:46:16 +00:00
|
|
|
class="el-icon ellipsis btn-quickprev"
|
|
|
|
:class="[quickprevIconClass]"
|
2016-07-27 06:15:02 +00:00
|
|
|
v-if="showPrevMore"
|
|
|
|
@mouseenter="quickprevIconClass = 'el-icon-d-arrow-left'"
|
|
|
|
@mouseleave="quickprevIconClass = 'el-icon-ellipsis'"
|
|
|
|
>
|
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
v-for="pager in pagers"
|
2016-07-29 09:46:16 +00:00
|
|
|
:class="{ active: currentPage === pager }"
|
2016-07-27 06:15:02 +00:00
|
|
|
class="number">{{ pager }}</li>
|
|
|
|
<li
|
2016-07-29 09:46:16 +00:00
|
|
|
class="el-icon ellipsis btn-quicknext"
|
|
|
|
:class="[quicknextIconClass]"
|
2016-07-27 06:15:02 +00:00
|
|
|
v-if="showNextMore"
|
|
|
|
@mouseenter="quicknextIconClass = 'el-icon-d-arrow-right'"
|
|
|
|
@mouseleave="quicknextIconClass = 'el-icon-ellipsis'"
|
|
|
|
>
|
|
|
|
</li>
|
|
|
|
<li
|
|
|
|
:class="{ active: currentPage === pageCount }"
|
|
|
|
class="number"
|
|
|
|
v-if="pageCount > 1">{{ pageCount }}</li>
|
|
|
|
</ul>
|
|
|
|
</template>
|
|
|
|
|
2016-07-29 09:46:16 +00:00
|
|
|
<script type="text/babel">
|
2016-07-27 06:15:02 +00:00
|
|
|
export default {
|
|
|
|
name: 'ElPager',
|
|
|
|
|
|
|
|
props: {
|
|
|
|
currentPage: Number,
|
|
|
|
|
|
|
|
pageCount: Number
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
onPagerClick(event) {
|
|
|
|
const target = event.target;
|
|
|
|
if (target.tagName === 'UL') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let newPage = Number(event.target.textContent);
|
|
|
|
const pageCount = this.pageCount;
|
|
|
|
const currentPage = this.currentPage;
|
|
|
|
|
|
|
|
if (target.className.indexOf('ellipsis') !== -1) {
|
|
|
|
if (target.className.indexOf('quickprev') !== -1) {
|
|
|
|
newPage = currentPage - 5;
|
|
|
|
} else if (target.className.indexOf('quicknext') !== -1) {
|
|
|
|
newPage = currentPage + 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isNaN(newPage)) {
|
|
|
|
if (newPage < 1) {
|
|
|
|
newPage = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPage > pageCount) {
|
|
|
|
newPage = pageCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newPage !== currentPage) {
|
2016-07-29 09:46:16 +00:00
|
|
|
this.$emit('currentChange', newPage);
|
2016-07-27 06:15:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
|
|
|
pagers() {
|
|
|
|
const pagerCount = 7;
|
|
|
|
|
|
|
|
const currentPage = Number(this.currentPage);
|
|
|
|
const pageCount = Number(this.pageCount);
|
|
|
|
|
|
|
|
let showPrevMore = false;
|
|
|
|
let showNextMore = false;
|
|
|
|
|
|
|
|
if (pageCount > pagerCount) {
|
|
|
|
if (currentPage > pagerCount - 2) {
|
|
|
|
showPrevMore = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (currentPage < pageCount - 2) {
|
|
|
|
showNextMore = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const array = [];
|
|
|
|
|
|
|
|
if (showPrevMore && !showNextMore) {
|
|
|
|
const startPage = pageCount - (pagerCount - 2);
|
|
|
|
for (let i = startPage; i < pageCount; i++) {
|
|
|
|
array.push(i);
|
|
|
|
}
|
|
|
|
} else if (!showPrevMore && showNextMore) {
|
|
|
|
for (let i = 2; i < pagerCount; i++) {
|
|
|
|
array.push(i);
|
|
|
|
}
|
|
|
|
} else if (showPrevMore && showNextMore) {
|
|
|
|
const offset = Math.floor(pagerCount / 2) - 1;
|
|
|
|
for (let i = currentPage - offset ; i <= currentPage + offset; i++) {
|
|
|
|
array.push(i);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (let i = 2; i < pageCount; i++) {
|
|
|
|
array.push(i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
this.showPrevMore = showPrevMore;
|
|
|
|
this.showNextMore = showNextMore;
|
|
|
|
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
current: null,
|
|
|
|
showPrevMore: false,
|
|
|
|
showNextMore: false,
|
|
|
|
quicknextIconClass: 'el-icon-ellipsis',
|
|
|
|
quickprevIconClass: 'el-icon-ellipsis'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
</script>
|