swiperBox.vue 2.29 KB
<template>
    <div class="swiper-box" v-if="swipers  && swipers.length">
        <swipe class="swipe" :autoplay="0" :touchable="swipers.length === 1 ? false : true" :show-indicators="options && options.showIndicators !== undefined ? options.showIndicators : showIndicators" @change="onChange">
            <swipe-item class="swipe-item" v-for="(item, index) in swipers" :key="index">
                <div class="item" @click="jump(item)">
                    <div class="img-box">
                        <img v-lazy="item.simg + SIGN.BIG" class="img" />
                    </div>
                </div>

                <!-- 展示播放按钮 -->
                <div @click="play(item)" v-if="item.type == 22" class="play-button-box">
                    <img src="static/img/play_dark.png" class="play-button-img" />
                </div>
            </swipe-item>
        </swipe>
    </div>
</template>

<script>

    // 引入组件
    import { Swipe, SwipeItem } from "vant";

    export default {
        name: 'swiperBox',
        data () {
            return {
                showIndicators: true,       // 是否显示定位图例
                currentIndex: 0             // 当前展示的swiper索引
            }
        },
        props: ['swipers', 'options'],
        components: {
            Swipe,
            SwipeItem
        },
        methods: {
        
            /**
             * 当swiper切换
             * @param {Int} index [切换swiper索引]
             */
            onChange(index) {

                // 设置当前展示的swiper索引
                this.$set(this, 'currentIndex', index);

                // 抛出事件
                this.$emit("onChange", index);
            },

            /**
             * swiper跳转事件
             */
            jump(item) {

                // 抛出事件
                this.$emit('jump', item);
            },

            /**
             * 播放视频
             * @param {Object} item [数据对象]
             */
            play(item) {
                
                // 抛出事件
                this.$emit('play', item);
            }
        }
    }
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style rel="stylesheet/less" lang="less" scoped>
    @import 'swiperBox';
</style>