|
|
@@ -1,65 +1,49 @@
|
|
|
<template>
|
|
|
<div class="pagination-wrapper">
|
|
|
- <div class="pagination">
|
|
|
- <span class="pagination__arrow icon" @click="handleChange({ page: page - 1 })"><</span>
|
|
|
- <span
|
|
|
- :class="{ 'pagination__page': true, '--active': page === 1 }"
|
|
|
- @click="handleChange({ page: 1 })"
|
|
|
- >1</span>
|
|
|
- <span
|
|
|
- v-if="hasLeftDot"
|
|
|
- class="pagination__hidden-arrow"
|
|
|
- @click="handleChange({ page: page - SHOW_PAGE_NUM })"
|
|
|
- >
|
|
|
- <span class="icon">
|
|
|
- 《
|
|
|
- </span>
|
|
|
- <span class="pagination__hidden-ellipsis">•••</span>
|
|
|
- </span>
|
|
|
- <span
|
|
|
+ <div class="pagination mt-16">
|
|
|
+ <c-button :theme="theme" :size="32" :left="12" :right="4" @click="handleChange({ page: page - 1 })">
|
|
|
+ <c-icon bold :theme="theme" :size="16">keyboard_arrow_left</c-icon>
|
|
|
+ </c-button>
|
|
|
+ <c-button text :theme="theme" @click="handleChange({ page: 1 })" :standout="page === 1">1</c-button>
|
|
|
+ <c-button :theme="theme" class="hidden-arrow-left" v-if="hasLeftDot" :size="32" :left="4" :right="4"
|
|
|
+ @click="handleChange({ page: page - SHOW_PAGE_NUM })">
|
|
|
+ <c-icon :theme="theme" :size="18">skip_previous</c-icon>
|
|
|
+ </c-button>
|
|
|
+ <c-button
|
|
|
+ :theme="theme" text :standout="page === item"
|
|
|
v-for="item in centerPages"
|
|
|
- :key="item"
|
|
|
- :class="{ 'pagination__page': true, '--active': page === item }"
|
|
|
+ :key="item" :right="4" :left="4"
|
|
|
@click="handleChange({ page: item })"
|
|
|
- >{{ item }}</span>
|
|
|
- <span
|
|
|
- v-if="hasRightDot"
|
|
|
- class="pagination__hidden-arrow --right"
|
|
|
- @click="handleChange({ page: page + SHOW_PAGE_NUM })"
|
|
|
- >
|
|
|
- <span class="icon">
|
|
|
- 《
|
|
|
- </span>
|
|
|
- <span class="pagination__hidden-ellipsis">•••</span>
|
|
|
- </span>
|
|
|
- <span
|
|
|
- v-if="totalPage > 1"
|
|
|
- :class="{ 'pagination__page': true, '--active': page === totalPage }"
|
|
|
- @click="handleChange({ page: totalPage })"
|
|
|
- >{{ totalPage }}</span>
|
|
|
- <span
|
|
|
- class="pagination__arrow --right icon"
|
|
|
- @click="handleChange({ page: page + 1 })"
|
|
|
- ><</span>
|
|
|
+ >{{ item }}
|
|
|
+ </c-button>
|
|
|
+ <c-button :theme="theme" class="hidden-arrow-left" v-if="hasRightDot" :size="32" :left="4" :right="4"
|
|
|
+ @click="handleChange({ page: page + SHOW_PAGE_NUM })">
|
|
|
+ <c-icon :theme="theme" :size="18">skip_next</c-icon>
|
|
|
+ </c-button>
|
|
|
+ <c-button text :theme="theme" @click="handleChange({ page: totalPage })" :standout="page === totalPage">
|
|
|
+ {{ totalPage }}
|
|
|
+ </c-button>
|
|
|
+ <c-button :theme="theme" :size="32" :right="20" :left="4" @click="handleChange({ page: page + 1 })">
|
|
|
+ <c-icon :theme="theme" bold :size="16">keyboard_arrow_right</c-icon>
|
|
|
+ </c-button>
|
|
|
</div>
|
|
|
- <div class="pagination-input">
|
|
|
- <input
|
|
|
- v-model="inputPage"
|
|
|
- class="search-input"
|
|
|
- style="width: 50px; margin-right: 5px"
|
|
|
- @keypress="handlePageInputEvent"
|
|
|
- />
|
|
|
- <span>of {{ totalPage }}</span>
|
|
|
+ <div class="mt-16">
|
|
|
+ <c-input v-model="inputPage" class="page-input" @keypress="handlePageInputEvent"></c-input>
|
|
|
+ <span>/ {{ totalPage }}</span>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import iconMap from '@/utils/icon-map'
|
|
|
+import CButton from '@/components/Basic/CButton'
|
|
|
+import CIcon from '@/components/Basic/CIcon'
|
|
|
+import CInput from '@/components/Basic/CInput'
|
|
|
|
|
|
const SHOW_PAGE_NUM = 3
|
|
|
|
|
|
export default {
|
|
|
+ components: { CInput, CIcon, CButton },
|
|
|
props: {
|
|
|
page: {
|
|
|
default: 1,
|
|
|
@@ -72,9 +56,13 @@ export default {
|
|
|
totalElements: {
|
|
|
type: Number,
|
|
|
default: 0
|
|
|
+ },
|
|
|
+ theme: {
|
|
|
+ type: String,
|
|
|
+ default: 'blue'
|
|
|
}
|
|
|
},
|
|
|
- data() {
|
|
|
+ data () {
|
|
|
return {
|
|
|
inputPage: String(this.page),
|
|
|
iconMap,
|
|
|
@@ -82,25 +70,27 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
- totalPage() {
|
|
|
+ totalPage () {
|
|
|
return Math.ceil(this.totalElements / this.size)
|
|
|
},
|
|
|
- hasLeftDot() {
|
|
|
+ hasLeftDot () {
|
|
|
return this.page >= SHOW_PAGE_NUM && this.totalPage >= SHOW_PAGE_NUM + 2
|
|
|
},
|
|
|
- hasRightDot() {
|
|
|
+ hasRightDot () {
|
|
|
return (
|
|
|
this.page <= this.totalPage - (SHOW_PAGE_NUM - 1) &&
|
|
|
this.totalPage >= SHOW_PAGE_NUM + 2
|
|
|
)
|
|
|
},
|
|
|
- centerPages() {
|
|
|
+ centerPages () {
|
|
|
const theCenter =
|
|
|
this.page < ((SHOW_PAGE_NUM + 1) / 2)
|
|
|
? ((SHOW_PAGE_NUM + 1) / 2)
|
|
|
- : this.page > this.totalPage - 2
|
|
|
- ? this.totalPage - 2
|
|
|
- : this.page
|
|
|
+ : (
|
|
|
+ this.page > this.totalPage - 2
|
|
|
+ ? this.totalPage - 2
|
|
|
+ : this.page
|
|
|
+ )
|
|
|
|
|
|
return Array(SHOW_PAGE_NUM)
|
|
|
.fill(0)
|
|
|
@@ -109,12 +99,12 @@ export default {
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
- handleChange({ page = this.page, size = this.size }) {
|
|
|
+ handleChange ({ page = this.page, size = this.size }) {
|
|
|
const thePage =
|
|
|
page < 1 ? 1 : page > this.totalPage ? this.totalPage : page
|
|
|
this.$emit('change', { page: thePage, size })
|
|
|
},
|
|
|
- handlePageInputEvent(event) {
|
|
|
+ handlePageInputEvent (event) {
|
|
|
if (event.key === 'Enter') {
|
|
|
event.preventDefault()
|
|
|
this.handleChange({ page: this.inputPage })
|
|
|
@@ -127,24 +117,14 @@ export default {
|
|
|
<style lang="scss" scoped>
|
|
|
@import "~@/style/theme.scss";
|
|
|
|
|
|
-$pagination-font-color: inherit;
|
|
|
-$pagination-font-color--hover: inherit;
|
|
|
-$pagination-page-background--hover: $theme-blue-transparent;
|
|
|
-$pagination-page-background--active: $theme-blue;
|
|
|
-
|
|
|
-.icon{
|
|
|
- font-family: 'iconfont', sans-serif;
|
|
|
-}
|
|
|
-
|
|
|
.pagination-wrapper {
|
|
|
display: flex;
|
|
|
flex-wrap: wrap;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
- color: $pagination-font-color;
|
|
|
}
|
|
|
|
|
|
-.pagination-input{
|
|
|
+.pagination-input {
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
}
|
|
|
@@ -153,57 +133,30 @@ $pagination-page-background--active: $theme-blue;
|
|
|
display: flex;
|
|
|
align-items: center;
|
|
|
justify-content: center;
|
|
|
+}
|
|
|
|
|
|
- &__arrow,
|
|
|
- &__page,
|
|
|
- &__hidden-arrow {
|
|
|
- line-height: 1em;
|
|
|
- display: block;
|
|
|
- transition: background-color 0.3s;
|
|
|
- padding: 8px 10px;
|
|
|
- margin: 0 4px;
|
|
|
- cursor: pointer;
|
|
|
- border-radius: 2px;
|
|
|
+.c-button {
|
|
|
+ border-radius: 1000px;
|
|
|
+ width: 34px;
|
|
|
+ height: 34px;
|
|
|
+ margin: 0 8px;
|
|
|
+}
|
|
|
|
|
|
- &:hover {
|
|
|
- color: $pagination-font-color--hover;
|
|
|
- background: $pagination-page-background--hover;
|
|
|
- }
|
|
|
- }
|
|
|
- &__page.--active {
|
|
|
- color: white;
|
|
|
- background-color: $pagination-page-background--active;
|
|
|
- }
|
|
|
+.page-input {
|
|
|
+ width: 64px;
|
|
|
+ height: 32px;
|
|
|
+ border-radius: 0;
|
|
|
+ margin-right: 8px;
|
|
|
+ color: #7a8a9a;
|
|
|
|
|
|
- &__arrow {
|
|
|
- &.--right {
|
|
|
- transform: rotate(180deg);
|
|
|
- }
|
|
|
+ & + span{
|
|
|
+ color: #5a6a7a;
|
|
|
}
|
|
|
+}
|
|
|
|
|
|
- &__hidden-arrow {
|
|
|
- position: relative;
|
|
|
- .icon {
|
|
|
- position: absolute;
|
|
|
- left: 50%;
|
|
|
- top: 50%;
|
|
|
- transform: translate(-50%, -50%);
|
|
|
- opacity: 0;
|
|
|
- }
|
|
|
- &:hover {
|
|
|
- .icon {
|
|
|
- opacity: 1;
|
|
|
- }
|
|
|
- .pagination__hidden-ellipsis {
|
|
|
- opacity: 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- &.--right {
|
|
|
- .icon {
|
|
|
- transform: translate(-50%, -50%) rotate(180deg);
|
|
|
- }
|
|
|
- }
|
|
|
+@media (max-width: 450px) {
|
|
|
+ .c-button {
|
|
|
+ margin: 0 4px;
|
|
|
}
|
|
|
}
|
|
|
</style>
|