video-render.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <view class="zaiui-video-h5-view-box">
  3. <!--封面-->
  4. <view class="video-cover-view" v-show="coverShow?true:false">
  5. <view class="bg-img bg-mask flex align-center text-center video-cover" :style="[{backgroundImage:'url('+ isCover +')'}]">
  6. <view class="text-white video-play-view">
  7. <text class="cuIcon-playfill play"></text>
  8. </view>
  9. </view>
  10. <!--点击事件,此view里不能放任何组件,只能放文字,否则会报错,原因未知。-->
  11. <view class="video-click" @click="video_view.onClick" :data-index='isNum' :data-src='isSrc'></view>
  12. </view>
  13. <!--视频组件框-->
  14. <view class="zaiui-video-h5-box" :id="['video_h5_' + isNum]"></view>
  15. </view>
  16. </template>
  17. <script>
  18. //在APP端创建H5的视频播放器组件,用此方案,可调整视频组件的层级问题。
  19. //如需扩展其它类型的组件,可按照此方案,自行扩展。
  20. export default {
  21. name: 'video-render',
  22. data() {
  23. return {
  24. coverShow: true,
  25. }
  26. },
  27. props: {
  28. isSrc: {
  29. type: String,
  30. default: ''
  31. },
  32. isNum: {
  33. type: Number,
  34. default: 1
  35. },
  36. isCover: {
  37. type: String,
  38. default: ''
  39. }
  40. },
  41. methods: {
  42. closeCoverClick() {
  43. //关闭封面
  44. this.coverShow = false;
  45. }
  46. }
  47. }
  48. </script>
  49. <script module="video_view" lang="renderjs">
  50. export default {
  51. methods: {
  52. onClick(event,ownerInstance) {
  53. let data = event.target.dataset;
  54. // 调用 service 层的方法
  55. ownerInstance.callMethod('closeCoverClick');
  56. this.initVideo(data.src,data.index);
  57. },
  58. initVideo(isSrc,isNum) {
  59. //更多video属性:https://www.w3school.com.cn/jsref/dom_obj_video.asp
  60. let src = isSrc.replace(/\"/g, "");
  61. const VIDEO = document.createElement("video");
  62. VIDEO.setAttribute("width", "100%");
  63. VIDEO.setAttribute("height", "200");
  64. VIDEO.setAttribute("autoplay", "autoplay"); //自动播放
  65. VIDEO.setAttribute("controls", "controls"); //控制条
  66. VIDEO.setAttribute("src", src);
  67. const view = document.getElementById("video_h5_" + isNum);
  68. view.appendChild(VIDEO);
  69. }
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .zaiui-video-h5-view-box {
  75. position: relative;
  76. width: 100%;
  77. .video-cover-view {
  78. position: relative;
  79. width: 100%;
  80. height: 195px;
  81. .video-cover {
  82. height: 195px;
  83. text-align: center;
  84. }
  85. .bg-mask {
  86. background-color: #ffffff;
  87. }
  88. .video-play-view {
  89. width: 100%;
  90. .play {
  91. font-size: 63.63upx;
  92. }
  93. }
  94. .video-click {
  95. position: absolute;
  96. left: 0;
  97. bottom: 0;
  98. top: 0;
  99. right: 0;
  100. pointer-events: all;
  101. z-index: 2;
  102. }
  103. }
  104. .zaiui-video-h5-box {
  105. position: relative;
  106. width: 100%;
  107. height: 100%;
  108. }
  109. }
  110. </style>