hookehuyr

refactor(视频播放器): 优化暂停逻辑并添加引用

在VideoPlayer组件中,将暂停逻辑从`videoRef.value?.$player`改为直接使用`player.value`,以提高代码可读性和维护性。在UploadVideoPopup组件中,添加`videoPlayerRef`引用,确保在提交和取消时暂停视频播放
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
30 </div> 30 </div>
31 31
32 <div v-if="videoUrl" class="video-preview"> 32 <div v-if="videoUrl" class="video-preview">
33 - <VideoPlayer :video-url="videoUrl" :autoplay="false" /> 33 + <VideoPlayer ref="videoPlayerRef" :video-url="videoUrl" :autoplay="false" />
34 </div> 34 </div>
35 </div> 35 </div>
36 </div> 36 </div>
...@@ -115,11 +115,14 @@ const onOversize = () => { ...@@ -115,11 +115,14 @@ const onOversize = () => {
115 showToast('文件大小不能超过100MB'); 115 showToast('文件大小不能超过100MB');
116 }; 116 };
117 117
118 +const videoPlayerRef = ref(null);
119 +
118 const onSubmit = () => { 120 const onSubmit = () => {
119 if (!videoUrl.value || !videoId.value) { 121 if (!videoUrl.value || !videoId.value) {
120 showToast('请先上传视频'); 122 showToast('请先上传视频');
121 return; 123 return;
122 } 124 }
125 + videoPlayerRef.value?.pause();
123 emit('submit', { 126 emit('submit', {
124 url: videoUrl.value, 127 url: videoUrl.value,
125 id: videoId.value, 128 id: videoId.value,
...@@ -129,6 +132,7 @@ const onSubmit = () => { ...@@ -129,6 +132,7 @@ const onSubmit = () => {
129 }; 132 };
130 133
131 const onCancel = () => { 134 const onCancel = () => {
135 + videoPlayerRef.value?.pause();
132 emit('cancel'); 136 emit('cancel');
133 emit('update:modelValue', false); 137 emit('update:modelValue', false);
134 }; 138 };
......
...@@ -109,8 +109,8 @@ onBeforeUnmount(() => { ...@@ -109,8 +109,8 @@ onBeforeUnmount(() => {
109 109
110 defineExpose({ 110 defineExpose({
111 pause() { 111 pause() {
112 - if (videoRef.value?.$player) { 112 + if (player.value) {
113 - videoRef.value.$player.pause(); 113 + player.value.pause();
114 } 114 }
115 }, 115 },
116 }); 116 });
......