Browse Source

导入试题提交校验优化

zhangjie 1 năm trước cách đây
mục cha
commit
02926f5f57

+ 2 - 2
src/modules/card/components/CardDesign.vue

@@ -330,7 +330,7 @@ export default {
       } else {
         this.initPageData();
       }
-      this.addWatch();
+      // this.addWatch();
     },
     initPageData() {
       if (this.paperSimpleStruct) {
@@ -378,7 +378,7 @@ export default {
     },
     addWatch() {
       this.$watch("cardConfig", (val) => {
-        const element = getCardHeadModel(val);
+        const element = getCardHeadModel(val.elements[0]);
         this.modifyCardHead(element);
         this.$nextTick(() => {
           this.rebuildPages();

+ 13 - 0
src/modules/card/views/CardBuild.vue

@@ -23,6 +23,12 @@
             >
               <div id="topic-column" class="page-column-main">
                 <div class="page-column-body">
+                  <!-- card-head-sample -->
+                  <card-head-sample
+                    :data="cardHeadSampleData"
+                    id="simple-card-head"
+                    v-if="topics.length && cardHeadSampleData"
+                  ></card-head-sample>
                   <!-- topic element -->
                   <topic-element-preview
                     v-for="element in topics"
@@ -48,6 +54,7 @@ import html2canvas from "html2canvas";
 import { getPageInitElements } from "../pageModel";
 import { buildCardFromPaperSimpleStruct } from "../autoBuild/simplePaperCard";
 import { saveCard } from "../api";
+import { getCardHeadModel } from "../elementModel";
 
 export default {
   name: "CardBuild",
@@ -65,6 +72,12 @@ export default {
       "topics",
       "pages",
     ]),
+    cardHeadSampleData() {
+      if (!this.cardConfig["pageSize"]) return;
+      const data = getCardHeadModel(this.cardConfig);
+      data.isSimple = true;
+      return data;
+    },
   },
   mounted() {
     this.initData();

+ 1 - 1
src/modules/card/views/CardManage.vue

@@ -522,7 +522,7 @@ export default {
       });
     },
     toView(row) {
-      const href = this.getRouterPath({
+      const { href } = this.$router.resolve({
         name: "CardPreview",
         params: {
           viewType: "view",

+ 47 - 7
src/modules/question/components/QuestionImportEdit.vue

@@ -148,7 +148,7 @@
 import { calcSum, deepCopy, objTypeOf, randomCode } from "@/plugins/utils";
 import QuestionImportPaperEdit from "./QuestionImportPaperEdit.vue";
 import UploadButton from "@/components/UploadButton.vue";
-import { isAnEmptyRichText } from "@/utils/utils";
+import { getRichTextAnswerPointCount, isAnEmptyRichText } from "@/utils/utils";
 import {
   questionImportPaperSave,
   questionImportParseRichText,
@@ -674,8 +674,8 @@ export default {
 
           // 选项
           if (SELECT_QUESTION.includes(questionType)) {
-            if (!question.quesOptions.length) {
-              qErrInfo.push(`没有选项`);
+            if (question.quesOptions.length < 2) {
+              qErrInfo.push(`选项少于2个`);
             }
             if (
               question.quesOptions.some((option) =>
@@ -699,11 +699,51 @@ export default {
             qErrInfo = [];
           }
 
+          // 完形填空
+          if (questionType === "READING_COMPREHENSION") {
+            const answerPointCount = getRichTextAnswerPointCount(quesBody);
+            if (answerPointCount !== question.subQuestions.length) {
+              errInfos.push(
+                `第${detail.number}大题题干答题点数量与选项数不匹配`
+              );
+            }
+            if (
+              question.subQuestions.some(
+                (q) => q.questionType !== "SINGLE_ANSWER_QUESTION"
+              )
+            ) {
+              errInfos.push(`第${detail.number}大题存在不是单选题的子题`);
+            }
+          }
+
+          // 听力题
+          if (questionType === "LISTENING_QUESTION") {
+            if (
+              question.subQuestions.some(
+                (q) => q.questionType !== "SINGLE_ANSWER_QUESTION"
+              )
+            ) {
+              errInfos.push(`第${detail.number}大题存在不是单选题的子题`);
+            }
+          }
+
           // 选词填空、段落匹配,单用模式时校验输入答案是否重复
           if (
             MATCHING_QUESTION.includes(questionType) &&
             question.quesParam.matchingMode === 1
           ) {
+            // 选词填空
+            if (questionType === "BANKED_CLOZE") {
+              const answerPointCount = getRichTextAnswerPointCount(quesBody);
+              if (answerPointCount > question.quesOptions.length) {
+                errInfos.push(`第${detail.number}大题题干答题点数量超过选项数`);
+              }
+            } else {
+              if (question.subQuestions.length > question.quesOptions.length) {
+                errInfos.push(`第${detail.number}大题小题数量超过选项数`);
+              }
+            }
+
             let selectedAnswer = [],
               errorQuestionIndexs = [];
             question.subQuestions.forEach((subq, sindex) => {
@@ -718,7 +758,7 @@ export default {
               errInfos.push(
                 `第${
                   detail.number
-                }大题${errorQuestionIndexs.join()}小题答案重复`
+                }大题${errorQuestionIndexs.join()}小题答案重复`
               );
             }
           }
@@ -737,11 +777,11 @@ export default {
               qErrInfo.push(`没有题干`);
             }
             if (
-              SELECT_QUESTION.includes(subq.subqType) &&
+              SELECT_QUESTION.includes(subq.questionType) &&
               !MATCHING_QUESTION.includes(questionType)
             ) {
-              if (!subq.quesOptions.length) {
-                qErrInfo.push(`没有选项`);
+              if (subq.quesOptions.length < 2) {
+                qErrInfo.push(`选项少于2个`);
               }
               if (
                 subq.quesOptions.some((option) =>

+ 10 - 4
src/modules/questions/views/GenPaper.vue

@@ -254,7 +254,7 @@
             v-model="exportModel.exportContent"
             @change="exportContentChange"
           >
-            <el-radio label="PAPER">试卷</el-radio>
+            <el-radio v-if="exportModel.id" label="PAPER">试卷</el-radio>
             <el-radio label="ANSWER">答案</el-radio>
             <el-radio label="THEMIS_PACKAGE">数据包</el-radio>
             <el-radio label="CARD_PACKAGE">题卡数据</el-radio>
@@ -855,6 +855,12 @@ export default {
         this.isShow = false;
         this.exportModel.exportContent = "";
         this.exportModel.templateId = "";
+        // 多于两个试卷时候,将无法导出试卷。todo
+        if (this.selectedPaperIds.length === 1) {
+          this.exportModel.id = this.selectedPaperIds[0];
+        } else {
+          this.exportModel.id = "";
+        }
       } else {
         this.$notify({
           message: "请勾选导出的数据",
@@ -1045,7 +1051,7 @@ export default {
         seqMode: this.exportModel.seqMode,
         configModalForm,
       };
-      const url = this.getRouterPath({
+      const { href } = this.$router.resolve({
         name: "PaperTemplateBuild",
         params: {
           paperId: this.exportModel.id,
@@ -1056,8 +1062,8 @@ export default {
         },
       });
 
-      // console.log(url);
-      this.paperPreviewUrl = url;
+      // console.log(href);
+      this.paperPreviewUrl = href;
     },
     registWindowSubmit() {
       window.submitPaperTemp = async ({

+ 18 - 0
src/utils/utils.js

@@ -48,3 +48,21 @@ export function numberToUpperCase(val) {
 
   return String.fromCharCode(64 + val);
 }
+
+/**
+ * 获取富文本数据中答题点个数
+ * @param {richText} richText
+ * @returns
+ */
+export function getRichTextAnswerPointCount(richText) {
+  if (isAnEmptyRichText(richText)) return 0;
+
+  let count = 0;
+  richText.sections.forEach((section) => {
+    section.blocks.forEach((block) => {
+      if (block.type === "cloze") count++;
+    });
+  });
+
+  return count;
+}