AnswerTemplateBuild.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <div class="paper-template-build">
  3. <div class="paper-template-build-body">
  4. <answer-template-view
  5. v-if="paperJson"
  6. ref="AnswerTemplateView"
  7. id="answer-template-view"
  8. class="preview-body"
  9. :answerData="paperJson"
  10. :pageCountMode="pageCountMode"
  11. @rend-finished="rendFinished"
  12. ></answer-template-view>
  13. </div>
  14. </div>
  15. </template>
  16. <script>
  17. import AnswerTemplateView from "../components/AnswerTemplateView.vue";
  18. import { paperDetailInfoApi } from "../../paper/api";
  19. import { buildPdf } from "@/plugins/htmlToPdf";
  20. export default {
  21. name: "AnswerTemplateBuild",
  22. components: { AnswerTemplateView },
  23. data() {
  24. return {
  25. paperId: this.$route.params.paperId,
  26. viewType: this.$route.params.viewType,
  27. seqMode: "MODE3",
  28. paperJson: null,
  29. maxColumnWidth: 200,
  30. maxColumnHeight: 200,
  31. curPaperTemp: {},
  32. downloading: false,
  33. fieldData: {},
  34. paperStructs: [],
  35. configSources: [],
  36. prepareDownloadPdf: false,
  37. pageCountMode: "SIMPLE",
  38. };
  39. },
  40. mounted() {
  41. if (this.viewType === "frame") {
  42. this.initFrame();
  43. return;
  44. }
  45. },
  46. methods: {
  47. async initFrame() {
  48. try {
  49. const answerSet = window.parent.answerSet;
  50. if (!answerSet) {
  51. this.emitFrameResult(false, "数据缺失");
  52. return;
  53. }
  54. this.seqMode = answerSet.seqMode;
  55. this.pageCountMode = answerSet.pageCountMode;
  56. await this.getPaperJson();
  57. } catch (error) {
  58. this.emitFrameResult(false, "数据错误");
  59. }
  60. },
  61. async rendFinished() {
  62. const answerBlob = await buildPdf(
  63. {
  64. elements: document
  65. .getElementById("answer-template-view")
  66. .querySelectorAll(".page-answer-flat"),
  67. pageSize: "A4",
  68. },
  69. true
  70. ).catch((error) => {
  71. console.error(error);
  72. });
  73. if (!answerBlob) {
  74. this.emitFrameResult(false, "生成答案pdf错误");
  75. return;
  76. }
  77. this.emitFrameResult(true, "", answerBlob);
  78. },
  79. emitFrameResult(success = true, errorMsg = "", blobCont = null) {
  80. // console.log("htmlC", htmlCont);
  81. window.parent &&
  82. window.parent.submitPaperTemp &&
  83. window.parent.submitPaperTemp({
  84. success,
  85. errorMsg,
  86. blobCont,
  87. contType: "answer",
  88. });
  89. },
  90. async getPaperJson() {
  91. const res = await paperDetailInfoApi({
  92. paperId: this.paperId,
  93. seqMode: this.seqMode,
  94. });
  95. this.paperJson = res.data;
  96. this.resetClozeSerialNo(this.paperJson);
  97. },
  98. resetClozeSerialNo(paperData) {
  99. const clozeQuestionTypes = ["CLOZE", "BANKED_CLOZE"];
  100. paperData.paperDetails.forEach((detail) => {
  101. detail.paperDetailUnits.forEach((question) => {
  102. if (!clozeQuestionTypes.includes(question.questionType)) return;
  103. question.question.quesBody.sections.forEach((section) => {
  104. section.blocks.forEach((block) => {
  105. if (block.type !== "cloze") return;
  106. block.value =
  107. question.question.subQuestions[block.value - 1].questionSeq;
  108. });
  109. });
  110. });
  111. });
  112. },
  113. },
  114. };
  115. </script>
  116. <style>
  117. .paper-template-build {
  118. text-align: center;
  119. }
  120. .paper-template-build-body {
  121. display: inline-block;
  122. text-align: initial;
  123. }
  124. .paper-template-build .page-box {
  125. margin-top: 10px;
  126. margin-bottom: 10px;
  127. }
  128. .paper-template-build .paper-build-config {
  129. padding: 10px 15px 2px;
  130. margin-top: 5px;
  131. background: #fff;
  132. border-radius: 10px;
  133. }
  134. .paper-build-config .el-form-item {
  135. margin-bottom: 16px;
  136. margin-right: 30px;
  137. }
  138. .paper-template-build .element-list {
  139. visibility: hidden;
  140. position: absolute;
  141. width: 1200px;
  142. height: 600px;
  143. overflow: hidden;
  144. left: -9999px;
  145. top: 0;
  146. z-index: 1;
  147. }
  148. </style>