video.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div class="videoBox warp" :class="'terminal' + terminal">
  3. <div class="videoLeftBox">
  4. <h3>{{componentContent.title}}</h3>
  5. <div v-html="componentContent.mainBody"></div>
  6. </div>
  7. <div class="videoRightBox" v-if="componentContent.coverImg && isPlay">
  8. <video class="myVideo" id="myVideo" :src="componentContent.videoUrl" enable-danmu danmu-btn controls></video>
  9. </div>
  10. <div class="videoCoverBox" v-if="componentContent.coverImg && !isPlay" @click="handlePlayVideo">
  11. <image :src="componentContent.coverImg" />
  12. </div>
  13. <div class="videoRightBox" v-if="!componentContent.coverImg">
  14. <video class="myVideo" id="myVideo" :src="componentContent.videoUrl" enable-danmu danmu-btn controls></video>
  15. </div>
  16. <div class="clear"></div>
  17. <!-- <div style="width:100vw;height:200px">
  18. <image :src="componentContent.coverImg" />
  19. </div>-->
  20. </div>
  21. </template>
  22. <script>
  23. export default {
  24. name: 'videoBox',
  25. props: {
  26. terminal: {
  27. type: Number,
  28. default: 4
  29. },
  30. componentContent: {
  31. type: Object
  32. }
  33. },
  34. created(){
  35. },
  36. mounted() {
  37. this.videoContext = uni.createVideoContext('myVideo',this)
  38. },
  39. data () {
  40. return {
  41. isPlay:false,
  42. videoContext:null
  43. }
  44. },
  45. methods:{
  46. handlePlayVideo(){
  47. this.isPlay = true
  48. setTimeout(()=>{
  49. this.videoContext.play()
  50. },500)
  51. }
  52. }
  53. }
  54. </script>
  55. <style lang="scss" scoped>
  56. .videoBox {
  57. padding: 20upx 0;
  58. display: flex;
  59. justify-content: flex-start;
  60. align-items: center;
  61. .videoLeftBox {
  62. width: 50%;
  63. padding-right: 10%;
  64. h3 {
  65. font-size: 28upx;
  66. color: #333333;
  67. margin-bottom: 30upx;
  68. }
  69. p {
  70. color: #333333;
  71. font-size: 14upx;
  72. line-height: 30upx;
  73. }
  74. }
  75. .videoRightBox {
  76. width: 50%;
  77. video {
  78. width: 100%;
  79. }
  80. }
  81. .clear {
  82. clear: both;
  83. }
  84. }
  85. .terminal1,.terminal2,.terminal3{
  86. &.videoBox{
  87. display: block;
  88. .videoLeftBox{
  89. width: 100%;
  90. text-align: center;
  91. margin-bottom: 20upx;
  92. }
  93. .videoRightBox {
  94. width: 100vw;
  95. height: 56.25vw; //16:9
  96. }
  97. }
  98. }
  99. .videoCoverBox{
  100. width: 100vw;
  101. height: 56.25vw; //16:9
  102. position: relative;
  103. &:before{
  104. content: '';
  105. width: 0rpx;
  106. height: 0rpx;
  107. border-left:80rpx solid #fff;
  108. border-right:50rpx solid transparent;
  109. border-top:50rpx solid transparent;
  110. border-bottom:50rpx solid transparent;
  111. position: absolute;
  112. top: 50%;
  113. left: 50%;
  114. transform: translate(-30%,-50%);
  115. z-index: 99;
  116. }
  117. image{
  118. width: 100%;
  119. height: 100%;
  120. }
  121. }
  122. </style>