<template>
<div class="turnpage-container">
<!-- 向左移动 -->
<div @click="onBeforenavClick()">
<slot name="turnBefore">
<i class="el-icon-d-arrow-left turn-icon"></i>
</slot>
</div>
<!-- 内容的显示 -->
<div v-for="(item,index) in newList" @click="onItemClick(item)" :key="index">
<slot name="turnContent" v-bind:item="item" v-bind:index="index">
<span class="turn-font">{{item}}</span>
</slot>
</div>
<!-- 向右移动 -->
<div @click="onAfternavClick()">
<slot name="turnAfter">
<i class="el-icon-d-arrow-right turn-icon " />
</slot>
</div>
</div>
</template>
<script>
export default {
props: {
parentData: {
type: Array,
required: true
},
value: {
type: Number,
required: true,
default: 0
},
turnPageNumber: {
type: Number,
required: true
},
showPageNumber: {
type: Number,
required: true
},
isfullPage: {
type: Boolean,
default: false
}
},
data() {
return {
activedItem: -1,
index: 0,
newList: []
}
},
methods: {
onItemClick(item) {
this.$emit('input', this.index)
this.$emit('turnPageChange', item)
},
onBeforenavClick() {
if (this.index > 0) {
this.index = this.index - this.turnPageNumber
this.onItemClick()
}
},
onAfternavClick() {
if (this.index < this.parentData.length - this.turnPageNumber) {
this.index = this.index + this.turnPageNumber
}
this.onItemClick()
}
},
watch: {
parentData: {
immediate: true,
handler(val) {
this.showList = val
this.newList = val.slice(0, this.showPageNumber)
}
},
value(val, oldValue) {
this.index = val
this.newList = this.parentData.slice(this.index, this.index + this.showPageNumber)
if (this.newList.length < this.showPageNumber && this.isfullPage === true && val > oldValue) {
this.index = this.parentData.length - this.showPageNumber
this.newList = this.parentData.slice(-this.showPageNumber)
}
if (this.newList.length < this.showPageNumber && this.isfullPage === true && val < oldValue) {
this.newList = this.parentData.slice(0, this.showPageNumber)
}
}
}
}
</script>
<style lang="scss" scoped>
.turnpage-container {
height: 100%;
width: 100%;
position: relative;
display: flex;
}
.turn-icon {
font-size: 18px;
color: #888888;
}
.turn-font {
color: #eeeeee;
font-size: 16px;
}
</style>
案例
<template v-slot:dragContainer>
<TurningPage class="attribute-query-container" v-model="currentPage" :parentData="attributeContent" :turnPageNumber='1' :showPageNumber="1" >
<template v-slot:turnBefore>
<div class="attribute-turning">
<i class="el-icon-arrow-left turning-btn"></i>
</div>
</template>
<template v-slot:turnContent="{ item, index }">
<ScrollDiv class="attribute-query-content" :isHorizontal="true">
<div v-for="(value,key) in item" :key="key" class="attribute-query-results">
<div class="attribute-key">{{key}}:</div>
<div class="attribute-key">{{value}}</div>
</div>
</ScrollDiv>
</template>
<template v-slot:turnAfter>
<div class="attribute-turning">
<i class="el-icon-arrow-right turning-btn"></i>
</div>
</template>
</TurningPage>
</template>