en-image-video.vue 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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="onPreviewImage(item)">
  6. </image>
  7. <image class="wh-45 video-icon" src="/static/img/task/play.png" mode="aspectFill" 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. this.$emit('onShowImg',item.url)
  50. },
  51. closeVideoImg(e) {
  52. if (!e.show) {
  53. console.log('关闭视频了')
  54. this.videoUrl = ''
  55. }
  56. },
  57. showVideoImg(url) {
  58. console.log(url)
  59. this.videoUrl = url
  60. this.$refs.videoPopup.open('center')
  61. },
  62. getVideoImg(url) {
  63. return tools.getOssVideo(url)
  64. },
  65. }
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .image-box {
  70. flex-wrap: wrap;
  71. }
  72. .image-item {
  73. position: relative;
  74. .image {
  75. display: block;
  76. }
  77. .video-icon {
  78. position: absolute;
  79. top: 50%;
  80. left: 50%;
  81. transform: translate(-50%, -50%);
  82. }
  83. }
  84. </style>