Sfoglia il codice sorgente

优化课程保存进度方法
编程保存进度方法合并
编程课不自动跳转下一节

liyanbo 4 mesi fa
parent
commit
6405722573

+ 2 - 2
src/components/blockly/MapGame.vue

@@ -1207,7 +1207,7 @@ window.isFinish = async function() {
     //无任务情况下直接完成
     if (totalTasks === 0 || completedTasks === totalTasks) {
       gameState.player.hasReachedEnd = true;
-      emits('saveProgress', starCount * 100)
+      emits('saveProgress', 'blockly', starCount * 100)
       showGameMessage(CONFIG.TIPS.FINISH, 'success' );
       return;
     }
@@ -1216,7 +1216,7 @@ window.isFinish = async function() {
     // 计算完成百分比
     const completionPercentage = totalTasks > 0 ? Math.round(completedTasks / totalTasks * starCount) : starCount;
     showGameMessage(CONFIG.TIPS.UNFINISHED, 'error');
-    emits('saveProgress', completionPercentage * 100)
+    emits('saveProgress', 'blockly', completionPercentage * 100)
   }
 };
 

+ 7 - 9
src/components/videopage/VideoPlayer.vue

@@ -121,14 +121,9 @@ const saveProgress = throttle(async (progress, currentTime) => {
         timestamp: Date.now()
       })
     )
+
     // 通过emit事件通知父组件保存进度
-    emits('saveProgress', {
-      progress,
-      currentTime,
-      gradeId: globalState.getGradeId(),
-      typeId: props.typeId,
-      courseId: props.courseId
-    })
+    emits('saveProgress', "course", progress)
     savedProgress.value.push(progress)
   } catch (error) {
     console.error(`保存进度失败:`, error)
@@ -227,9 +222,12 @@ const handleSeeked = () => {
 const handleVideoEnded = () => {
   // 视频结束时保存100%进度
   if (!savedProgress.value.includes(100)) {
-    saveProgress(100, videoRef.value.duration)
+    // 通过emit事件通知父组件保存进度
+    emits('saveProgress', "course", 100)
+    savedProgress.value.push(100)
   }
-  // emits('videoEnded')
+
+  emits('videoEnded')
 }
 
 // 在视频加载完成后设置上次播放进度

+ 7 - 22
src/views/programming/Interface.vue

@@ -74,7 +74,7 @@
                    @close-game="emit('closeVideo')"
                    @prev-section="playPreviousVideo"
                    @next-section="playNextVideo"
-                   @saveProgress="saveBlocklyProgress"
+                   @saveProgress="handleSaveProgress"
           ></MapGame>
 
         </template>
@@ -256,7 +256,7 @@ const handleVideoEnded = () => {
   }
 
   // 自动播放下一个
-  playNextVideo();
+  // playNextVideo();
 }
 
 // 禁用视频
@@ -442,33 +442,18 @@ onMounted(async () => {
   typeSort.value = router.currentRoute.value.query.typeSort;
 })
 
-// 保存视频进度接口
-const handleSaveProgress = async (progressData) => {
-  try {
-    const { progress, typeId, courseId } = progressData
-    await saveRecordBlockly({
-      brpZtId: props.courseData.ztId,
-      brpCtId: typeId,
-      brpCourseId: courseId,
-      brpType: 'course',
-      brpProgress: progress
-    })
-  } catch (error) {
-    console.error('保存视频进度失败:', error)
-  }
-}
-// 保存bockly进度接口
-const saveBlocklyProgress = async () => {
+// 保存视频/bockly进度接口
+const handleSaveProgress = async (type, progress) => {
   try {
     await saveRecordBlockly({
       brpZtId: props.courseData.ztId,
       brpCtId: props.courseData.bcType,
       brpCourseId: course.value.id,
-      brpType: 'blockly',
-      brpProgress: 300
+      brpType: type,
+      brpProgress: progress
     })
   } catch (error) {
-    console.error('保存blockly进度失败:', error)
+    console.error(`保存${type}进度失败:`, error)
   }
 }