Преглед на файлове

视频未加载完就提交问题

zaijin преди 1 година
родител
ревизия
fadceb2556
променени са 1 файла, в които са добавени 11 реда и са изтрити 2 реда
  1. 11 2
      src/components/CourseVideo/index.vue

+ 11 - 2
src/components/CourseVideo/index.vue

@@ -3,7 +3,7 @@
  * @Author: 空白格
  * @Date: 2022-08-24 13:48:47
  * @LastEditors: 空白格
- * @LastEditTime: 2023-04-19 14:59:21
+ * @LastEditTime: 2023-04-19 15:46:27
  * @FilePath: \veterans_client_web\src\components\CourseVideo\index.vue
  * @Copyright: Copyright (c) 2016~2022 by 空白格, All Rights Reserved.
 -->
@@ -96,6 +96,8 @@ export default {
         video_real_time: 0,
       },
       isPay: false,
+      // 视频是否加载完成
+      isLoadVideo: false,
     };
   },
   watch: {
@@ -175,6 +177,7 @@ export default {
     loadedmetadata(details) {
       this.videoInfo.duration = details.target.duration;
       this.videoInfo.initial_time = this.currentClasses.currentDuration;
+      this.isLoadVideo = true;
       this.$nextTick(() => {
         this.$refs.video.currentTime = this.videoInfo.initial_time;
       });
@@ -191,7 +194,11 @@ export default {
         playDuration = this.videoInfo.playDuration;
       }
       // 防止视频未加载完成就提交
-      if (Number(this.videoInfo.duration) > 0 && Number(playDuration) > 0) {
+      if (
+        Number(this.videoInfo.duration) > 0 &&
+        Number(playDuration) > 0 &&
+        this.isLoadVideo
+      ) {
         submitClassesDuration({
           tabId: this.currentClasses.id,
           playDuration: playDuration,
@@ -200,6 +207,7 @@ export default {
         }).then((res) => {
           if (res.code === 200) {
             console.log("已记录播放时长" + JSON.stringify(res.data));
+            this.isLoadVideo = false;
             if (isNeed) {
               this.$emit("changeClasses", item);
               this.currentClasses = item;
@@ -210,6 +218,7 @@ export default {
           }
         });
       } else if (isNeed) {
+        this.isLoadVideo = false;
         this.$emit("changeClasses", item);
         this.currentClasses = item;
         this.isPay = true;