en-image-video.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <view>
  3. <view class="row image-box">
  4. <view class="image-item m-r20 m-t20" mode="aspectFill" v-for="(item,index) in imgList">
  5. <image class="image r-10 " :src="item.type === 1?item.url:getVideoImg(item.url)" :style="[{width},{height}]" @click.stop="onPreviewImage(item)">
  6. </image>
  7. <image class="wh-45 video-icon" src="/static/img/task/play.png" mode="aspectFill" @click.stop="showVideoImg(item.url)" v-if="item.type === 2">
  8. </image>
  9. </view>
  10. </view>
  11. <uni-popup ref="videoPopup" @change="closeVideoImg">
  12. <view class="video-box" v-if="videoUrl">
  13. <video class="myVideo" :src="videoUrl" :autoplay="true"></video>
  14. </view>
  15. </uni-popup>
  16. </view>
  17. </template>
  18. <script>
  19. import tools from "@/service/tools";
  20. export default {
  21. props: {
  22. is_both: {
  23. type: Boolean,
  24. default: false
  25. },
  26. width: {
  27. type: String,
  28. default: '130rpx'
  29. },
  30. height: {
  31. type: String,
  32. default: '130rpx'
  33. },
  34. imgList: {
  35. default: []
  36. },
  37. previewImage: {
  38. default: []
  39. }
  40. },
  41. data() {
  42. return {
  43. videoUrl:''
  44. }
  45. },
  46. mounted() {},
  47. methods: {
  48. onPreviewImage(item) {
  49. if(item.type===1){
  50. this.$emit('onShowImg',item.url)
  51. }else {
  52. this.showVideoImg(item.url)
  53. }
  54. },
  55. closeVideoImg(e) {
  56. if (!e.show) {
  57. console.log('关闭视频了')
  58. this.videoUrl = ''
  59. }
  60. },
  61. showVideoImg(url) {
  62. console.log(url)
  63. this.videoUrl = url
  64. this.$refs.videoPopup.open('center')
  65. },
  66. getVideoImg(url) {
  67. return tools.getOssVideo(url)
  68. },
  69. }
  70. }
  71. </script>
  72. <style lang="scss" scoped>
  73. .image-box {
  74. flex-wrap: wrap;
  75. }
  76. .image-item {
  77. position: relative;
  78. .image {
  79. display: block;
  80. }
  81. .video-icon {
  82. position: absolute;
  83. top: 50%;
  84. left: 50%;
  85. transform: translate(-50%, -50%);
  86. }
  87. }
  88. .video-box {
  89. height: 70vh;
  90. width: 100vw;
  91. .myVideo {
  92. height: 70vh;
  93. width: 100vw;
  94. }
  95. }
  96. </style>