Prechádzať zdrojové kódy

[修改]成绩管理接入mock数据

soleil 7 rokov pred
rodič
commit
10efc85902

+ 1 - 0
mock/modules/resultstatistics/index.js

@@ -3,6 +3,7 @@ const router = express.Router();
 const resultstatisticsSerializer = require("../../serializers/resultstatistics/ResultstatisticsSerializer");
 
 router.route("/course/:courseId").post((req, res) => {
+  console.log("enter api");
   //获得用户信息
   res.send({
     data: [

+ 1 - 0
mock/routes.js

@@ -8,5 +8,6 @@ router.use("/group", require("./modules/group"));
 router.use("/question", require("./modules/question"));
 router.use("/assignment", require("./modules/assignment"));
 router.use("/review", require("./modules/review"));
+router.use("/resultstatistics", require("./modules/resultstatistics"));
 
 module.exports = router;

+ 1 - 0
src/api/_prefix.js

@@ -9,3 +9,4 @@ export const GROUP_MODULE = `${API_VERSION}/group`;
 export const QUESTION_MODULE = `${API_VERSION}/question`;
 export const ASSIGNMENT_MODULE = `${API_VERSION}/assignment`;
 export const REVIEW_MODULE = `${API_VERSION}/review`;
+export const RESULTSTATISTICS_MODULE = `${API_VERSION}/resultstatistics`;

+ 3 - 1
src/api/resultstatistics.js

@@ -6,5 +6,7 @@ import { RESULTSTATISTICS_MODULE } from "./_prefix";
  * @returns {Promise<{data:ResultstatisticsSerializer[]}>}
  */
 export const getStudentFinaleResult = (courseId = 123) => {
-  return request(`${RESULTSTATISTICS_MODULE}/course/${courseId}`);
+  return request(`${RESULTSTATISTICS_MODULE}/course/${courseId}`, {
+    method: "POST"
+  });
 };

+ 51 - 186
src/views/teacher/Result/index.vue

@@ -30,18 +30,18 @@
                 {{ props.row.id }}
               </b-table-column>
               <b-table-column label="学生姓名" width="120" centered>
-                {{ props.row.student }}
+                {{ props.row.user.nickname }}
               </b-table-column>
               <b-table-column label="文档作业" centered sortable>
-                80
+                {{ average(props.row.documents) }}
               </b-table-column>
 
               <b-table-column label="代码作业" centered sortable>
-                90
+                {{ average(props.row.codes) }}
               </b-table-column>
 
               <b-table-column label="互评作业" centered sortable>
-                100
+                {{ average(props.row.reviews) }}
               </b-table-column>
               <b-table-column
                 field="finalResult"
@@ -49,8 +49,8 @@
                 sortable
                 centered
               >
-                <span :class="['tag', type(props.row.finalResult)]">
-                  {{ props.row.finalResult }}
+                <span :class="['tag', type(getFinalResult(props.row))]">
+                  {{ getFinalResult(props.row) }}
                 </span>
               </b-table-column>
             </template>
@@ -66,30 +66,30 @@
                         <div class="homework-class">文档作业</div>
                         <div
                           class="result"
-                          v-for="item in props.row.documentHomeworkResult"
+                          v-for="item in props.row.documents"
                           :key="item.id"
                         >
-                          {{ item.name }} : {{ item.result }}
+                          {{ item.name }} : {{ item.score }}
                         </div>
                       </div>
                       <div class="document-homework">
                         <div class="homework-class">代码作业</div>
                         <div
                           class="result"
-                          v-for="item in props.row.codeHomeworkResult"
+                          v-for="item in props.row.codes"
                           :key="item.id"
                         >
-                          {{ item.name }} : {{ item.result }}
+                          {{ item.name }} : {{ item.score }}
                         </div>
                       </div>
                       <div class="document-homework">
                         <div class="homework-class">互评作业</div>
                         <div
                           class="result"
-                          v-for="item in props.row.reviewHomeworkResult"
+                          v-for="item in props.row.reviews"
                           :key="item.id"
                         >
-                          {{ item.name }} : {{ item.result }}
+                          {{ item.name }} : {{ item.score }}
                         </div>
                       </div>
                     </div>
@@ -175,180 +175,13 @@
 </template>
 <script>
 import { mapState } from "vuex";
-import { getStudentCourseReviewList } from "@/api/review";
+// import { getStudentCourseReviewList } from "@/api/review";
 import PageHeader from "@/components/PageHeader";
 import PageBody from "@/components/PageBody/index";
 import Chart from "chart.js";
 import BInput from "buefy/src/components/input/Input";
 import { required, numeric, between } from "vuelidate/lib/validators";
-
-const data = [
-  {
-    id: 1,
-    student: "小白",
-    documentHomeworkResult: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      },
-      {
-        id: 3,
-        name: "第三次作业",
-        result: 99
-      }
-    ],
-    charge: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      }
-    ],
-    score: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      }
-    ],
-    finalResult: 99
-  },
-  {
-    id: 2,
-    student: "yasen",
-    documentHomeworkResult: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      },
-      {
-        id: 3,
-        name: "第三次作业",
-        result: 99
-      }
-    ],
-    charge: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      }
-    ],
-    score: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      }
-    ],
-
-    finalResult: 79
-  },
-  {
-    id: 3,
-    student: "soleil",
-    documentHomeworkResult: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      },
-      {
-        id: 3,
-        name: "第三次作业",
-        result: 99
-      }
-    ],
-    charge: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      }
-    ],
-    score: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      }
-    ],
-    finalResult: 59
-  },
-  {
-    id: 4,
-    student: "xiaohan",
-    documentHomeworkResult: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      },
-      {
-        id: 3,
-        name: "第三次作业",
-        result: 99
-      }
-    ],
-    charge: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      }
-    ],
-    score: [
-      {
-        id: 1,
-        name: "第一次作业",
-        result: 80
-      },
-      {
-        id: 2,
-        name: "第二次作业",
-        result: 85
-      }
-    ],
-    finalResult: 99
-  }
-];
+import { getStudentFinaleResult } from "@/api/resultstatistics";
 
 export default {
   components: {
@@ -377,10 +210,11 @@ export default {
         { id: 1, title: "文档作业题目" },
         { id: 2, title: "代码作业题目" }
       ],
-      data,
+      data: [],
       isCardModalActive: false,
       myChart2: {},
-      percent: ""
+      percent: "",
+      finalResultPercentage: [20, 20, 20, 10, 10, 10, 10]
     };
   },
   methods: {
@@ -393,12 +227,43 @@ export default {
       } else if (number >= 80) {
         return "is-success";
       }
+    },
+    //计算平均成绩
+    average(resultList) {
+      let res = 0;
+      for (let item of resultList) {
+        res += item.score;
+      }
+      return res / resultList.length;
+    },
+    //计算总评
+    getFinalResult(result) {
+      let finalRes = 0;
+      let currentIndex = 0;
+      for (let docRes of result.documents) {
+        finalRes +=
+          docRes.score * (this.finalResultPercentage[currentIndex] / 100);
+        currentIndex++;
+      }
+      for (let codeRes of result.codes) {
+        finalRes +=
+          codeRes.score * (this.finalResultPercentage[currentIndex] / 100);
+        currentIndex++;
+      }
+      for (let reviewRes of result.reviews) {
+        finalRes +=
+          reviewRes.score * (this.finalResultPercentage[currentIndex] / 100);
+        currentIndex++;
+      }
+      return parseInt(finalRes);
     }
   },
   mounted() {
-    getStudentCourseReviewList(this.courses.id).then(
-      value => (this.review = value.data)
-    );
+    //获取成绩信息
+    getStudentFinaleResult(this.courses.id).then(res => {
+      console.log(res.data);
+      this.data = res.data;
+    });
     //绘制图表
     var resultChart = document.getElementById("result-chart");
     var myChart2 = new Chart(resultChart, {