123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <template>
- <view class="diy-banner" :style="{ height: `${imgHeights[imgCurrent]}rpx` }">
- <!-- 图片轮播 -->
- <swiper :autoplay="autoplay" class="swiper-box" :duration="duration" :circular="true" :interval="itemStyle.interval * 1000"
- @change="_bindChange">
- <swiper-item v-for="(dataItem, index) in dataList" :key="index">
- <image lazy-load :lazy-load-margin="0" class="slide-image" :src="dataItem.image" @click="onLink(dataItem.url)"
- @load="_imagesHeight" />
- </swiper-item>
- </swiper>
- <!-- 指示点 -->
- <view class="indicator-dots" :class="itemStyle.btnShape">
- <view class="dots-item" :class="{ active: imgCurrent == index }" :style="{ backgroundColor: itemStyle.btnColor }"
- v-for="(dataItem, index) in dataList" :key="index"></view>
- </view>
- </view>
- </template>
- <script>
- import mixin from '../mixin'
- export default {
- name: "Banner",
-
- props: {
- itemIndex: String,
- itemStyle: Object,
- params: Object,
- dataList: Array
- },
- mixins: [mixin],
-
- data() {
- return {
- width: 730,
- indicatorDots: false,
- autoplay: true,
- duration: 800,
- imgHeights: [],
- imgCurrent: 0,
- }
- },
-
- methods: {
- onLink(linkObj) {
- this.$navTo(linkObj)
- },
-
- _imagesHeight(e) {
-
- const imgwidth = e.detail.width,
- imgheight = e.detail.height,
-
- ratio = imgwidth / imgheight;
-
- const viewHeight = this.width / ratio;
- const imgHeights = this.imgHeights;
-
- imgHeights.push(viewHeight);
- this.imgHeights = imgHeights;
- },
-
- _bindChange(e) {
- this.imgCurrent = e.detail.current
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- .diy-banner {
- position: relative;
- max-height: 400rpx;
- margin-top: 100rpx;
-
- margin-top: 120rpx;
-
-
- .swiper-box {
- height: 100%;
- padding: 0rpx 10rpx 0rpx 10rpx;
- max-width: 750rpx;
- max-height: 450rpx;
- .slide-image {
- width: 100%;
- height: 100%;
- margin: 0 auto;
- display: block;
- border-radius: 10rpx;
- }
- }
-
-
- .indicator-dots {
- width: 100%;
- height: 28rpx;
- padding: 0 20rpx;
- position: absolute;
- left: 0;
- right: 0;
- bottom: 20rpx;
- opacity: 0.8;
- display: flex;
- justify-content: center;
- .dots-item {
- width: 16rpx;
- height: 16rpx;
- margin-right: 8rpx;
- background-color: #fff;
- &:last-child {
- margin-right: 0;
- }
- &.active {
- background-color: #313131 !important;
- }
- }
-
- &.round .dots-item {
- width: 16rpx;
- height: 16rpx;
- border-radius: 20rpx;
- }
-
- &.square .dots-item {
- width: 16rpx;
- height: 16rpx;
- }
-
- &.rectangle .dots-item {
- width: 22rpx;
- height: 14rpx;
- }
- }
- }
- </style>
|