AnswerTemplateBuild.vue 3.8 KB

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