QuestionImportEdit.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. <template>
  2. <div class="question-export-edit">
  3. <el-dialog
  4. custom-class="question-export-edit-dialog"
  5. :visible.sync="modalIsShow"
  6. :close-on-click-modal="false"
  7. :close-on-press-escape="false"
  8. append-to-body
  9. fullscreen
  10. destroy-on-close
  11. :show-close="false"
  12. @opened="visibleChange"
  13. @closed="initData"
  14. >
  15. <div slot="title" class="box-justify">
  16. <div>
  17. <h2>文件上传</h2>
  18. </div>
  19. <div>
  20. <upload-button
  21. btn-content="重新上传文件"
  22. btn-icon="icon icon-import"
  23. :disabled="loading"
  24. :upload-data="uploadData"
  25. :upload-url="uploadUrl"
  26. :format="importFileTypes"
  27. @valid-error="uploadError"
  28. @upload-error="uploadError"
  29. @upload-success="uploaded"
  30. ></upload-button>
  31. <el-button
  32. size="small"
  33. type="danger"
  34. icon="icon icon-back-white"
  35. @click="cancel"
  36. >返回</el-button
  37. >
  38. </div>
  39. </div>
  40. <div class="qe-body">
  41. <div class="qe-part qe-part-edit">
  42. <div class="qe-part-main">
  43. <div class="qe-part-head">
  44. <h3>题目编辑</h3>
  45. <div>
  46. <i class="icon icon-tips"></i>
  47. 提示:若识别有误,可点击左侧题目按格式进行修改后重新识别
  48. </div>
  49. </div>
  50. <div class="qe-part-body">
  51. <v-editor
  52. ref="RichTextEditor"
  53. v-model="paperRichJson"
  54. :enable-formula="false"
  55. :enable-audio="false"
  56. custom-emit-input
  57. :custom-render-action="renderRichText"
  58. :custom-tojson-action="richTextToJSON"
  59. ></v-editor>
  60. </div>
  61. </div>
  62. </div>
  63. <div class="qe-part qe-part-view">
  64. <div class="qe-part-main">
  65. <div class="qe-part-head">
  66. <h3>题目阅览</h3>
  67. <div>
  68. <el-button
  69. size="small"
  70. type="primary"
  71. plain
  72. icon="icon icon-export-answer"
  73. @click="toImportAnswer"
  74. >导入答案属性</el-button
  75. >
  76. <el-button
  77. size="small"
  78. type="primary"
  79. icon="icon icon-save-white"
  80. :loading="loading"
  81. @click="confirm"
  82. >识别无误,加入题库</el-button
  83. >
  84. </div>
  85. </div>
  86. <div id="qe-part-paper" class="qe-part-body">
  87. <question-import-paper-edit
  88. v-if="paperData.length"
  89. ref="QuestionImportPaperEdit"
  90. :key="questionKey"
  91. :paper="paperData"
  92. :course-id="data.importData.courseId"
  93. ></question-import-paper-edit>
  94. </div>
  95. </div>
  96. </div>
  97. <div class="qe-middle">
  98. <div class="qe-middle-arrow"></div>
  99. <el-button
  100. size="small"
  101. type="primary"
  102. :loading="loading"
  103. @click="toParse"
  104. >识别</el-button
  105. >
  106. </div>
  107. </div>
  108. </el-dialog>
  109. <!-- 上传答案文件 -->
  110. <import-file-dialog
  111. ref="ImportAnswerDialog"
  112. dialog-title="导入答案"
  113. :template-download-handle="answerTemplateDownload"
  114. :upload-url="uploadAnswerUrl"
  115. :upload-data="uploadAnswerData"
  116. add-file-param="dataFile"
  117. @uploaded="answerUploaded"
  118. ></import-file-dialog>
  119. </div>
  120. </template>
  121. <script>
  122. import paperRichTextJson from "../datas/paperRichText.json";
  123. import paperParseData from "../datas/paperParseData.json";
  124. import { calcSum, deepCopy, objTypeOf, randomCode } from "@/plugins/utils";
  125. import QuestionImportPaperEdit from "./QuestionImportPaperEdit.vue";
  126. import UploadButton from "@/components/UploadButton.vue";
  127. import { isAnEmptyRichText } from "@/utils/utils";
  128. import {
  129. questionImportPaperSave,
  130. questionImportParseRichText,
  131. questionImportDownloadTemplate,
  132. } from "../api";
  133. import ImportFileDialog from "@/components/ImportFileDialog.vue";
  134. import { QUESTION_API } from "@/constants/constants";
  135. import { propertyNameQueryApi } from "@/modules/question/api";
  136. import { downloadByApi } from "@/plugins/download";
  137. import { richTextToJSON, renderRichText } from "./import-edit/richText";
  138. const questionInfoField = [
  139. "courseId",
  140. "difficulty",
  141. "quesProperties",
  142. "score",
  143. "publicity",
  144. "control",
  145. "answerAnalysis",
  146. "quesAnswer",
  147. ];
  148. export default {
  149. name: "QuestionExportEdit",
  150. components: { QuestionImportPaperEdit, ImportFileDialog, UploadButton },
  151. props: {
  152. data: {
  153. type: Object,
  154. default() {
  155. return {
  156. richText: { sections: [] },
  157. detailInfo: [],
  158. importData: {
  159. courseId: "",
  160. courseName: "",
  161. name: "",
  162. checkTotalScore: false,
  163. useOriginalPaper: false,
  164. totalScore: 0,
  165. },
  166. };
  167. },
  168. },
  169. },
  170. data() {
  171. return {
  172. modalIsShow: false,
  173. loading: false,
  174. questionKey: "",
  175. paperData: [],
  176. paperRichJson: { sections: [] },
  177. richTextToJSON,
  178. renderRichText,
  179. // upload answer
  180. uploadAnswerUrl: `${QUESTION_API}/word/parse/import`,
  181. uploadAnswerData: {},
  182. // word upload
  183. uploadData: {},
  184. importFileTypes: ["docx", "doc"],
  185. uploadUrl: `${QUESTION_API}/word/parse/struct`,
  186. };
  187. },
  188. methods: {
  189. async visibleChange() {
  190. await this.getCourseProperty();
  191. this.paperData = deepCopy(paperParseData);
  192. this.paperRichJson = this.transformRichText(paperRichTextJson);
  193. this.uploadData = { courseId: this.data.importData.courseId };
  194. // this.paperRichJson = deepCopy(this.data.richText);
  195. // this.paperData = deepCopy(this.data.detailInfo);
  196. this.transformDataInfo();
  197. this.questionKey = randomCode();
  198. this.$nextTick(() => {
  199. this.registSrollEvent();
  200. });
  201. },
  202. transformRichText(richText) {
  203. let nsections = [];
  204. richText.sections.forEach((section) => {
  205. nsections.push({
  206. blocks: section.blocks,
  207. attributes: { id: `section-${section.remark.index}` },
  208. });
  209. if (section.remark && !section.remark.status) {
  210. nsections.push({
  211. blocks: [
  212. {
  213. type: "text",
  214. value: section.remark.cause,
  215. },
  216. ],
  217. attributes: {
  218. id: `section-error-${section.remark.index}`,
  219. class: "section-error",
  220. },
  221. });
  222. }
  223. });
  224. return { sections: nsections };
  225. },
  226. async getCourseProperty() {
  227. const res = await propertyNameQueryApi(this.data.importData.courseId, "");
  228. const optionList = res.data || [];
  229. window.sessionStorage.setItem(
  230. "coursePropertys",
  231. JSON.stringify({ optionList, courseId: this.data.importData.courseId })
  232. );
  233. },
  234. transformDataInfo() {
  235. this.transformRichImg(this.paperRichJson);
  236. this.paperData.forEach((detail) => {
  237. detail.questions.forEach((question) => {
  238. this.transformQuestion(question);
  239. if (question.subQuestions && question.subQuestions.length) {
  240. question.subQuestions.forEach((subq) => {
  241. this.transformQuestion(subq);
  242. });
  243. }
  244. });
  245. });
  246. },
  247. transformQuestion(question) {
  248. this.transformRichImg(question.body);
  249. this.transformRichImg(question.answerRichTexts);
  250. if (question.options && question.options.length) {
  251. question.options.forEach((item) => {
  252. this.transformRichImg(item.body);
  253. });
  254. }
  255. question.quesAnswer = this.transformQuestionAnser(question.quesAnswer);
  256. },
  257. transformRichImg(richText) {
  258. if (isAnEmptyRichText(richText)) return;
  259. const rate = 96 / 300;
  260. richText.sections.forEach((section) => {
  261. section.blocks.forEach((block) => {
  262. if (block.type !== "image" || !block.param) return;
  263. block.param.width = block.param.width * rate;
  264. block.param.height = block.param.height * rate;
  265. });
  266. });
  267. },
  268. transformQuestionAnser(quesAnswer) {
  269. let qAnswer = null;
  270. try {
  271. qAnswer = quesAnswer ? JSON.parse(quesAnswer) : null;
  272. } catch (error) {
  273. console.log(error);
  274. }
  275. if (!qAnswer || objTypeOf(qAnswer) !== "array") return quesAnswer;
  276. qAnswer.forEach((item) => {
  277. this.transformRichImg(item);
  278. });
  279. return JSON.stringify(qAnswer);
  280. },
  281. initData() {
  282. this.paperData = [];
  283. this.paperRichJson = { sections: [] };
  284. window.sessionStorage.removeItem("coursePropertys");
  285. this.$message.closeAll();
  286. this.removeSrollEvent();
  287. },
  288. cancel() {
  289. this.modalIsShow = false;
  290. },
  291. open() {
  292. this.modalIsShow = true;
  293. },
  294. async toParse() {
  295. if (isAnEmptyRichText(this.paperRichJson)) {
  296. this.$message.error("请输入试卷内容!");
  297. return;
  298. }
  299. if (this.loading) return;
  300. this.loading = true;
  301. let richText = this.$refs.RichTextEditor.emitJsonAction();
  302. richText.sections = richText.sections.filter(
  303. (item) =>
  304. !item.attributes || item.attributes["class"] !== "remark-error"
  305. );
  306. const res = await questionImportParseRichText({
  307. richText,
  308. courseId: this.data.importData.courseId,
  309. }).catch(() => {});
  310. this.loading = false;
  311. if (!res) return;
  312. const cacheData = this.getCachePaperInfo(
  313. this.getImportPaperData(),
  314. questionInfoField
  315. );
  316. // console.log(cacheData);
  317. this.paperData = this.assignCachePaperData(res.data, cacheData);
  318. this.questionKey = randomCode();
  319. },
  320. getCachePaperInfo(paperData, cacheFields = []) {
  321. let cachePaperInfo = {};
  322. paperData.forEach((detail, dIndex) => {
  323. detail.questionInfo.forEach((question, qIndex) => {
  324. let info = {};
  325. let k = `${dIndex + 1}_${qIndex + 1}`;
  326. if (cacheFields.length) {
  327. cacheFields.forEach((field) => {
  328. info[field] = question[field];
  329. });
  330. } else {
  331. info = { ...question };
  332. }
  333. cachePaperInfo[k] = info;
  334. if (question.subQuestions && question.subQuestions.length) {
  335. question.subQuestions.forEach((subq, subqIndex) => {
  336. let info = {};
  337. let k = `${dIndex + 1}_${qIndex + 1}_${subqIndex + 1}`;
  338. if (cacheFields.length) {
  339. cacheFields.forEach((field) => {
  340. info[field] = subq[field];
  341. });
  342. } else {
  343. info = { ...subq };
  344. }
  345. cachePaperInfo[k] = info;
  346. });
  347. }
  348. });
  349. });
  350. // console.log(cachePaperInfo);
  351. return cachePaperInfo;
  352. },
  353. assignCachePaperData(paperData, cacheData, mergeReverse = false) {
  354. return paperData.map((detail, dIndex) => {
  355. detail.questions = detail.questions.map((question, qIndex) => {
  356. let k = `${dIndex + 1}_${qIndex + 1}`;
  357. let nq = this.mergeObjData(
  358. question,
  359. cacheData[k] || {},
  360. mergeReverse
  361. );
  362. if (question.subQuestions && question.subQuestions.length) {
  363. nq.subQuestions = question.subQuestions.map((subq, subqIndex) => {
  364. let k = `${dIndex + 1}_${qIndex + 1}_${subqIndex + 1}`;
  365. return this.mergeObjData(subq, cacheData[k] || {}, mergeReverse);
  366. });
  367. }
  368. return nq;
  369. });
  370. return detail;
  371. });
  372. },
  373. isNull(val) {
  374. if (val) {
  375. if (val === "[]") return true;
  376. if (objTypeOf(val) === "array" && !val.length) return true;
  377. }
  378. return val === null || val === "" || val === undefined;
  379. },
  380. mergeObjData(targetObj, cacheObj, mergeReverse) {
  381. let data = { ...targetObj };
  382. Object.keys(cacheObj).forEach((k) => {
  383. if (mergeReverse) {
  384. data[k] = this.isNull(cacheObj[k]) ? targetObj[k] : cacheObj[k];
  385. } else {
  386. data[k] = this.isNull(targetObj[k]) ? cacheObj[k] : targetObj[k];
  387. }
  388. });
  389. return data;
  390. },
  391. getImportPaperData() {
  392. if (!this.$refs.QuestionImportPaperEdit) return [];
  393. let paperData = deepCopy(this.$refs.QuestionImportPaperEdit.getData());
  394. const transformFieldMap = { body: "quesBody", options: "quesOptions" };
  395. const fields = Object.keys(transformFieldMap);
  396. const course = {
  397. id: this.data.importData.courseId,
  398. name: this.data.importData.courseName,
  399. };
  400. const transformQuestion = (question) => {
  401. question.id = null;
  402. question.course = course;
  403. fields.forEach((field) => {
  404. question[transformFieldMap[field]] = question[field];
  405. delete question[field];
  406. });
  407. if (question.quesOptions && question.quesOptions.length) {
  408. question.quesOptions = question.quesOptions.map((option) => {
  409. option.optionBody = option.body;
  410. delete option.body;
  411. return option;
  412. });
  413. }
  414. return question;
  415. };
  416. const detailInfo = paperData.map((detail) => {
  417. const questionInfo = detail.questions.map((question) => {
  418. transformQuestion(question);
  419. if (question.subQuestions && question.subQuestions.length) {
  420. question.subQuestions = question.subQuestions.map((subq) =>
  421. transformQuestion(subq)
  422. );
  423. question.score = calcSum(
  424. question.subQuestions.map((q) => q.score || 0)
  425. );
  426. }
  427. return question;
  428. });
  429. return {
  430. name: detail.name,
  431. number: detail.number,
  432. questionCount: questionInfo.length,
  433. questionInfo,
  434. questionScore: detail.questionScore,
  435. totalScore: calcSum(questionInfo.map((q) => q.score || 0)),
  436. };
  437. });
  438. // console.log(detailInfo);
  439. return detailInfo;
  440. },
  441. checkImportPaperData(paperData) {
  442. this.$message.closeAll();
  443. // 题目内容校验
  444. const MATCHING_QUESTION = ["PARAGRAPH_MATCHING", "BANKED_CLOZE"];
  445. const SELECT_QUESTION = [
  446. "SINGLE_ANSWER_QUESTION",
  447. "MULTIPLE_ANSWER_QUESTION",
  448. ...MATCHING_QUESTION,
  449. ];
  450. const NESTED_QUESTION = [
  451. ...MATCHING_QUESTION,
  452. "READING_COMPREHENSION",
  453. "CLOZE",
  454. "LISTENING_QUESTION",
  455. ];
  456. const ALLOW_EMPTY_BODY_QUESTION = [
  457. "LISTENING_QUESTION",
  458. ...MATCHING_QUESTION,
  459. ];
  460. let errInfos = [];
  461. paperData.forEach((detail) => {
  462. detail.questionInfo.forEach((question) => {
  463. const { questionType, quesBody } = question;
  464. const questionTitle = `第${detail.number}大题第${question.number}小题`;
  465. let qErrInfo = [];
  466. // 题干
  467. if (
  468. !ALLOW_EMPTY_BODY_QUESTION.includes(questionType) &&
  469. (!quesBody || isAnEmptyRichText(quesBody))
  470. ) {
  471. qErrInfo.push(`没有题干`);
  472. }
  473. // 选项
  474. if (SELECT_QUESTION.includes(questionType)) {
  475. if (!question.quesOptions.length) {
  476. qErrInfo.push(`没有选项`);
  477. }
  478. if (
  479. question.quesOptions.some((option) =>
  480. isAnEmptyRichText(option.optionBody)
  481. )
  482. ) {
  483. qErrInfo.push(`有选择内容为空`);
  484. }
  485. }
  486. // 小题数
  487. if (
  488. NESTED_QUESTION.includes(questionType) &&
  489. !question.subQuestions.length
  490. ) {
  491. qErrInfo.push(`没有小题`);
  492. }
  493. if (qErrInfo.length) {
  494. errInfos.push(`${questionTitle}${qErrInfo.join("、")}`);
  495. qErrInfo = [];
  496. }
  497. // 选词填空、段落匹配,单用模式时校验输入答案是否重复
  498. if (
  499. MATCHING_QUESTION.includes(questionType) &&
  500. question.quesParam.matchingMode === 1
  501. ) {
  502. let selectedAnswer = [],
  503. errorQuestionIndexs = [];
  504. question.subQuestions.forEach((subq, sindex) => {
  505. if (selectedAnswer.includes(subq.quesAnswer)) {
  506. errorQuestionIndexs.push(`${question.number}-${sindex + 1}`);
  507. } else {
  508. if (subq.quesAnswer !== "[]")
  509. selectedAnswer.push(subq.quesAnswer);
  510. }
  511. });
  512. if (errorQuestionIndexs.length) {
  513. errInfos.push(
  514. `第${
  515. detail.number
  516. }大题${errorQuestionIndexs.join()}小题答案重复!`
  517. );
  518. }
  519. }
  520. if (!NESTED_QUESTION.includes(questionType)) return;
  521. // 套题小题校验
  522. question.subQuestions.forEach((subq, sindex) => {
  523. const subqTitle = `第${detail.number}大题第${question.number}-${
  524. sindex + 1
  525. }小题`;
  526. if (
  527. questionType === "READING_COMPREHENSION" &&
  528. (!subq.quesBody || isAnEmptyRichText(subq.quesBody))
  529. ) {
  530. qErrInfo.push(`没有题干`);
  531. }
  532. if (
  533. SELECT_QUESTION.includes(subq.subqType) &&
  534. !MATCHING_QUESTION.includes(questionType)
  535. ) {
  536. if (!subq.quesOptions.length) {
  537. qErrInfo.push(`没有选项`);
  538. }
  539. if (
  540. subq.quesOptions.some((option) =>
  541. isAnEmptyRichText(option.optionBody)
  542. )
  543. ) {
  544. qErrInfo.push(`有选择内容为空`);
  545. }
  546. }
  547. if (qErrInfo.length) {
  548. errInfos.push(`${subqTitle}${qErrInfo.join("、")}`);
  549. qErrInfo = [];
  550. }
  551. });
  552. });
  553. });
  554. if (errInfos.length) {
  555. this.$message({
  556. showClose: true,
  557. message: errInfos.join("。"),
  558. type: "error",
  559. duration: 0,
  560. });
  561. return;
  562. }
  563. if (!this.data.importData.useOriginalPaper) return true;
  564. let detailNumbers = paperData.map((detail) => detail.number);
  565. // 大题号重复性校验
  566. let repeatDetaiNumbers = [];
  567. let detailNums = [];
  568. for (let i = 0; i < detailNumbers.length; i++) {
  569. const num = detailNumbers[i];
  570. if (detailNums.includes(num)) {
  571. if (!repeatDetaiNumbers.includes(num)) repeatDetaiNumbers.push(num);
  572. } else {
  573. detailNums.push(num);
  574. }
  575. }
  576. if (repeatDetaiNumbers.length) {
  577. this.$message({
  578. showClose: true,
  579. message: `大题号${repeatDetaiNumbers.join("、")}重复`,
  580. type: "error",
  581. duration: 0,
  582. });
  583. return;
  584. }
  585. // 大题号连续性校验
  586. for (let i = 0; i < detailNumbers.length; i++) {
  587. if (detailNumbers[i] - 1 !== i) {
  588. this.$message({
  589. showClose: true,
  590. message: "大题号不连续",
  591. type: "error",
  592. duration: 0,
  593. });
  594. return;
  595. }
  596. }
  597. // 答案、分数校验
  598. let totalScore = calcSum(paperData.map((d) => d.totalScore));
  599. let errQuestions = [];
  600. paperData.forEach((detail) => {
  601. detail.questionInfo.forEach((question) => {
  602. if (question.subQuestions && question.subQuestions.length) {
  603. let subIndexs = [];
  604. question.subQuestions.forEach((subq, sind) => {
  605. if (!subq.score)
  606. subIndexs.push(question.number + "-" + (sind + 1));
  607. });
  608. if (subIndexs.length)
  609. errQuestions.push(
  610. `第${detail.number}大题第${subIndexs.join()}小题`
  611. );
  612. } else {
  613. if (!question.score) {
  614. errQuestions.push(
  615. `第${detail.number}大题第${question.number}小题`
  616. );
  617. }
  618. }
  619. });
  620. });
  621. if (errQuestions.length) {
  622. this.$message({
  623. showClose: true,
  624. message: `请设置如下试题的分值:${errQuestions.join("、")}。`,
  625. type: "error",
  626. duration: 0,
  627. });
  628. return;
  629. }
  630. if (
  631. this.data.importData.checkTotalScore &&
  632. totalScore !== this.data.importData.totalScore
  633. ) {
  634. this.$message({
  635. showClose: true,
  636. message: `试卷总分与导入设置的总分不一致!`,
  637. type: "error",
  638. duration: 0,
  639. });
  640. return;
  641. }
  642. return true;
  643. },
  644. async confirm() {
  645. const confirm = await this.$confirm("确认加入题库吗?", "提示", {
  646. type: "warning",
  647. }).catch(() => {});
  648. if (confirm !== "confirm") return;
  649. const detailInfo = this.getImportPaperData();
  650. if (!this.checkImportPaperData(detailInfo)) return;
  651. if (this.loading) return;
  652. this.loading = true;
  653. const res = await questionImportPaperSave({
  654. ...this.data.importData,
  655. detailInfo,
  656. }).catch(() => {});
  657. this.loading = false;
  658. if (!res) return;
  659. this.$message.success("提交成功!");
  660. this.$emit("modified");
  661. this.cancel();
  662. },
  663. // 导入答案属性
  664. toImportAnswer() {
  665. const detailInfo = this.getImportPaperData();
  666. this.uploadAnswerData = {
  667. detailInfo: JSON.stringify(detailInfo),
  668. ...this.data.importData,
  669. };
  670. this.$refs.ImportAnswerDialog.open();
  671. },
  672. async answerTemplateDownload() {
  673. const detailInfo = this.getImportPaperData();
  674. const res = await downloadByApi(() => {
  675. return questionImportDownloadTemplate({
  676. detailInfo,
  677. ...this.data.importData,
  678. });
  679. }).catch((e) => {
  680. this.$message.error(e || "下载失败,请重新尝试!");
  681. });
  682. if (!res) return;
  683. this.$message.success("下载成功!");
  684. },
  685. answerUploaded(res) {
  686. const cacheData = this.getCachePaperInfo(
  687. res.data.detailInfo,
  688. questionInfoField
  689. );
  690. this.paperData = this.assignCachePaperData(
  691. this.paperData,
  692. cacheData,
  693. true
  694. );
  695. this.questionKey = randomCode();
  696. },
  697. // word upload
  698. uploaded(res) {
  699. this.$message.success("上传成功!");
  700. this.paperRichJson = deepCopy(res.data.richText);
  701. this.paperData = deepCopy(res.data.detailInfo);
  702. this.transformDataInfo();
  703. this.questionKey = randomCode();
  704. },
  705. uploadError(error) {
  706. this.$message.error(error.message);
  707. },
  708. // scroll
  709. registSrollEvent() {
  710. document
  711. .getElementById("qe-part-paper")
  712. .addEventListener("scroll", this.scrollEvent);
  713. },
  714. removeSrollEvent() {
  715. document
  716. .getElementById("qe-part-paper")
  717. .removeEventListener("scroll", this.scrollEvent);
  718. },
  719. scrollEvent(e) {
  720. // e.preventDefault();
  721. // e.stopPropagation();
  722. const questionContIndexList =
  723. this.$refs.QuestionImportPaperEdit.questionContIndexList;
  724. const scrollTop = e.target.scrollTop;
  725. // console.log(questionContIndexList, scrollTop);
  726. const targeContIndex = questionContIndexList.findIndex(
  727. (item) => scrollTop < item[3]
  728. );
  729. const targeCont =
  730. targeContIndex !== -1
  731. ? questionContIndexList[targeContIndex - 1]
  732. : questionContIndexList.slice(-1)[0];
  733. const richTextSectionDom = document.getElementById(
  734. `section-${targeCont[2]}`
  735. );
  736. const elPos = this.$refs.RichTextEditor.$el
  737. .querySelector(".v-editor-main")
  738. .getBoundingClientRect();
  739. const textPos = richTextSectionDom.getBoundingClientRect();
  740. let textScrollTop = textPos.y - elPos.y;
  741. textScrollTop = Math.max(textScrollTop, 0);
  742. this.$refs.RichTextEditor.$el.querySelector(
  743. ".v-editor-container"
  744. ).scrollTop = textScrollTop;
  745. },
  746. },
  747. };
  748. </script>