Browse Source

fix试题内容没有事先获取的 bug

Michael Wang 6 years ago
parent
commit
82c388d05c

+ 14 - 7
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -131,7 +131,11 @@ export default {
       "resetExamQuestionDirty"
     ]),
     async initData() {
-      const [exam, paperStruct, examQuestionListData] = await Promise.all([
+      const [
+        examData,
+        paperStructData,
+        examQuestionListData
+      ] = await Promise.all([
         this.$http.get("/api/ecs_exam_work/exam/" + this.$route.params.examId),
         this.$http.get(
           "/api/ecs_oe_student/examRecordPaperStruct/getExamRecordPaperStruct?examRecordDataId=" +
@@ -139,18 +143,21 @@ export default {
         ),
         this.$http.get("/api/ecs_oe_student/examQuestion/findExamQuestionList")
       ]);
+      const [exam, paperStruct] = [examData.data, paperStructData.data];
+
+      let examQuestionList = examQuestionListData.data;
 
       if (
-        exam.data === undefined ||
-        paperStruct.data === undefined ||
-        examQuestionListData.data === undefined
+        exam === undefined ||
+        paperStruct === undefined ||
+        examQuestionListData === undefined
       ) {
         this.$Message.error("获取试卷信息失败");
         this.logout();
         return;
       }
 
-      if (exam.data.examType === "PRACTICE") {
+      if (exam.examType === "PRACTICE") {
         const practiceType = (await this.$http.get(
           "/api/ecs_exam_work/exam/examOrgProperty/" +
             this.$route.params.examId +
@@ -162,7 +169,7 @@ export default {
       // init subNumber
       let questionId = null;
       let i = 1;
-      let examQuestionList = examQuestionListData.data;
+
       examQuestionList = examQuestionList.map(eq => {
         if (questionId == eq.questionId) {
           eq.subNumber = i++;
@@ -212,7 +219,7 @@ export default {
       });
 
       this.updateExamState({
-        exam: exam.data,
+        exam: exam,
         paperStruct: paperStruct,
         examQuestionList: examQuestionList
       });

+ 9 - 4
src/features/OnlineExam/Examing/QuestionView.vue

@@ -57,13 +57,18 @@ export default {
   methods: {
     ...mapMutations(["updateExamQuestion"]),
     async updateQuestion() {
+      const currentExamQuestion = this.examQuestion; // 避免以后执行时,this.examQuestion换掉了
       const res = await this.$http.get(
         "/api/ecs_oe_student/examQuestion/getQuestionContent?questionId=" +
           this.examQuestion.questionId
       );
 
+      if (res.data === undefined) {
+        return;
+      }
+
       this.updateExamQuestion({
-        order: this.examQuestion.order,
+        order: currentExamQuestion.order,
         getQuestionContent: true
       });
       const question = res.data;
@@ -129,16 +134,16 @@ export default {
       } else {
         this.parentQuestionBody = null;
         initQuestion(
-          question.questionUnitList[this.examQuestion.subNumber - 1]
+          question.questionUnitList[currentExamQuestion.subNumber - 1]
         );
       }
 
       this.question =
-        question.questionUnitList[this.examQuestion.subNumber - 1];
+        question.questionUnitList[currentExamQuestion.subNumber - 1];
 
       {
         // cache next question content
-        const currentOrder = this.examQuestion.order;
+        const currentOrder = currentExamQuestion.order;
         if (currentOrder < this.examQuestionList.length) {
           this.$http.get(
             "/api/ecs_oe_student/examQuestion/getQuestionContent?questionId=" +