Bladeren bron

feat: 导出答案模式调整

zhangjie 6 maanden geleden
bovenliggende
commit
079bc9e04c
1 gewijzigde bestanden met toevoegingen van 65 en 1 verwijderingen
  1. 65 1
      src/modules/questions/views/GenPaper.vue

+ 65 - 1
src/modules/questions/views/GenPaper.vue

@@ -437,21 +437,36 @@
         height="800"
       ></iframe>
     </div>
+
+    <!-- answer dom -->
+    <answer-template-view
+      v-if="paperJson"
+      ref="AnswerTemplateView"
+      id="answer-template-view"
+      class="preview-body"
+      :answerData="paperJson"
+      :pageCountMode="pageCountMode"
+      @rend-finished="rendFinished"
+    ></answer-template-view>
   </section>
 </template>
 
 <script>
 import PaperBuildConfig from "../../paper-export/components/PaperBuildConfig.vue";
+import AnswerTemplateView from "../../paper-export/components/AnswerTemplateView.vue";
 import { QUESTION_API } from "@/constants/constants";
 import { LEVEL_TYPE, PUBLICITY_LIST } from "../constants/constants";
 import { mapState } from "vuex";
 import { downloadByApi, downloadByBlob } from "@/plugins/download";
 import { paperTemplateListApi } from "../../paper-export/api";
 import { deepCopy } from "@/plugins/utils";
+import { paperDetailInfoApi } from "../../paper/api";
+import { buildPdf } from "@/plugins/htmlToPdf";
 
 export default {
   components: {
     PaperBuildConfig,
+    AnswerTemplateView,
   },
   data() {
     return {
@@ -527,6 +542,7 @@ export default {
       paperTempList: [],
       configSources: [],
       configModalForm: {},
+      paperJson: null,
     };
   },
   computed: {
@@ -1107,7 +1123,7 @@ export default {
       // console.log(href);
       this.paperPreviewUrl = href;
     },
-    toDownloadAnswerPdf() {
+    toDownloadAnswerPdf1() {
       if (this.downloading) return;
       this.downloading = true;
       window.answerSet = {
@@ -1127,6 +1143,54 @@ export default {
       });
       this.answerPreviewUrl = href;
     },
+    async toDownloadAnswerPdf() {
+      if (this.downloading) return;
+      this.downloading = true;
+
+      await this.getPaperJson().catch(() => {
+        this.downloading = false;
+        this.$message.error("生成答案pdf错误");
+      });
+    },
+    async rendFinished() {
+      const answerPdfName = `${this.exportModel.courseName}(${this.exportModel.courseCode})_${this.exportModel.paperName}_答案.pdf`;
+      await buildPdf({
+        elements: document
+          .getElementById("answer-template-view")
+          .querySelectorAll(".page-answer-flat"),
+        filename: answerPdfName,
+        pageSize: "A4",
+      }).catch((error) => {
+        console.error(error);
+        this.downloading = false;
+        this.$message.error("生成答案pdf错误");
+      });
+      this.paperJson = null;
+      this.$message.success("答案pdf生成成功");
+    },
+    async getPaperJson() {
+      const res = await paperDetailInfoApi({
+        paperId: this.exportModel.id,
+        seqMode: this.exportModel.seqMode,
+      });
+      this.paperJson = res.data;
+      this.resetClozeSerialNo(this.paperJson);
+    },
+    resetClozeSerialNo(paperData) {
+      const clozeQuestionTypes = ["CLOZE", "BANKED_CLOZE"];
+      paperData.paperDetails.forEach((detail) => {
+        detail.paperDetailUnits.forEach((question) => {
+          if (!clozeQuestionTypes.includes(question.questionType)) return;
+          question.question.quesBody.sections.forEach((section) => {
+            section.blocks.forEach((block) => {
+              if (block.type !== "cloze") return;
+              block.value =
+                question.question.subQuestions[block.value - 1].questionSeq;
+            });
+          });
+        });
+      });
+    },
     registWindowSubmit() {
       window.submitPaperTemp = async ({
         success,