detail.vue 4.4 KB
<template>
  <div class="layout" v-if="loaded">
    <div>
      <template v-if="(info.imageUrlList && info.imageUrlList.length) || info.videoUrl">
        <van-swipe @change="changeSwiper" height="210" show-indicators>
          <van-swipe-item v-if="info.videoUrl">
            <video id="swiper_video" :autoplay="autoplay" controls controlslist="nodownload" disablepictureinpicture playsinline="true" :src="info.videoUrl"></video>
          </van-swipe-item>
          <van-swipe-item v-for="(item, index) in info.imageUrlList" :key="index">
            <van-image width="100%" height="100%" fit="contain" :src="item" />
          </van-swipe-item>
          <template #indicator>
            <div class="custom-indicator">{{ curIdx + 1 }}/{{ fileNum }}</div>
          </template>
        </van-swipe>
      </template>
      <div class="rich-text">
        <div v-html="decodeURIComponent(info.materialUrl)" class="hide"></div>
      </div>
    </div>
    <div class="bottom-send flex">
      <div class="num flex">
        <div class="sprite-icon icon-send"></div>
        {{ info.sendNum }}
      </div>
      <div class="num flex">
        <div class="sprite-icon icon-eye"></div>
        {{ info.readNum }}
      </div>
      <van-button block round @click="shareToExternalMoments(info)">分享朋友圈</van-button>
      <van-button block round color="#3975C6" @click="sendMessage(info)">转发</van-button>
    </div>
  </div>
</template>

<script type="text/ecmascript-6">
import { marketingApi } from '@/api'
import { shareMixin } from '@/mixins'
export default {
  mixins: [shareMixin],
  name: 'detail',
  data() {
    return {
      curIdx: 0,
      fileList: [],
      autoplay: 3000,
      materialUrl: '',
      info: {},
      fileNum: 0,
      loaded: false,
      poster: ''
    }
  },
  beforeRouteEnter (to, from, next) {
    let {query} = to
    document.title = query.name || '详情'
    next()
  },
  created() {
    const { id } = this.getQuery()
    // let id = 148
    this.getDetail(id)
  },
  mounted() {
     
      
  },
  methods: {
    changeSwiper(idx) {
      this.curIdx = idx
    },
    getDetail(id) {
      marketingApi.getTextDetail({ id, flag: 0 }).then(data => {
        if(data){
          // const fileList = []
          // if (data.videoUrl) {
          //   fileList.push({ type: 'video', url: data.videoUrl })
          // }
          // if (data.imageUrlList && data.imageUrlList.length) {
          //   data.imageUrlList.forEach(item => {
          //     fileList.push({ type: 'image', url: item })
          //   })
          // }
          // this.fileList = fileList
          this.fileNum = data.imageUrlList && data.imageUrlList.length ? data.imageUrlList.length: 0
          if(data.videoUrl) this.fileNum = this.fileNum + 1
          this.info = data
          this.loaded = true
          if(!data.videoUrl) return;
          // this.getVideoFirstFrame(data.videoUrl).then(res => {
          //   this.poster = res.dataURL
          // })
          this.$nextTick(()=>{  
            const video = document.getElementById('swiper_video')
            video.addEventListener('play', ()=> {
              this.autoplay = 0
            })
            video.addEventListener('pause', ()=> {
              this.autoplay = 3000
            })
            video.addEventListener('ended', ()=> {
              this.autoplay = 3000
            }, false)
          })
        }
      })
    }
  }
}
</script>

<style lang="scss">
.layout {
  background-color: #fff;
}
.van-swipe {
  background-color: #f8f8f8;
  padding-bottom: 20px;
}
.van-swipe-item {
  height: 210px;
}
#swiper_video {
  width: 100%;
  height: 100%;
}
.custom-indicator {
  display: inline-block;
  text-align: center;
  position: absolute;
  top: 10px;
  right: 10px;
  width: 38px;
  font-size: 11px;
  color: #ffffff;
  height: 24px;
  line-height: 24px;
  background: #666666;
  border-radius: 12px;
}
.rich-text {
  padding-bottom: 120px;
}
.hide img {
  width: 100%;
  height: unset;
}
.bottom-send {
  padding: 0 16px 34px;
  height: 82px;
  background: #f8f8f8;
  border-radius: 0px 0px 4px 4px;
  position: fixed;
  bottom: 0;
  width: 100%;
  box-sizing: border-box;
  box-shadow: 0 0 0 0 #e9e9e9;
  border-top: 1px solid #dcdee0;
  .num {
    font-size: 12px;
    color: #999999;
    margin-right: 10px;
    .sprite-icon {
      margin-right: 4px;
    }
  }
  .van-button {
    min-width: 100px;
    height: 36px;
    font-size: 12px;
    margin-left: 10px;
  }
}
</style>