Kaynağa Gözat

在线练习:显示批次和科目名称

Michael Wang 6 yıl önce
ebeveyn
işleme
a07e33bbf7

+ 1 - 1
src/features/OnlinePractice/OnlinePracticeHome.vue

@@ -14,7 +14,7 @@
         </Select>
       </div>
 
-      <OnlinePracticeList :courses="courses"></OnlinePracticeList>
+      <OnlinePracticeList :courses="courses" :examList="examList"></OnlinePracticeList>
 
     </div>
   </main-layout>

+ 4 - 1
src/features/OnlinePractice/OnlinePracticeList.vue

@@ -44,6 +44,7 @@ export default {
     return { now: new Date(), selectedCourse: null };
   },
   props: {
+    examList: Array,
     courses: Array
   },
   created() {
@@ -75,7 +76,9 @@ export default {
       this.$router.push(
         `/online-practice/exam/${course.examId}/list?examStudentId=${
           course.examStudentId
-        }`
+        }&examName=${encodeURIComponent(
+          course.examName
+        )}&courseName=${encodeURIComponent(course.courseName)}`
       );
     }
   },

+ 16 - 5
src/features/OnlinePractice/OnlinePracticeRecordList.vue

@@ -9,8 +9,8 @@
     <div class="home">
 
       <div style="display: grid; grid-template-columns: repeat(4, 1fr); margin-bottom: 20px; text-align: left">
-        <div>批次: <span></span></div>
-        <div>科目: <span></span></div>
+        <div>批次: <span>{{examName}}</span></div>
+        <div>科目: <span>{{courseName}}</span></div>
         <div>平均正确率: <span>{{aveAccuracy}}%</span></div>
         <div>最高正确率: <span>{{maxAccuracy}}%</span></div>
       </div>
@@ -64,7 +64,7 @@ import moment from "moment";
 export default {
   name: "OnlinePracticeRecordList",
   data() {
-    return { exam: null, recordList: [] };
+    return { recordList: [] };
   },
   async created() {
     const res = await this.$http.get(
@@ -86,8 +86,19 @@ export default {
     }
   },
   computed: {
+    examName() {
+      return this.$route.query.examName;
+    },
+    courseName() {
+      return this.$route.query.courseName;
+    },
     maxAccuracy() {
-      return Math.max(...this.recordList.map(v => v.objectiveAccuracy)) || 0;
+      if (this.recordList.length === 0) {
+        return 0;
+      }
+      return Math.max(...this.recordList.map(v => v.objectiveAccuracy)).toFixed(
+        2
+      );
     },
     aveAccuracy() {
       if (this.recordList.length === 0) {
@@ -96,7 +107,7 @@ export default {
       return (
         this.recordList.map(v => v.objectiveAccuracy).reduce((a, b) => a + b) /
         this.recordList.length
-      );
+      ).toFixed(2);
     }
   }
 };