preview.vue 2.34 KB
<template>
  <view class="popup-box" v-if="popupShow">
    <view class="nav-bar">
      <view class="back" @click="back">
        <uni-icons type="left" :size="20" color="#fff"></uni-icons>
      </view>
      <view class="title">{{ title }}</view>
    </view>
    <view class="popup-body">
      <video ref="videoPlayer" :src="detailUrl" controls v-if="sourceType == 2"></video>
      <view class="img-detail" v-else>
        <image @click="back" :src="detailUrl" mode="heightFix" />
      </view>
    </view>
  </view>
</template>
<script type="text/ecmascript-6">
import report from "@/mixin/report.js";
export default {
  props: {
    isComponents: Boolean,
    show: Boolean,
    mediaObject: Object
  },
  data () {
    return {
      title: '',
      sourceType: '',
      detailUrl: ''
    }
  },
  watch:{
    show:{
      immediate: true,
      handler (n) {
        if (n) {
          console.log(this.mediaObject)
          this.init(this.mediaObject)
        }
      }
    }
  },
  computed: {
    popupShow () {
      let status = true
      if (this.isComponents) status = this.show
      return status
    },
  },
  mixins: [report],
  onLoad (options) {
    this.init(options)
  },
  methods: {
    init (options) {
      const { tabName, sourceType, detailUrl } = options
      this.title = tabName
      this.sourceType = sourceType
      this.detailUrl = detailUrl
    },
    back () {
      if (this.isComponents) this.$emit('previewBack')
      else uni.navigateBack()
    },
  }
}
</script>
<style scoped lang="scss">
.popup-box {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  padding: toRpx(60) 0;
  z-index: 999;
  .nav-bar {
    width: 100%;
    height: toRpx(96);
    margin-bottom: toRpx(50);
    display: flex;
    align-items: center;
    .back {
      height: 100%;
      aspect-ratio: 1/1;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .title {
      color: #fff;
      flex: 1;
      font-size: toRpx(32);
      font-weight: 700;
      text-align: center;
    }
  }
  .popup-body {
    width: 100%;
    height: calc(100% - #{toRpx(200)});
    video {
      width: 100%;
      height: 100%;
    }
    .img-detail {
      height: 100%;
      text-align: center;
      image {
        height: calc(100vh - #{toRpx(200)});
        width: auto;
      }
    }
  }
}
</style>