123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <template>
- <div class="paper-template-build">
- <div class="paper-template-build-body">
- <answer-template-view
- ref="AnswerTemplateView"
- id="answer-template-view"
- class="preview-body"
- :answerData="paperJson"
- :pageCountMode="pageCountMode"
- ></answer-template-view>
- </div>
- </div>
- </template>
- <script>
- import AnswerTemplateView from "../components/AnswerTemplateView.vue";
- import { paperDetailInfoApi } from "../../paper/api";
- import { buildPdf } from "@/plugins/htmlToPdf";
- export default {
- name: "AnswerTemplateBuild",
- components: { AnswerTemplateView },
- data() {
- return {
- paperId: this.$route.params.paperId,
- viewType: this.$route.params.viewType,
- seqMode: "MODE3",
- paperJson: {},
- maxColumnWidth: 200,
- maxColumnHeight: 200,
- curPaperTemp: {},
- downloading: false,
- fieldData: {},
- paperStructs: [],
- configSources: [],
- prepareDownloadPdf: false,
- pageCountMode: "SIMPLE",
- };
- },
- mounted() {
- if (this.viewType === "frame") {
- this.initFrame();
- return;
- }
- },
- methods: {
- async initFrame() {
- try {
- const answerSet = window.parent.answerSet;
- if (!answerSet) {
- this.emitFrameResult(false, "数据缺失");
- return;
- }
- this.seqMode = answerSet.seqMode;
- this.pageCountMode = answerSet.pageCountMode;
- await this.getPaperJson();
- } catch (error) {
- this.emitFrameResult(false, "数据错误");
- }
- this.$nextTick(async () => {
- const answerBlob = await buildPdf(
- {
- elements: document
- .getElementById("answer-template-view")
- .querySelectorAll(".page-answer-flat"),
- pageSize: "A4",
- },
- true
- ).catch((error) => {
- console.error(error);
- });
- if (!answerBlob) {
- this.emitFrameResult(false, "生成答案pdf错误");
- return;
- }
- this.emitFrameResult(true, "", answerBlob);
- });
- },
- emitFrameResult(success = true, errorMsg = "", blobCont = null) {
- // console.log("htmlC", htmlCont);
- window.parent &&
- window.parent.submitPaperTemp &&
- window.parent.submitPaperTemp({
- success,
- errorMsg,
- blobCont,
- contType: "answer",
- });
- },
- async getPaperJson() {
- const res = await paperDetailInfoApi({
- paperId: this.paperId,
- seqMode: this.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;
- });
- });
- });
- });
- },
- },
- };
- </script>
- <style>
- .paper-template-build {
- text-align: center;
- }
- .paper-template-build-body {
- display: inline-block;
- text-align: initial;
- }
- .paper-template-build .page-box {
- margin-top: 10px;
- margin-bottom: 10px;
- }
- .paper-template-build .paper-build-config {
- padding: 10px 15px 2px;
- margin-top: 5px;
- background: #fff;
- border-radius: 10px;
- }
- .paper-build-config .el-form-item {
- margin-bottom: 16px;
- margin-right: 30px;
- }
- .paper-template-build .element-list {
- visibility: hidden;
- position: absolute;
- width: 1200px;
- height: 600px;
- overflow: hidden;
- left: -9999px;
- top: 0;
- z-index: 1;
- }
- </style>
|