resource-focus-image.vue 2.56 KB
<template>
    <resource class="focus-image">
        <awesome-swiper name="mySwiper" :reg-success="swiperSuccess" :options="swiperOption" class="swipe">
            <div class="swiper-wrapper" @click="activeLink">
                <div class="swiper-slide"
                     v-for="focus in value.data"
                     :key="focus.src"
                     :style="{backgroundColor: focus.bgColor}">
                    <img-format :src="focus.src" :w="750" :h="480"></img-format>
                </div>
            </div>
            <div class="swiper-pagination"></div>
        </awesome-swiper>
        <a-link ref="linkA" :href="activeHref" :yas="value" :yas-f="index" :yas-i="imageIndex"></a-link>
    </resource>
</template>

<script>
    import Resource from './resource';

    export default {
        name: 'ResourceFocusImage',
        props: {
            value: Object,
            index: Number
        },
        data() {
            return {
                activeHref: '',
                swiperOption: {
                    loop: true,
                    autoplay: true,
                    pagination: {
                        el: '.swiper-pagination'
                    }
                }
            };
        },
        computed: {
            imageIndex() {
                return this.mySwiper ? this.mySwiper.realIndex : 0;
            }
        },
        methods: {
            swiperSuccess(swiper) {
                this.mySwiper = swiper;
            },
            activeLink() {
                const img = this.value.data[this.mySwiper.realIndex];

                if (img) {
                    this.activeHref = img.url;
                    this.$nextTick(() => {
                        this.$refs.linkA.click();
                    });
                }
            }
        },
        components: {Resource}
    };
</script>

<style lang="scss">
    .focus-image {
        padding: 0 !important;
        height: 480px;
        overflow: hidden;

        .swipe {
            position: relative;
            height: 100%;
        }

        .swiper-slide {
            a {
                display: block;
            }

            img {
                width: 100%;
                height: 100%;
            }
        }

        .swiper-pagination-bullet {
            width: 10px;
            height: 10px;
            background: #e0e0e0;
            opacity: 1;
            border-radius: 0;

                &.swiper-pagination-bullet-active {
                     width: 20px;
                     background: #fff;
                }
            }
        }
</style>