You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

218 lines
5.0 KiB

<template>
<view class="uni-pagination">
<view class="uni-pagination__btns">
<view
:class="['uni-pagination__btn',{'uni-pagination--disabled':currentIndex === 1}]"
:hover-class="currentIndex === 1 ? '' : 'uni-pagination--hover'"
:hover-start-time="20"
:hover-stay-time="70"
@click="clickLeft">
<template v-if="showIcon===true || showIcon === 'true'">
<uni-icons
color="#000"
size="20"
type="arrowleft"/>
</template>
<template v-else>
{{ prevText }}
</template>
</view>
</view>
<view class="uni-pagination__num">
<text class="uni-pagination__num-current">{{ currentIndex }}</text>/{{ maxPage }}
</view>
<view class="uni-pagination__btns stylebtn">
<view
:class="['uni-pagination__btn',{'uni-pagination--disabled':currentIndex === maxPage}]"
:hover-class="currentIndex === maxPage ? '' : 'uni-pagination--hover'"
:hover-start-time="20"
:hover-stay-time="70"
@click="clickRight">
<template v-if="showIcon===true || showIcon === 'true'">
<uni-icons
color="#000"
size="20"
type="arrowright"/>
</template>
<template v-else>
{{ nextText }}
</template>
</view>
</view>
<!-- <view class="uni-pagination__num">
<input type="text" v-model="currentIndex" class="uniinput"/>
</view> -->
</view>
</template>
<script>
// import uniIcons from 'uni-icons.vue'
export default {
name: 'UniPagination',
components: {
// uniIcons
},
props: {
prevText: {
type: String,
default: '上一页'
},
nextText: {
type: String,
default: '下一页'
},
current: {
type: [Number, String],
default: 1
},
total: { // 数据总量
type: [Number, String],
default: 0
},
pageSize: { // 每页数据量
type: [Number, String],
default: 10
},
showIcon: { // 是否以 icon 形式展示按钮
type: [Boolean, String],
default: false
}
},
data () {
return {
currentIndex: 1
}
},
computed: {
maxPage () {
let maxPage = 1
let total = Number(this.total)
let pageSize = Number(this.pageSize)
if (total && pageSize) {
maxPage = Math.ceil(total / pageSize)
}
return maxPage
}
},
watch: {
current (val) {
this.currentIndex = +val
}
},
created () {
this.currentIndex = +this.current
},
methods: {
clickLeft () {
if (Number(this.currentIndex) === 1) {
return
}
this.currentIndex -= 1
this.change('prev')
},
clickRight () {
if (Number(this.currentIndex) === this.maxPage) {
return
}
this.currentIndex += 1
this.change('next')
},
change (e) {
this.$emit('change', {
type: e,
current: this.currentIndex
})
}
}
}
</script>
<style lang="scss">
// <style>
@mixin pagination-disabled {
opacity: 0.3;
}
@mixin pagination-hover {
color: rgba(0, 0, 0, .6);
background-color: $uni-bg-color-hover;
}
.uni-pagination {
width: 100%;
box-sizing: border-box;
padding: 0 40upx;
position: relative;
overflow: hidden;
// display: flex;
flex-direction: row;
margin: 0upx 0upx 30upx 0upx;
&__btns {
flex: 1;
// display: flex;
width: 150upx;
float: left;
justify-content: space-between;
align-items: center;
flex-direction: row;
color: rgba(51,51,51,1);
}
&__btn {
width: 120upx;
height: 60upx;
padding: 0 16upx;
line-height: 60upx;
font-size: $uni-font-size-base;
box-sizing: border-box;
position: relative;
background-color: #f8f8f8;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
&:after {
content: "";
width: 200%;
height: 200%;
position: absolute;
top: 0;
left: 0;
border: 1px solid $uni-border-color;
transform: scale(.5);
transform-origin: 0 0;
box-sizing: border-box;
border-radius: $uni-border-radius-lg;
}
}
&__num {
font-size: $uni-font-size-base;
color: $uni-text-color;
position: absolute;
left: 50%;
top: 0;
transform: translateX(-50%);
&-current {
color: $uni-color-primary;
}
}
&--disabled {
@include pagination-disabled;
}
&--hover {
@include pagination-hover;
}
}
.uni-pagination__btn {padding: 5px 10px;border: 1px solid rgba(15,130,253,1);color: #333;border-radius: 5px;cursor: pointer;width: 150upx;}
.uni-pagination__btn.uni-pagination--disabled {border: 1px solid rgba(15,130,253,1);color: #fff;background: rgba(15,130,253,1);opacity: 0.8;}
.uni-pagination__num {margin: 5px 10px 0px 10px; color: rgba(51,51,51,1);font-size: 30upx;}
.uni-pagination__num-current {color: rgba(15,130,253,1);}
.uniinput {border: 1px solid #00aaa1;color: #00aaa1;padding: 3px 5px;height: auto;background: #fff;width: 40px;text-align: center;line-height: normal;font-size: 18px;margin: -5px 0px 0px 0px;border-radius: 5px;}
.stylebtn {float: right;}
</style>