videos.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view :style="[videoWrapStyle]" v-show="!isSortType">
  3. <view class="video-box" id="myVideo" :style="[videoStyle]">
  4. <video class="video" object-fit="cover" :src="dataConfig.videoConfig.url" :poster="dataConfig.imgConfig.url" controls></video>
  5. </view>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. dataConfig: {
  12. type: Object,
  13. default: () => {}
  14. },
  15. isSortType: {
  16. type: String | Number,
  17. default: 0
  18. }
  19. },
  20. data() {
  21. return {
  22. height: 0,
  23. }
  24. },
  25. computed: {
  26. // 视频高度
  27. videoStyle() {
  28. let borderRadius = `${this.dataConfig.fillet.val * 2}rpx`;
  29. if (this.dataConfig.fillet.type) {
  30. borderRadius =
  31. `${this.dataConfig.fillet.valList[0].val * 2}rpx ${this.dataConfig.fillet.valList[1].val * 2}rpx ${this.dataConfig.fillet.valList[2].val * 2}rpx ${this.dataConfig.fillet.valList[3].val * 2}rpx`;
  32. }
  33. return {
  34. 'height': this.height + 'px',
  35. 'border-radius': borderRadius,
  36. };
  37. },
  38. videoWrapStyle() {
  39. return {
  40. 'padding': `${this.dataConfig.topConfig.val * 2}rpx ${this.dataConfig.prConfig.val * 2}rpx ${this.dataConfig.bottomConfig.val * 2}rpx`,
  41. 'margin-top': `${this.dataConfig.mbConfig.val * 2}rpx`,
  42. 'background': this.dataConfig.bottomBgColor.color[0].item,
  43. };
  44. },
  45. },
  46. mounted() {
  47. const query = uni.createSelectorQuery().in(this);
  48. query.select('#myVideo').boundingClientRect(data => {
  49. switch (this.dataConfig.scaleConfig.tabVal) {
  50. case 0:
  51. this.height = data.width * 9 / 16;
  52. break;
  53. case 1:
  54. this.height = data.width * 3 / 4;
  55. break;
  56. default:
  57. this.height = data.width;
  58. break;
  59. }
  60. }).exec();
  61. },
  62. }
  63. </script>
  64. <style lang="scss" scoped>
  65. .video-box {
  66. overflow: hidden;
  67. }
  68. .video {
  69. width: 100%;
  70. height: 100%;
  71. }
  72. </style>