cwg-video-player.vue 2.0 KB

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