zhangjie 2 年 前
コミット
04ff87fb18
1 ファイル変更33 行追加30 行削除
  1. 33 30
      src/modules/question/components/QuestionImportEdit.vue

+ 33 - 30
src/modules/question/components/QuestionImportEdit.vue

@@ -224,9 +224,9 @@ export default {
       // });
       this.resetData(this.data);
 
-      // this.$nextTick(() => {
-      //   this.registScrollEvent();
-      // });
+      this.$nextTick(() => {
+        this.registScrollEvent();
+      });
     },
     resetData({ richText, detailInfo }) {
       this.paperData = deepCopy(detailInfo);
@@ -394,6 +394,14 @@ export default {
     open() {
       this.modalIsShow = true;
     },
+    getRichTextJsons() {
+      let sections = [];
+      this.$refs.RichTextEditor.forEach((item) => {
+        const itemRichJson = item.emitJsonAction();
+        sections.push(...itemRichJson.sections);
+      });
+      return { sections };
+    },
     async toParse() {
       if (isAnEmptyRichText(this.paperRichJson)) {
         this.$message.error("请输入试卷内容!");
@@ -403,12 +411,7 @@ export default {
       if (this.loading) return;
       this.loading = true;
 
-      let richText = this.$refs.RichTextEditor.emitJsonAction();
-      richText.sections = richText.sections.filter(
-        (item) =>
-          !item.attributes || item.attributes["class"] !== "section-error"
-      );
-
+      let richText = this.getRichTextJsons();
       const res = await questionImportParseRichText({
         richText,
         courseId: this.data.importData.courseId,
@@ -853,17 +856,17 @@ export default {
       document
         .getElementById("qe-part-paper")
         .addEventListener("scroll", this.paperScrollEvent);
-      this.$refs.RichTextEditor.$el
-        .querySelector(".v-editor-container")
-        .addEventListener("scroll", this.richTextScrollEvent);
+      document
+        .getElementById("qe-part-richtext-list")
+        .parentNode.addEventListener("scroll", this.richTextScrollEvent);
     },
     removeScrollEvent() {
       document
         .getElementById("qe-part-paper")
         .removeEventListener("scroll", this.paperScrollEvent);
-      this.$refs.RichTextEditor.$el
-        .querySelector(".v-editor-container")
-        .removeEventListener("scroll", this.richTextScrollEvent);
+      document
+        .getElementById("qe-part-richtext-list")
+        .parentNode.removeEventListener("scroll", this.richTextScrollEvent);
     },
     paperScrollEvent(e) {
       // e.preventDefault();
@@ -906,20 +909,21 @@ export default {
       );
       if (!richTextSectionDom) return;
 
-      const richTextContainerDom = this.$refs.RichTextEditor.$el.querySelector(
-        ".v-editor-container"
-      );
-      const richTextMainDom =
-        this.$refs.RichTextEditor.$el.querySelector(".v-editor-main");
-      const sectionOffsetTop = richTextSectionDom.offsetTop;
-      let nextSectionOffsetTop = richTextMainDom.offsetHeight;
+      const richTextListDom = document.getElementById("qe-part-richtext-list");
+      const elPos = richTextListDom.getBoundingClientRect();
+      const richTextContainerDom = richTextListDom.parentNode;
+
+      const sectionOffsetTop =
+        richTextSectionDom.getBoundingClientRect().y - elPos.y;
+      let nextSectionOffsetTop = richTextListDom.offsetHeight;
 
       if (nextTargetCont) {
         const nextRichTextSectionDom = document.getElementById(
           `section-${nextTargetCont[2][0]}`
         );
         if (nextRichTextSectionDom) {
-          nextSectionOffsetTop = nextRichTextSectionDom.offsetTop;
+          nextSectionOffsetTop =
+            nextRichTextSectionDom.getBoundingClientRect().y - elPos.y;
         } else {
           nextSectionOffsetTop =
             richTextSectionDom.offsetTop + richTextSectionDom.offsetHeight;
@@ -942,10 +946,9 @@ export default {
     },
     richTextScrollEvent(e) {
       if (this.scrollType === "paper") {
-        this.lastRichTextScrollTop =
-          this.$refs.RichTextEditor.$el.querySelector(
-            ".v-editor-container"
-          ).scrollTop;
+        this.lastRichTextScrollTop = document.getElementById(
+          "qe-part-richtext-list"
+        ).parentNode.scrollTop;
         return;
       }
       this.scrollType = "rich-text";
@@ -959,8 +962,8 @@ export default {
       const offsetH = isScrollDown ? 150 : 0;
       const scrollTop = e.target.scrollTop + offsetH;
 
-      const richTextMainDom =
-        this.$refs.RichTextEditor.$el.querySelector(".v-editor-main");
+      const richTextListDom = document.getElementById("qe-part-richtext-list");
+
       const questionContIndexList =
         this.$refs.QuestionImportPaperEdit.questionContIndexList;
 
@@ -997,7 +1000,7 @@ export default {
           (scrollTop - targeCont[1]) / (nextTargetCont[1] - targeCont[1]);
       } else {
         targeCont = this.richTextIndexList.slice(-1)[0];
-        const textHeight = richTextMainDom.offsetHeight;
+        const textHeight = richTextListDom.offsetHeight;
         targeContPercent =
           (scrollTop - targeCont[1]) / (textHeight - targeCont[1]);
       }