123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <template>
- <div class="carousel" :style="{backgroundColor: activeColor}">
- <div class="container">
- <slot></slot>
- <div class="carousel-container">
- <div v-swiper:mySwiper="swiperOption">
- <div class="swiper-wrapper">
- <div class="swiper-slide" v-for="banner in banners">
- <a :href="banner.detailsLink" target="_blank" v-if="banner.detailsLink">
- <img :src="banner.pictureLink"/>
- </a>
- <span v-if="!banner.detailsLink">
- <img :src="banner.pictureLink"/>
- </span>
- </div>
- </div>
- <div class="swiper-button-prev"><i class="iconfont icon-arrow-left"></i></div>
- <div class="swiper-button-next"><i class="iconfont icon-arrow-right"></i></div>
- <div class="swiper-pagination swiper-pagination-bullets"></div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script>
- import { carousel } from '~utils/mixin'
- export default {
- name: 'carousel',
- mixins: [carousel],
- data () {
- return {
- activeSlide: 0
- }
- },
- computed: {
- banners () {
- if (this.$store.state.carousel.banners.data && this.$store.state.carousel.banners.data.data) {
- // banner.sort(function (a, b) {
- // return a.contentId - b.contentId
- // })
- return this.$store.state.carousel.banners.data.data.slice()
- } else {
- return ''
- }
- },
- activeColor () {
- return this.banners.length ? this.banners[this.activeSlide].metadatas['contExp_select'] : null
- },
- swiperOption () {
- let _this = this
- return {
- autoplay: 6000,
- initialSlide: 0,
- pagination: '.swiper-pagination',
- // 解决点击分页器后图片就不能轮播的问题
- autoplayDisableOnInteraction: false,
- paginationClickable: true,
- mousewheelControl: false,
- effect: _this.effect,
- lazyLoading: true,
- loop: true,
- prevButton: '.swiper-button-prev',
- nextButton: '.swiper-button-next',
- onTransitionStart: (swiper) => {
- // 不要通过vue刷新dom,会导致pagination无法刷新
- // this.activeSlide = swiper.activeIndex
- if (_this.banners.length && (swiper.activeIndex > _this.banners.length)) {
- swiper.activeIndex = 1
- } else if (_this.banners.length && swiper.activeIndex <= 0) {
- swiper.activeIndex = _this.banners.length
- }
- let carousel = document.querySelector('.carousel')
- if (carousel && carousel !== null) {
- carousel.style.backgroundColor =
- _this.banners[swiper.activeIndex - 1].metadatas['contExp_select']
- }
- }
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- @import '~assets/scss/variables';
- $carousel_width: 992px;
- $carousel_height: 477px;
- .carousel {
- transition: background-color .3s;
- position: relative;
- margin-bottom: $lg-pad;
- .carousel-container {
- width: $carousel_width;
- height: $carousel_height;
- margin-left: 200px;
- overflow: hidden;
- .swiper-wrapper {
- position: static;
- .swiper-slide {
- img {
- display: block;
- height: $carousel_height;
- width: 100%;
- }
- a[href='']:hover{
- cursor: default;
- }
- }
- }
- }
- }
- </style>
|