Переглянути джерело

fix: 权重计算精度以及待办任务数量显示问题

zhangjie 10 місяців тому
батько
коміт
456cf758fa

+ 4 - 4
src/modules/exam/store.js

@@ -99,17 +99,17 @@ const actions = {
         func: markWaitTaskCount,
       },
     ];
-    const countAll = task
-      .filter((item) => state.waitTypes.includes(item.type))
-      .map((item) => item.func());
+    const taskList = task.filter((item) => state.waitTypes.includes(item.type));
+    const countAll = taskList.map((item) => item.func());
     const counts = await Promise.all(countAll).catch(() => {});
 
     if (!counts) return;
 
     const waitTask = {};
     counts.forEach((count, index) => {
-      waitTask[task[index].type] = count;
+      waitTask[taskList[index].type] = count;
     });
+
     commit("setWaitTask", waitTask);
 
     const count = calcSum(counts);

+ 9 - 6
src/modules/target/components/course-examine/CourseExamineWeight.vue

@@ -62,7 +62,7 @@
 
 <script>
 import { courseExamineWeightDetail, courseExamineWeightSave } from "../../api";
-import { calcSum } from "@/plugins/utils";
+import { calcSum, toPrecision } from "@/plugins/utils";
 
 export default {
   name: "course-examine-weight",
@@ -90,6 +90,9 @@ export default {
       this.columns = [];
       await this.getList();
     },
+    calcSumPrecision(dList) {
+      return toPrecision(calcSum(dList), 2);
+    },
     async getList() {
       const res = await courseExamineWeightDetail({
         obeCourseOutlineId: this.rowData.id,
@@ -135,7 +138,7 @@ export default {
     },
     weightChange(rowIndex, cindex) {
       this.dataList.forEach((item, tindex) => {
-        item.totalWeight = calcSum(
+        item.totalWeight = this.calcSumPrecision(
           item.evaluationList.map((elem) => elem.weight || 0)
         );
       });
@@ -168,7 +171,7 @@ export default {
 
       // 所有课程目标都应该有设置权重
       this.dataList.forEach((item, tindex) => {
-        item.totalWeight = calcSum(
+        item.totalWeight = this.calcSumPrecision(
           item.evaluationList.map((elem) => elem.weight || 0)
         );
       });
@@ -182,7 +185,7 @@ export default {
       }
 
       // 目标整体权重
-      const totalWeight = calcSum(
+      const totalWeight = this.calcSumPrecision(
         this.dataList.map((item) => item.totalWeight || 0)
       );
       if (totalWeight !== 100) {
@@ -218,13 +221,13 @@ export default {
         }
 
         if (index === lastNo) {
-          sums[index] = calcSum(
+          sums[index] = this.calcSumPrecision(
             this.dataList.map((item) => item.totalWeight || 0)
           );
           return;
         }
 
-        sums[index] = calcSum(
+        sums[index] = this.calcSumPrecision(
           this.dataList.map(
             (item) => item.evaluationList[index - 1].weight || 0
           )