四零语境前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
2.3 KiB

  1. <template>
  2. <uv-popup
  3. ref="videoModal"
  4. title="视频播放"
  5. :show-cancel-button="false"
  6. :show-confirm-button="false"
  7. :close-on-click-overlay="true"
  8. :safeAreaInsetBottom="false"
  9. @close="handleClose"
  10. >
  11. <template #default>
  12. <view class="video-container">
  13. <video
  14. v-if="currentVideo"
  15. :src="currentVideo"
  16. controls
  17. autoplay
  18. :show-fullscreen-btn="true"
  19. :show-play-btn="true"
  20. :show-center-play-btn="true"
  21. style="width: 100%; height: 400rpx; border-radius: 8rpx;"
  22. @error="onVideoError"
  23. @play="onVideoPlay"
  24. @pause="onVideoPause"
  25. ></video>
  26. <view v-else class="video-loading">
  27. <text>视频加载中...</text>
  28. </view>
  29. </view>
  30. </template>
  31. </uv-popup>
  32. </template>
  33. <script>
  34. export default {
  35. name: 'VideoPopup',
  36. data() {
  37. return {
  38. currentVideo: ''
  39. }
  40. },
  41. methods: {
  42. // 打开视频弹窗
  43. open(videoUrl) {
  44. if (videoUrl) {
  45. this.currentVideo = videoUrl
  46. this.$refs.videoModal.open()
  47. } else {
  48. uni.showToast({
  49. title: '视频地址无效',
  50. icon: 'error'
  51. })
  52. }
  53. },
  54. // 关闭视频弹窗
  55. close() {
  56. this.$refs.videoModal.close()
  57. this.currentVideo = ''
  58. },
  59. // 处理弹窗关闭事件
  60. handleClose() {
  61. this.currentVideo = ''
  62. this.$emit('close')
  63. },
  64. // 视频错误处理
  65. onVideoError(e) {
  66. console.error('视频播放错误:', e)
  67. uni.showToast({
  68. title: '视频播放失败',
  69. icon: 'error'
  70. })
  71. this.close()
  72. this.$emit('error', e)
  73. },
  74. // 视频开始播放
  75. onVideoPlay() {
  76. console.log('视频开始播放')
  77. this.$emit('play')
  78. },
  79. // 视频暂停
  80. onVideoPause() {
  81. console.log('视频暂停播放')
  82. this.$emit('pause')
  83. }
  84. }
  85. }
  86. </script>
  87. <style scoped lang="scss">
  88. .video-container {
  89. position: relative;
  90. width: 90vw;
  91. .video-loading {
  92. display: flex;
  93. align-items: center;
  94. justify-content: center;
  95. height: 400rpx;
  96. background: #f5f5f5;
  97. border-radius: 8rpx;
  98. text {
  99. font-size: 28rpx;
  100. color: #999;
  101. }
  102. }
  103. }
  104. </style>