swiper.vue 3.1 KB
<template>
    <div class="swiper-box" :class="{'points-mall-swiper':isPointsMall}" 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="$parent.$parent.gotoDetail(item)">
                    <div class="img-box">
                        <img v-if="isPointsMall" v-lazy="item + SIGN.BIG" class="img" />
                        <img v-else v-lazy="item.simg + SIGN.BIG" class="img" />
                    </div>
                </div>

                <!-- 展示播放按钮 -->
                <div @click="playNow(item.to)" v-if="item.type == 22" class="play-button-box">
                    <img src="static/img/play_dark.png" class="play-button-img" />
                </div>
            </swipe-item>
            <template v-if="isPointsMall" #indicator>
                <div class="custom-indicator">
                    {{ current + 1 }}/{{swipers.length}}
                </div>
            </template>
        </swipe>
    </div>
</template>

<script>

// 引入组件
// import { Swipe, SwipeItem } from 'mint-ui';
import { Swipe, SwipeItem } from "vant";

export default {
  data () {
    return {
      showIndicators: true,
      current: 0 // 图片位置
    }
  },
  props: ["swipers", "options", "isPointsMall"],
  components: {
    Swipe,
    SwipeItem
  },
  methods: {
    /**
     * 当swiper切换
     * @param {int} index [切换swiper索引]
     */
    onChange (index) {
      this.current = index;
      this.$emit("onChange", index);
    },
    /**
      * 播放视频
      * @param {String} videoUrl [数据对象]
      */
    playNow(videoUrl) {
        
        // 判断App内
        if (this.isCNLive.value) {

            // 判断通用跳转函数是否存在
            if (typeof this.$parent.$parent.gotoDetail === 'function') {

                // 设置跳转参数
                let params = {
                    type: '22',
                    to: videoUrl,
                    shop_type: ''
                };
                // 通用跳转
                this.$parent.$parent.gotoDetail(params);
            }
        } else {

            // App外,唤起App
            this.openApp();
        }
    },
    /**
     * 唤起App封装
     */
    openApp() {
        this.$nextTick(() => {

            // 唤起App
            if (typeof this.$parent.$parent.callAppModal === 'function' && typeof this.$parent.$refs.callApp === 'object') {

                // 设置唤起参数
                let options = {
                    success: this.$parent.$refs.callApp.callApp
                }

                // 唤起App
                this.$parent.$parent.callAppModal(options);
            }
        });
    },
  }
}
</script>

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