فهرست منبع

优化语音作答题逻辑

Michael Wang 6 سال پیش
والد
کامیت
1c28791bfe

+ 2 - 1
src/features/OnlineExam/Examing/ExamingEnd.vue

@@ -158,7 +158,8 @@ export default {
     this.updateExamState({
       exam: null,
       paperStruct: null,
-      examQuestionList: null
+      examQuestionList: null,
+      questionAudioFileUrl: []
     });
   },
   computed: {

+ 39 - 3
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -234,7 +234,8 @@ export default {
     this.updateExamState({
       exam: null,
       paperStruct: null,
-      examQuestionList: null
+      examQuestionList: null,
+      questionAudioFileUrl: []
     });
     this.$Modal.remove();
   },
@@ -244,6 +245,7 @@ export default {
   methods: {
     ...mapMutations([
       "updateExamState",
+      "updateExamQuestion",
       "toggleSnapNow",
       "updateExamResult",
       "resetExamQuestionDirty"
@@ -352,7 +354,8 @@ export default {
         exam: exam,
         paperStruct: paperStruct,
         examQuestionList: examQuestionList,
-        allAudioPlayTimes: JSON.parse(examQuestionList[0].audioPlayTimes) || []
+        allAudioPlayTimes: JSON.parse(examQuestionList[0].audioPlayTimes) || [],
+        questionAudioFileUrl: []
       });
       // console.log(examQuestionList);
       // console.log(examQuestionList.find(v => v.answerType === "SINGLE_AUDIO"));
@@ -537,7 +540,8 @@ export default {
       "snapNow",
       "snapProcessingCount",
       "shouldSubmitPaper",
-      "remainTime"
+      "remainTime",
+      "questionAudioFileUrl"
     ]),
     previousQuestionOrder: vm => {
       if (vm.examQuestion().order > 1) {
@@ -560,6 +564,38 @@ export default {
     },
     shouldSubmitPaper() {
       this.realSubmitPaper();
+    },
+    questionAudioFileUrl(value) {
+      // console.log(this.examQuestion.studentAnswer);
+      // console.log("watch", value);
+      const examRecordDataId = this.$route.params.examRecordDataId;
+      const that = this;
+      for (const q of value) {
+        if (!q.saved) {
+          this.$http
+            .post(
+              "/api/ecs_oe_student/examControl/confirmAudioUploadSaveStatus",
+              {
+                examRecordDataId,
+                filePath: q.audioFileUrl,
+                order: q.order
+              }
+            )
+            .then(() => {
+              that.updateExamQuestion({
+                order: q.order,
+                studentAnswer: q.audioFileUrl
+              });
+              q.saved = true;
+            })
+            .catch(() => {
+              this.$Message.error({
+                content: "更新音频题答案失败!",
+                duration: 10
+              });
+            });
+        }
+      }
     }
     // examQuestionList(val, oldVal) {
     //   // console.log(val, oldVal);

+ 4 - 39
src/features/OnlineExam/Examing/TextQuestionView.vue

@@ -182,7 +182,7 @@ export default {
     },
     fetchQRCode() {
       if (this.examQuestion.answerType === "SINGLE_AUDIO") {
-        getQRCode(this.examQuestion.questionId);
+        getQRCode(this.examQuestion.order);
       }
     }
   },
@@ -194,48 +194,17 @@ export default {
     questionQrCode(value) {
       // console.log(this.examQuestion.studentAnswer);
       // console.log("watch", value);
-      if (value.questionId === this.examQuestion.questionId) {
+      if (value.order === this.examQuestion.order) {
         this.qrValue = value.qrCode;
       }
     },
     questionQrCodeScanned(value) {
       // console.log(this.examQuestion.studentAnswer);
       // console.log("watch", value);
-      if (value.questionId === this.examQuestion.questionId) {
+      if (value.order === this.examQuestion.order) {
         this.qrScanned = true;
       }
     },
-    questionAudioFileUrl(value) {
-      // console.log(this.examQuestion.studentAnswer);
-      // console.log("watch", value);
-      const examRecordDataId = this.$route.params.examRecordDataId;
-      const that = this;
-      for (const q of value) {
-        if (q.questionId === this.examQuestion.questionId) {
-          this.$http
-            .post(
-              "/api/ecs_oe_student/examControl/confirmAudioUploadSaveStatus",
-              {
-                examRecordDataId,
-                filePath: q.audioFileUrl,
-                questionId: this.examQuestion.questionId
-              }
-            )
-            .then(() => {
-              that.updateExamQuestion({
-                order: that.examQuestion.order,
-                studentAnswer: q.audioFileUrl
-              });
-            })
-            .catch(() => {
-              this.$Message.error({
-                content: "更新音频题答案失败!",
-                duration: 10
-              });
-            });
-        }
-      }
-    },
     studentAnswer() {
       let realAnswer = null;
       if (this.studentAnswer) {
@@ -258,11 +227,7 @@ export default {
     }
   },
   computed: {
-    ...mapState([
-      "questionQrCode",
-      "questionQrCodeScanned",
-      "questionAudioFileUrl"
-    ]),
+    ...mapState(["questionQrCode", "questionQrCodeScanned"]),
     isSyncState() {
       return this.examQuestion.order == this.$route.params.order;
     },

+ 15 - 6
src/features/OnlineExam/Examing/ws.js

@@ -6,10 +6,10 @@ let shouldReconnect = true;
 let heartbeatId = null;
 const RECONNECT_INTERVAL = 3000;
 const HEARTBEAT_INTERVAL = 50 * 1000;
+let reconnectNumber = 0;
 
 export function openWS({ examRecordDataId }) {
   console.log("in openWS", examRecordDataId);
-  console.log("in openWS", store);
   ws = new WebSocket(
     "ws://192.168.10.39:8010" +
       `/audioAnswerWebSocket/${examRecordDataId}/${store.state.user.key}/${
@@ -19,6 +19,7 @@ export function openWS({ examRecordDataId }) {
 
   ws.onopen = event => {
     console.log("open ws", event);
+    reconnectNumber = 0;
 
     ws.onmessage = processWSMessage;
 
@@ -29,6 +30,14 @@ export function openWS({ examRecordDataId }) {
         console.log("close -> reconnect");
         setTimeout(() => {
           // tryWSReconnect();
+          reconnectNumber++;
+          if (reconnectNumber >= 5) {
+            Message.error({
+              content: "Websocket重连失败",
+              duration: 3,
+              closable: true
+            });
+          }
           openWS({ examRecordDataId });
         }, RECONNECT_INTERVAL);
       } else {
@@ -60,12 +69,12 @@ export function closeWsWithoutReconnect() {
   ws.close();
 }
 
-export function getQRCode(questionId) {
+export function getQRCode(order) {
   if (ws.readyState === ws.OPEN) {
     ws.send(
       JSON.stringify({
         eventType: "GET_QR_CODE",
-        questionId
+        order
       })
     );
     return true;
@@ -93,19 +102,19 @@ function processWSMessage(event) {
       console.log("get qrcode", res);
       store.commit("examingHomeModule/setQuestionQrCode", {
         qrCode: res.data.qrCode,
-        questionId: res.data.questionId
+        order: res.data.order
       });
       break;
     case "SCAN_QR_CODE":
       console.log("wx scanned qrcode", res);
       store.commit("examingHomeModule/setQuestionQrCodeScanned", {
-        questionId: res.data.questionId
+        order: res.data.order
       });
       break;
     case "GET_AUDIO_ANSWER":
       console.log("get audio url", res);
       store.commit("examingHomeModule/setQuestionAudioFileUrl", {
-        questionId: res.data.questionId,
+        order: res.data.order,
         audioFileUrl: res.data.audioFileUrl
       });
       break;

+ 4 - 1
src/store.js

@@ -155,10 +155,13 @@ const examingHomeModule = {
       state.questionQrCodeScanned = payload;
     },
     setQuestionAudioFileUrl(state, payload) {
+      state.questionAudioFileUrl = state.questionAudioFileUrl.filter(
+        v => !v.saved
+      );
       let ary = state.questionAudioFileUrl;
       let found = false;
       for (const i of ary) {
-        if (i.questionId === payload.questionId) {
+        if (i.order === payload.order) {
           i.audioFileUrl = payload.audioFileUrl;
           found = true;
           break;