AnswerTemplateView.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <template>
  2. <div class="paper-template-view answer-template-view card-view paper-page">
  3. <div v-for="(singlePageData, index) in flatData" :key="index">
  4. <div class="page-box page-box-A4 page-box-answer">
  5. <div class="page-main-inner">
  6. <div v-for="(row, i) in singlePageData || []" :key="i">
  7. <div v-if="row.type == 'bigTitle'" class="is-detail-title">
  8. {{ row.number | numberToChaineseFilter }}、{{ row.name }}
  9. {{ row.title }}
  10. </div>
  11. <div v-else>
  12. <span>{{ row.questionSeq + ". " }}</span>
  13. <question-answer :data="row"></question-answer>
  14. </div>
  15. </div>
  16. <page-number
  17. type="text"
  18. :rule="getPageNumberCont(index + 1)"
  19. ></page-number>
  20. </div>
  21. </div>
  22. </div>
  23. <div class="page-box page-box-A4 page-box-answer origin-view">
  24. <div class="page-main-inner">
  25. <!-- {{ flatData }} -->
  26. <div v-for="(big, index) in paperDetails" :key="index">
  27. <div
  28. class="is-detail-title"
  29. v-domObserver="
  30. (top) => {
  31. getDomTop(top, index);
  32. }
  33. "
  34. >
  35. {{ big.number | numberToChaineseFilter }}、{{ big.name }}
  36. {{ big.title }}
  37. </div>
  38. <div v-for="(small, i) in big.paperDetailUnits" :key="i">
  39. <div
  40. v-if="!small.question.subQuestions"
  41. v-domObserver="
  42. (top) => {
  43. getDomTop(top, index, i);
  44. }
  45. "
  46. >
  47. <span>{{ small.question.questionSeq + ". " }}</span>
  48. <question-answer :data="small.question"></question-answer>
  49. </div>
  50. <template v-if="small.question.subQuestions">
  51. <div
  52. v-for="(innerQuestion, innerIndex) in small.question
  53. .subQuestions"
  54. :key="innerIndex"
  55. v-domObserver="
  56. (top) => {
  57. getDomTop(top, index, i, innerIndex);
  58. }
  59. "
  60. >
  61. <span>{{ innerQuestion.questionSeq + ". " }}</span>
  62. <question-answer :data="innerQuestion"></question-answer>
  63. </div>
  64. </template>
  65. </div>
  66. </div>
  67. </div>
  68. </div>
  69. </div>
  70. </template>
  71. <script>
  72. import PageNumber from "./PageNumber";
  73. import QuestionAnswer from "../../question/components/QuestionAnswer.vue";
  74. import { cloneDeep } from "lodash";
  75. export default {
  76. name: "AnswerTemplateView",
  77. components: {
  78. PageNumber,
  79. QuestionAnswer,
  80. },
  81. props: {
  82. pageConfig: {
  83. type: Object,
  84. default() {
  85. return {};
  86. },
  87. },
  88. answerData: {
  89. type: Object,
  90. default() {
  91. return {};
  92. },
  93. },
  94. pageCountMode: {
  95. type: String,
  96. },
  97. },
  98. computed: {
  99. paperDetails() {
  100. return this.answerData?.paperDetails || [];
  101. },
  102. //数据扁平化,便于高度计算
  103. flatData() {
  104. let arr = [[]];
  105. const limitHeight = 976;
  106. let usedPageIndex = 0;
  107. let computedHeight = 0;
  108. let paperDetailsWithTop = cloneDeep(this.paperDetailsWithTop);
  109. for (let i = 0; i < paperDetailsWithTop.length; i++) {
  110. let cloneBig = cloneDeep(paperDetailsWithTop[i]);
  111. let { top, height } = cloneBig; //大题标题的尺寸数据
  112. if (computedHeight + top + height > limitHeight) {
  113. usedPageIndex++;
  114. arr[usedPageIndex] = [];
  115. computedHeight = top + height;
  116. } else {
  117. computedHeight += top + height;
  118. }
  119. arr[usedPageIndex].push({
  120. type: "bigTitle",
  121. name: cloneBig.name,
  122. title: cloneBig.title,
  123. number: cloneBig.number,
  124. });
  125. if (cloneBig.paperDetailUnits?.length) {
  126. for (let j = 0; j < cloneBig.paperDetailUnits.length; j++) {
  127. let unit = cloneBig.paperDetailUnits[j];
  128. let question = unit.question;
  129. let { top, height } = unit; //大题标题的尺寸数据
  130. if (!question.subQuestions) {
  131. //无套题的小题尺寸数据
  132. if (computedHeight + top + height > limitHeight) {
  133. usedPageIndex++;
  134. arr[usedPageIndex] = [];
  135. computedHeight = top + height;
  136. } else {
  137. computedHeight += top + height;
  138. }
  139. arr[usedPageIndex].push({
  140. type: "subQuestion",
  141. ...cloneDeep(question),
  142. });
  143. } else {
  144. for (let x = 0; x < question.subQuestions.length; x++) {
  145. let innerQuestion = question.subQuestions[x];
  146. let { top, height } = innerQuestion;
  147. if (computedHeight + top + height > limitHeight) {
  148. usedPageIndex++;
  149. arr[usedPageIndex] = [];
  150. computedHeight = top + height;
  151. } else {
  152. computedHeight += top + height;
  153. }
  154. arr[usedPageIndex].push({
  155. type: "innerQuestion",
  156. ...cloneDeep(innerQuestion),
  157. });
  158. }
  159. }
  160. }
  161. }
  162. }
  163. if (arr.length % 2 != 0 && this.pageCountMode === "DOUBLE") {
  164. arr.push([]);
  165. }
  166. return arr;
  167. },
  168. },
  169. data() {
  170. return {
  171. paperDetailsWithTop: [],
  172. // computedPages: [],
  173. };
  174. },
  175. watch: {
  176. answerData(val) {
  177. let arr = cloneDeep(val?.paperDetails || []);
  178. this.paperDetailsWithTop = arr.map((detail) => {
  179. detail.position = { top: 0, height: 0 };
  180. if (detail.paperDetailUnits?.length) {
  181. detail.paperDetailUnits = detail.paperDetailUnits.map((unit) => {
  182. unit.position = { top: 0, height: 0 };
  183. let question = unit.question;
  184. if (question.subQuestions?.length) {
  185. question.subQuestions = question.subQuestions.map((subQues) => {
  186. subQues.position = { top: 0, height: 0 };
  187. return subQues;
  188. });
  189. }
  190. return unit;
  191. });
  192. }
  193. return detail;
  194. });
  195. },
  196. },
  197. methods: {
  198. created() {},
  199. mounted() {},
  200. getDomTop(position, index, subIndex, innerIndex) {
  201. let arr = cloneDeep(this.paperDetailsWithTop);
  202. if (subIndex == undefined && innerIndex == undefined) {
  203. arr[index].position = {
  204. top: position.top - 40,
  205. height: position.height,
  206. };
  207. }
  208. if (subIndex) {
  209. if (innerIndex == undefined) {
  210. arr[index]["paperDetailUnits"][subIndex].position = {
  211. top: position.top - 40,
  212. height: position.height,
  213. };
  214. } else {
  215. arr[index]["paperDetailUnits"][subIndex]["question"]["subQuestions"][
  216. innerIndex
  217. ].position = {
  218. top: position.top - 40,
  219. height: position.height,
  220. };
  221. }
  222. }
  223. this.paperDetailsWithTop = arr;
  224. },
  225. getPageNumberCont(pageNo) {
  226. return `第${pageNo}页 共${this.flatData.length}页`;
  227. },
  228. },
  229. };
  230. </script>