preview.vue 1.94 KB
<template>
  <view class="popup-box">
    <view class="nav-bar">
      <view class="back" @click="back">
        <uni-icons type="left" :size="24" 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 :src="detailUrl" :style="{ width: width + 'px' }"
      /></view>
    </view>
  </view>
</template>
<script type="text/ecmascript-6">
export default {
  data () {
    return {
        width:0,
      title: '11',
      sourceType: '',
      detailUrl: ''
    }
  },
  onLoad (options) {
    const  {tabName,sourceType,detailUrl} = options
    this.title = tabName
    this.sourceType = sourceType
    this.detailUrl = detailUrl
    const img = new Image()
    img.onload = ()=> {
        this.width = document.querySelector('.img-detail').offsetHeight*img.height/img.width
        console.log(this.width)
    }
    img.src = detailUrl
  },
  methods: {
    back() {
        uni.navigateBack()
    }
  }
}
</script>
<style scoped lang="scss">
.popup-box {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: #000;
  padding: 100rpx 0rpx;
  z-index: 100;
  .nav-bar {
    width: 100%;
    height: 96rpx;
    margin-bottom: 50rpx;
    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: 32rpx;
      text-align: center;
    }
  }
  .popup-body {
    width: 100%;
    height: calc(100% - 200rpx);
    video {
      width: 100%;
      height: 100%;
    }
    .img-detail {
      height: 100%;
      text-align: center;
      image {
        height: 100%;
        width: auto;
      }
    }
  }
}
</style>