فهرست منبع

fix:将视频片段的上传改为异步处理

lalala 1 سال پیش
والد
کامیت
4f37a81aca
3فایلهای تغییر یافته به همراه19 افزوده شده و 43 حذف شده
  1. 13 8
      src/apis/doubao.ts
  2. 4 16
      src/views/AiSpeakingPage/SpeakingPage.vue
  3. 2 19
      src/views/AiSpeakingPage/component/VoiceAnalysis.vue

+ 13 - 8
src/apis/doubao.ts

@@ -55,14 +55,19 @@ const doubaoApis = {
         });
     },
 
-    saveSigment:(userId : number, assignmentId: Number, sigmentUrl: String, duration: Number) => {
-        return  axiosInstance.get(`${SPEAKING_PREFIX }/saveSigment`, {
-            params: {
-                userId,
-                assignmentId,
-                sigmentUrl,
-                duration
-            }
+    saveSigment:(userId : number, assignmentId: Number, file: File, duration: Number) => {
+        const formData = new FormData();
+        formData.append('file',file);
+        formData.append('userId', userId.toString());
+        formData.append('assignmentId', assignmentId.toString());
+        formData.append('duration', duration.toString());
+        return  axiosInstance.post(`${SPEAKING_PREFIX }/saveSigment`, 
+        formData,
+        {
+            headers:{
+                'Content-Type': 'multipart/form-data'
+            },
+            timeout:300000
         });
     },
     getSigment:(userId : number, assignmentId: Number) => {

+ 4 - 16
src/views/AiSpeakingPage/SpeakingPage.vue

@@ -703,27 +703,16 @@ const saveHomework = async () => {
         const fileName = `user_${userId}_${assignmentId}_${Date.now()}`;
         let renameFile =new File([videoBlob], fileName +'.webm', { type: 'video/webm' })
         try {
-          fileApis
-          .uploadFile(renameFile)
+          doubaoApis
+          .saveSigment(userId, assignmentId,renameFile, duration)
           .then(res =>{
             recordedChunks.value = [];
             isHomeworkSaved.value = true;
             hasHomeworkSaved.value = true;
             isHomeworkStarted.value = false;
             ElMessage.success("视频片段暂存成功");
-            doubaoApis
-            .saveSigment(userId, assignmentId, res.data.data, duration)
-            .then(url =>{
-              console.log(url.data.data)
-              savedChunks.value = url.data.data;
-              loadingInstance.close();
-            })
-            .catch(err => {
-              ElMessage.error('保存出错啦,请重新尝试')
-              loadingInstance.close();
-            })
+            loadingInstance.close();
           })
-          
         } catch (error) {
           console.error("视频片段上传失败:", error);
           ElMessage.error("视频片段上传失败");
@@ -830,7 +819,6 @@ const resetHomework = async() => {
   .then(res =>{
     if(res.data.code == 200){
       recordedChunks.value = [];
-      savedChunks.value = [];
       chatMessages.value = [];
       isHomeworkSaved.value = false;
       isHomeworkStarted.value = false;
@@ -859,7 +847,7 @@ const submitHomework = async () => {
     return;
   }
   if(isHomeworkStarted.value){
-    ElMessage.warning("作业正在进行中,请存后再提交")
+    ElMessage.warning("作业正在进行中,请存后再提交")
     return;
   }
 

+ 2 - 19
src/views/AiSpeakingPage/component/VoiceAnalysis.vue

@@ -31,7 +31,7 @@
   import { ElEmpty } from "element-plus"; // 引入 Element Plus 的 Empty 组件
   import doubaoApis from "@/apis/doubao";
   import fileApis from "@/apis/file";
-import { filterFields } from "element-plus/es/components/form/src/utils";
+  import { filterFields } from "element-plus/es/components/form/src/utils";
 
 
   const props = defineProps({
@@ -44,24 +44,7 @@ import { filterFields } from "element-plus/es/components/form/src/utils";
       required: true,
     }
   })
-  const analysisResults = ref([
-    {
-      content: "My favorite animal is dog",
-      accuracyScore: 99.9,
-      fluencyScore: 85.5,
-      integrityScore: 92.3,
-      standardScore: 88.7,
-      totalScore: 91.6,
-      wordScoreList: [
-        { word: "My", totalScore: 95 },
-        { word: "favorite", totalScore: 90 },
-        { word: "animal", totalScore: 85 },
-        { word: "is", totalScore: 98 },
-        { word: "dog", totalScore: 92 },
-      ],
-    },
-  ]);
-  
+  const analysisResults = ref([]);
   const chartRefs = ref([]);
   const charts = ref([]);
   const voiceAnalysisContainerRef = ref(null);