Selaa lähdekoodia

props传递有问题

Michael Wang 6 vuotta sitten
vanhempi
commit
811b85ff40

+ 5 - 8
src/components/FaceRecognition/FaceRecognition.vue

@@ -109,15 +109,12 @@ export default {
       await this.faceCompare(captureFilePath);
     },
     async faceCompare(captureFilePath) {
-      const res = await this.$http.get(
-        "/api/ecs_core/studentFaceInfo/identityNumber",
-        {
-          params: {
-            identityNumber: this.user.identityNumber,
-            orgId: this.user.rootOrgId
-          }
+      const res = await this.$http.get("/api/ecs_core/student/getStudentInfo", {
+        params: {
+          identityNumber: this.user.identityNumber,
+          orgId: this.user.rootOrgId
         }
-      );
+      });
       const faceToken = res.data.faceToken;
       console.log(faceToken);
       console.log(captureFilePath);

+ 1 - 1
src/features/OnlineExam/Examing/ArrowNavView.vue

@@ -38,7 +38,7 @@ export default {
   created: function() {
     window.addEventListener("keyup", this.keyup);
   },
-  destroyed() {
+  beforeDestroy() {
     window.removeEventListener("keyup", this.keyup);
   },
   methods: {

+ 3 - 4
src/features/OnlineExam/Examing/BooleanQuestionView.vue

@@ -33,7 +33,7 @@ export default {
   created: function() {
     window.addEventListener("keyup", this.keyup);
   },
-  destroyed() {
+  beforeDestroy() {
     window.removeEventListener("keyup", this.keyup);
   },
   methods: {
@@ -49,12 +49,11 @@ export default {
           ["checkbox", "radio"].includes(document.activeElement.type))
       ) {
         if ("KeyY" === e.code) {
-          this.stuAnswer = "正确";
+          this.answerQuestion(this.examQuestion.id, "正确");
         }
         if ("KeyN" === e.code) {
-          this.stuAnswer = "错误";
+          this.answerQuestion(this.examQuestion.id, "错误");
         }
-        this.answerQuestion(this.examQuestion.id, this.stuAnswer);
       }
     },
     async answerQuestion(examQuestionId, stuAnswer) {

+ 24 - 24
src/features/OnlineExam/Examing/ExamingHome.vue

@@ -1,5 +1,5 @@
 <template>
-  <div v-if="exam" class="container">
+  <div v-if="exam && examQuestion" class="container">
     <div class="header">
       <RemainTime></RemainTime>
       <OverallProgress :exam-question-list="validQuestions"></OverallProgress>
@@ -30,17 +30,12 @@ import ArrowNavView from "./ArrowNavView.vue";
 import QuestionNavView from "./QuestionNavView.vue";
 import FaceRecognition from "../../../components/FaceRecognition/FaceRecognition";
 import { createNamespacedHelpers } from "vuex";
-const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
+const { mapState, mapMutations, mapGetters } = createNamespacedHelpers(
+  "examingHomeModule"
+);
 
 export default {
   name: "ExamingHome",
-  data() {
-    return {
-      preExamQuestion: null,
-      nextExamQuestion: null,
-      examQuestion: null
-    };
-  },
   async created() {
     await this.initData();
     if (!this.$route.query.examQuestionId) {
@@ -49,11 +44,10 @@ export default {
       );
       return;
     }
-    this.updateQuestion();
-  },
-  beforeRouteUpdate(to, from, next) {
-    this.updateQuestion(next);
   },
+  // beforeRouteUpdate(to, from, next) {
+  //   this.updateQuestion(next);
+  // },
   methods: {
     ...mapMutations(["updateExamState"]),
     async initData() {
@@ -69,15 +63,11 @@ export default {
       const examQuestionList = await this.$http.get(
         "/api/exam_question/?exam_record_id=" + this.$route.query.examRecordId
       );
-      const validQuestions = examQuestionList.data.filter(
-        q => q.nestedQuestion === false
-      );
 
       this.updateExamState({
         exam: exam.data,
         paperStruct: paperStruct.data,
-        examQuestionList: examQuestionList.data,
-        validQuestions
+        examQuestionList: examQuestionList.data
       });
     },
     updateQuestion: async function(next) {
@@ -93,11 +83,11 @@ export default {
 
       next && next();
       if (!this.exam) return;
-      this.examQuestion = this.examQuestionList.find(
-        eq => eq.id == this.$route.query.examQuestionId // number == string
-      );
-      this.preExamQuestion = this.validQuestions[this.examQuestion.orders - 2];
-      this.nextExamQuestion = this.validQuestions[this.examQuestion.orders];
+      // this.examQuestion = this.examQuestionList.find(
+      //   eq => eq.id == this.$route.query.examQuestionId // number == string
+      // );
+      // this.preExamQuestion = this.validQuestions[this.examQuestion.orders - 2];
+      // this.nextExamQuestion = this.validQuestions[this.examQuestion.orders];
     },
     async submitPaper() {
       //FIXME: submit precondition
@@ -106,7 +96,17 @@ export default {
     }
   },
   computed: {
-    ...mapState(["exam", "paperStruct", "examQuestionList", "validQuestions"])
+    ...mapState(["exam", "paperStruct", "examQuestionList"]),
+    ...mapGetters(["validQuestions"]),
+    examQuestion: vm =>
+      vm.examQuestionList &&
+      vm.examQuestionList.find(
+        eq => eq.id == vm.$route.query.examQuestionId // number == string
+      ),
+    preExamQuestion: vm =>
+      vm.examQuestion && vm.validQuestions[vm.examQuestion.orders - 2],
+    nextExamQuestion: vm =>
+      vm.examQuestion && vm.validQuestions[vm.examQuestion.orders]
   },
   components: {
     RemainTime,

+ 28 - 8
src/features/OnlineExam/Examing/FillBlankQuestionView.vue

@@ -6,7 +6,7 @@
     </div>
     <div v-for="(option, index) in stuAnswer.split('##')" :key="examQuestion.id + index" class="option">
       <span class="question-options">{{index+1}}. </span>
-      <input type="text" name="question" class="input-answer" :value="option" @input="inputAnswer" />
+      <input type="text" name="question" class="input-answer" :value="option" @input="inputAnswer" @blur="submitAnswer" />
     </div>
     <div class="reset">
       <i-button type="warning" size="large" @click="() => answerQuestion(examQuestion.id, null)">重置答案</i-button>
@@ -19,6 +19,15 @@ import QuestionBody from "./QuestionBody";
 import { createNamespacedHelpers } from "vuex";
 const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
 
+/**
+ * 1. 进入页面,this.stuAnswer从examQuestion.stuAnswer获得数据
+ * 2. 输入答案,this.stuAnswer更新,同时questionbody更新,但不提交答案
+ * 3. 输入框失去焦点,提交答案
+ * 4. 切换页面,this.stuAnswer从examQuestion获得数据
+ *
+ * FIXME: question没有更新。。。。
+ * */
+
 export default {
   name: "FillBlankQuestionView",
   data() {
@@ -34,13 +43,13 @@ export default {
   created() {
     this.prepareData();
   },
-  beforeUpdate() {
-    this.prepareData();
-    const realAnswer = this.stuAnswer.replace(/##/g, "").trim() || null;
-    if (realAnswer !== this.examQuestion.stuAnswer) {
-      this.answerQuestion(this.examQuestion.id, realAnswer);
-    }
-  },
+  // beforeUpdate() {
+  //   this.prepareData();
+  // const realAnswer = this.stuAnswer.replace(/##/g, "").trim() || null;
+  // if (realAnswer !== this.examQuestion.stuAnswer) {
+  //   this.answerQuestion(this.examQuestion.id, realAnswer);
+  // }
+  // },
   methods: {
     ...mapMutations(["updateExamQuestionAnswer"]),
     prepareData() {
@@ -79,6 +88,17 @@ export default {
           (answers.shift() || questionNumber - answers.length) +
           "</span>"
       );
+    },
+    submitAnswer() {
+      const realAnswer = this.stuAnswer.replace(/##/g, "").trim() || null;
+      if (realAnswer !== this.examQuestion.stuAnswer) {
+        this.answerQuestion(this.examQuestion.id, realAnswer);
+      }
+    }
+  },
+  watch: {
+    examQuestion: function() {
+      this.prepareData();
     }
   },
   components: {

+ 24 - 14
src/features/OnlineExam/Examing/MultipleQuestionView.vue

@@ -11,13 +11,15 @@
       <span class="question-options" v-html="option.content"></span>
     </div>
     <div class="reset">
-      <i-button type="warning" size="large" @click="resetQuestion(examQuestion.id)">重置答案</i-button>
+      <i-button type="warning" size="large" @click="() => answerQuestion(examQuestion.id, null)">重置答案</i-button>
     </div>
   </div>
 </template>
 
 <script>
 import QuestionBody from "./QuestionBody";
+import { createNamespacedHelpers } from "vuex";
+const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
 
 const optionName = ["A", "B", "C", "D", "E", "F"];
 export default {
@@ -35,10 +37,14 @@ export default {
   created: function() {
     window.addEventListener("keyup", this.keyup);
   },
-  destroyed() {
+  beforeDestroy() {
     window.removeEventListener("keyup", this.keyup);
   },
+  beforeUpdate() {
+    this.answerQuestion(this.examQuestion.id, this.stuAnswer);
+  },
   methods: {
+    ...mapMutations(["updateExamQuestionAnswer"]),
     keyup(e) {
       // console.log(e);
       // console.log(document.activeElement.type);
@@ -76,23 +82,27 @@ export default {
           .sort()
           .join("");
       }
-      this.answerQuestion();
-    },
-    answerQuestion: function() {
-      this.$http.put("/api/exam_question/" + this.examQuestion.id, {
-        stuAnswer: this.stuAnswer
-      });
+      // this.answerQuestion(this.examQuestion.id, this.stuAnswer);
     },
-    resetQuestion: function(examQuestionId) {
-      this.stuAnswer = "";
-      this.$http.put("/api/exam_question/" + examQuestionId, {
-        stuAnswer: null
-      });
+    async answerQuestion(examQuestionId, stuAnswer) {
+      let realAnswer = stuAnswer;
+      if (stuAnswer === "") {
+        realAnswer = null;
+      }
+      if (realAnswer !== this.examQuestion.stuAnswer) {
+        await this.$http.put("/api/exam_question/" + examQuestionId, {
+          stuAnswer: realAnswer
+        });
+        this.updateExamQuestionAnswer({
+          examQuestionId,
+          stuAnswer: realAnswer
+        });
+      }
     }
   },
   watch: {
     examQuestion: function() {
-      this.stuAnswer = this.examQuestion.stuAnswer;
+      this.stuAnswer = this.examQuestion.stuAnswer || "";
     }
   },
   components: {

+ 3 - 3
src/features/OnlineExam/Examing/QuestionView.vue

@@ -1,7 +1,6 @@
 <template>
   <div v-if="question && examQuestion" class="question-view">
     <div class="sign-button">
-      <!-- <i-button :icon="examQuestion.isSign ? 'ios-star':'ios-star-outline'" style="color: yellow" size="large" @click="toggleSign"></i-button> -->
       <Icon :type="examQuestion.isSign ? 'ios-star':'ios-star-outline'" :style="{color: '#ffcc00'}" class="star" @click="toggleSign" />
     </div>
     <template v-if="question.questionType === 'SINGLE_ANSWER_QUESTION'">
@@ -43,6 +42,9 @@ export default {
   props: {
     examQuestion: Object
   },
+  created() {
+    this.updateQuestion();
+  },
   methods: {
     async updateQuestion() {
       if (!this.examQuestion) {
@@ -54,7 +56,6 @@ export default {
             this.examQuestion.parentQuestion.questionId)
       );
       const question = res.data;
-      // const examQuestion = this.examQuestion;
 
       const transferWellNumberAndTrustInBody = function(repQuestion) {
         //将题干中的三个#替换为下划线
@@ -73,7 +74,6 @@ export default {
             .replace(/##(\d+)##/g, function(a, b) {
               return "__" + parseInt(b) + "__";
             });
-          // repQuestion.body = $sce.trustAsHtml(repQuestion.body);
         }
       };
       const initQuestion = function(repQuestion) {

+ 14 - 13
src/features/OnlineExam/Examing/SingleQuestionView.vue

@@ -18,6 +18,8 @@
 
 <script>
 import QuestionBody from "./QuestionBody";
+import { createNamespacedHelpers } from "vuex";
+const { mapState, mapMutations } = createNamespacedHelpers("examingHomeModule");
 
 const optionName = ["A", "B", "C", "D", "E", "F"];
 export default {
@@ -35,13 +37,15 @@ export default {
   created: function() {
     window.addEventListener("keyup", this.keyup);
   },
-  destroyed() {
+  beforeDestroy() {
     window.removeEventListener("keyup", this.keyup);
   },
+  beforeUpdate() {
+    this.answerQuestion(this.examQuestion.id, this.stuAnswer);
+  },
   methods: {
+    ...mapMutations(["updateExamQuestionAnswer"]),
     keyup(e) {
-      // console.log(e);
-      // console.log(document.activeElement.type);
       if (
         ["BODY", "A", "BUTTON", "DIV"].includes(
           document.activeElement.tagName
@@ -55,19 +59,16 @@ export default {
             .includes(e.code)
         ) {
           this.stuAnswer = e.code[3];
-          this.answerQuestion(this.examQuestion.id, this.stuAnswer);
         }
       }
     },
-    answerQuestion: function(examQuestionId, stuAnswer) {
-      this.stuAnswer = stuAnswer;
-      this.$http.put("/api/exam_question/" + examQuestionId, { stuAnswer });
-    },
-    resetQuestion: function(examQuestionId) {
-      this.stuAnswer = null;
-      this.$http.put("/api/exam_question/" + examQuestionId, {
-        stuAnswer: null
-      });
+    async answerQuestion(examQuestionId, stuAnswer) {
+      if (stuAnswer !== this.examQuestion.stuAnswer) {
+        await this.$http.put("/api/exam_question/" + examQuestionId, {
+          stuAnswer
+        });
+        this.updateExamQuestionAnswer({ examQuestionId, stuAnswer });
+      }
     }
   },
   watch: {

+ 6 - 9
src/features/OnlineExam/OnlineExamFaceCheckModal.vue

@@ -44,16 +44,13 @@ export default {
     course: Object
   },
   async created() {
-    const res = await this.$http.get(
-      "/api/ecs_core/studentFaceInfo/identityNumber",
-      {
-        params: {
-          identityNumber: this.$store.state.user.identityNumber,
-          orgId: this.$store.state.user.rootOrgId
-        }
+    const res = await this.$http.get("/api/ecs_core/student/getStudentInfo", {
+      params: {
+        identityNumber: this.$store.state.user.identityNumber,
+        orgId: this.$store.state.user.rootOrgId
       }
-    );
-    this.userPhoto = res.data.student.photoPath;
+    });
+    this.userPhoto = res.data.photoPath;
     // FIXME: 以后api返回的是绝对路径
     if (this.userPhoto.startsWith("http") === false) {
       this.userPhoto =

+ 1 - 1
src/features/OnlineExam/OnlineExamList.vue

@@ -55,7 +55,7 @@ export default {
     this.getNow();
     this.intervalID = setInterval(this.getNow, 1000);
   },
-  destroyed() {
+  beforeDestroy() {
     clearInterval(this.intervalID);
   },
   methods: {

+ 12 - 5
src/store.js

@@ -25,7 +25,6 @@ const examingHomeModule = {
     exam: null,
     paperStruct: null,
     examQuestionList: null,
-    validQuestions: null,
     questionFilterType: "ALL"
   },
   mutations: {
@@ -36,15 +35,23 @@ const examingHomeModule = {
       state.questionFilterType = type;
     },
     updateExamQuestionAnswer(state, { examQuestionId, stuAnswer }) {
-      state.validQuestions.forEach(eq => {
-        if (eq.id == examQuestionId) {
-          eq.stuAnswer = stuAnswer;
+      state.examQuestionList = state.examQuestionList.map(eq => {
+        if (eq.id === examQuestionId) {
+          return Object.assign({}, eq, { stuAnswer });
         }
+        return eq;
       });
     }
   },
   actions: {},
-  getters: {}
+  getters: {
+    validQuestions: state => {
+      return (
+        state.examQuestionList &&
+        state.examQuestionList.filter(q => q.nestedQuestion === false)
+      );
+    }
+  }
 };
 
 let initUser = {};