Kaynağa Gözat

新增blockly保存进度

liyanbo 5 ay önce
ebeveyn
işleme
6536ffba6e

+ 4 - 1
src/components/blockly/MapGame.vue

@@ -123,7 +123,7 @@
 </template>
 
 <script setup>
-import {ref, onMounted, onUnmounted, reactive, computed, nextTick, watch} from 'vue';
+import {ref, onMounted, onUnmounted, reactive, computed, nextTick, watch, defineEmits} from 'vue';
 import { useRouter, useRoute } from 'vue-router';
 import { ArrowLeftBold } from '@element-plus/icons-vue';
 import * as Blockly from "blockly";
@@ -134,6 +134,8 @@ import playerImage from '@/assets/images/blockly/user.png';
 // 游戏接口数据
 import { getMapGameById } from '@/api/blockly/game.js';
 
+// 定义emits
+const emits = defineEmits(['saveProgress'])
 // 定义组件属性
 const props = defineProps({
   // 游戏ID
@@ -1574,6 +1576,7 @@ window.isFinish = async function() {
 
     gameState.player.hasReachedEnd = true;
     showGameMessage(CONFIG.TIPS.FINISH, 'success' );
+    emits('saveProgress')
   }
 };
 

+ 17 - 2
src/views/programming/Interface.vue

@@ -36,6 +36,7 @@
               :currentIndex="course.key || ''"
               @timeUpdate="handleVideoTimeUpdate"
               @videoEnded="handleVideoEnded"
+              @saveProgress="handleSaveProgress"
           />
           <!-- 图片 -->
           <ImageView v-if="course.courseContentType === 'image'" :imagePath="course.courseImagePath" altText="课程图片"></ImageView>
@@ -72,6 +73,7 @@
                    @close-game="emit('closeVideo')"
                    @prev-section="playPreviousVideo"
                    @next-section="playNextVideo"
+                   @saveProgress="saveBlocklyProgress"
           ></MapGame>
 
         </template>
@@ -293,7 +295,7 @@ const handleVideoTimeUpdate = ({ currentTime, progressPercentage, courseConfig:
           // 保存弹窗问题进度
           await saveRecordBlockly({
             brpZtId: props.courseData.ztId,
-            brpCtId: props.courseData.typeId,
+            brpCtId: props.courseData.bcType,
             brpCourseConfigId: config.id,
             brpCourseId: courseId.value,
             brpType: 'courseQuest',
@@ -442,7 +444,6 @@ onMounted(async () => {
 const handleSaveProgress = async (progressData) => {
   try {
     const { progress, typeId, courseId } = progressData
-
     await saveRecordBlockly({
       brpZtId: props.courseData.ztId,
       brpCtId: typeId,
@@ -454,6 +455,20 @@ const handleSaveProgress = async (progressData) => {
     console.error('保存视频进度失败:', error)
   }
 }
+// 保存bockly进度接口
+const saveBlocklyProgress = async () => {
+  try {
+    await saveRecordBlockly({
+      brpZtId: props.courseData.ztId,
+      brpCtId: props.courseData.bcType,
+      brpCourseId: props.courseData.id,
+      brpType: 'blockly',
+      brpProgress: 100
+    })
+  } catch (error) {
+    console.error('保存blockly进度失败:', error)
+  }
+}
 
 </script>