Browse Source

feat: 仲裁处理提交时做数据校验

chenhao 3 years ago
parent
commit
c76ba34972
1 changed files with 35 additions and 1 deletions
  1. 35 1
      src/features/arbitrate/Arbitrate.vue

+ 35 - 1
src/features/arbitrate/Arbitrate.vue

@@ -28,7 +28,7 @@
 </template>
 
 <script setup lang="ts">
-import { onMounted, watch } from "vue";
+import { onMounted, watch, h } from "vue";
 import { store } from "@/store/store";
 import MarkHeader from "./MarkHeader.vue";
 import { useRoute } from "vue-router";
@@ -53,6 +53,8 @@ import { getPaper } from "@/api/jsonMark";
 import { getArbitrateHistory } from "@/api/arbitratePage";
 import EventBus from "@/plugins/eventBus";
 import { addFileServerPrefixToTask } from "@/utils/utils";
+import { isNumber } from "lodash-es";
+import type { Question } from "@/types";
 
 const route = useRoute();
 let isSingleStudent = !!route.query.historyId;
@@ -158,9 +160,41 @@ async function getOneOfStuTask() {
 
 const saveTaskToServer = async (unselective: boolean) => {
   if (!store.currentTask) return;
+  const markResult = store.currentTask.markResult;
+  if (!markResult) return;
   console.log("save inspect task to server");
   const mkey = "save_task_key";
   void message.loading({ content: "保存评卷任务...", key: mkey });
+  type SubmitError = {
+    question: Question;
+    index: number;
+    error: string;
+  };
+  const errors: SubmitError[] = [];
+  markResult.scoreList.forEach((score, index) => {
+    if (!store.currentTask) return;
+    const question = store.currentTask.questionList[index];
+    let error;
+    if (!isNumber(score)) {
+      error = `${question.mainNumber}-${question.subNumber} 没有赋分不能提交。`;
+    } else if (isNumber(question.maxScore) && score > question.maxScore) {
+      error = `${question.mainNumber}-${question.subNumber} 赋分大于最高分不能提交。`;
+    } else if (isNumber(question.minScore) && score < question.minScore) {
+      error = `${question.mainNumber}-${question.subNumber} 赋分小于最低分不能提交。`;
+    }
+    if (error) {
+      errors.push({ question, index, error });
+    }
+  });
+  if (errors.length) {
+    console.log(errors);
+    const msg = errors.map((v) => h("div", `${v.error}`));
+    return message.warning({
+      content: h("span", ["校验失败", ...msg]),
+      duration: 10,
+      key: mkey,
+    });
+  }
   let res;
   if (unselective) {
     res = await saveArbitrateTask(