cwg-video-player.vue 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <template>
  2. <view class="video-section">
  3. <view class="video-title">{{ t('PersonalManagement.KYCVerify.VideoTitle') }}</view>
  4. <view class="video-wrapper" :style="wrapperStyle">
  5. <iframe :src="videoUrl" class="demo-video" @load="onVideoLoad" @error="onVideoError" />
  6. </view>
  7. </view>
  8. </template>
  9. <script setup>
  10. import { computed, ref, watch } from 'vue'
  11. import { onLoad, onUnload } from '@dcloudio/uni-app'
  12. const props = defineProps({
  13. videoUrl: {
  14. type: String,
  15. required: true
  16. },
  17. aspectRatio: {
  18. type: Number,
  19. default: 16 / 9 // 默认16:9比例
  20. }
  21. })
  22. const wrapperStyle = computed(() => {
  23. return {
  24. width: '100%',
  25. position: 'relative',
  26. paddingBottom: `${(1 / props.aspectRatio) * 100}%`, // 根据宽高比计算padding
  27. backgroundColor: '#000',
  28. overflow: 'hidden'
  29. }
  30. })
  31. const onVideoLoad = () => {
  32. console.log('视频加载成功')
  33. }
  34. const onVideoError = (err) => {
  35. console.error('视频加载失败', err)
  36. uni.showToast({
  37. title: '视频加载失败,请稍后重试',
  38. icon: 'none'
  39. })
  40. }
  41. </script>
  42. <style lang="scss" scoped>
  43. .video-section {
  44. margin-top: 40rpx;
  45. .video-title {
  46. font-size: 28rpx;
  47. font-weight: 600;
  48. color: var(--bs-heading-color);
  49. margin-bottom: 20rpx;
  50. padding-left: 20rpx;
  51. }
  52. .video-wrapper {
  53. position: relative;
  54. width: 100%;
  55. border-radius: 16rpx;
  56. overflow: hidden;
  57. background: #000;
  58. .demo-video {
  59. position: absolute;
  60. top: 0;
  61. left: 0;
  62. width: 100%;
  63. height: 100%;
  64. border: none;
  65. background: #000;
  66. }
  67. web-view {
  68. position: absolute;
  69. top: 0;
  70. left: 0;
  71. width: 100%;
  72. height: 100%;
  73. border: none;
  74. background: #000;
  75. }
  76. }
  77. }
  78. </style>