Răsfoiți Sursa

bugfix,答题点逻辑调整

zhangjie 2 ani în urmă
părinte
comite
6d4b30fef5

+ 3 - 5
src/components/vEditor/VEditor.vue

@@ -25,7 +25,7 @@ import {
   MAX_JSON_SIZE,
 } from "./constants";
 import { pasteHandle } from "./clipboard";
-import { answerPointDragHandle } from "./components/answerPoint";
+import { answerPointRebuild } from "./components/answerPoint";
 import timeMixin from "@/mixins/timeMixin";
 
 export default {
@@ -81,10 +81,6 @@ export default {
   mounted() {
     this.initData();
     this.$refs.editor.addEventListener("paste", pasteHandle.bind(this));
-    this.$refs.editor.addEventListener(
-      "input",
-      answerPointDragHandle.bind(this)
-    );
     this.$refs.editor.addEventListener("wheel", this.wheelEventHandle);
   },
   beforeDestroy() {
@@ -105,6 +101,8 @@ export default {
         return;
       }
 
+      if (this.enableAnswerPoint) answerPointRebuild.bind(this)();
+
       if (this.emitType === "html") {
         const content = this.$refs.editor.innerHTML;
         this.$emit("input", content);

+ 1 - 38
src/components/vEditor/components/answerPoint.js

@@ -19,57 +19,20 @@ export async function answerPointHandle() {
   node.dataset.order = 0;
 
   document.execCommand("insertHTML", false, node.outerHTML);
-
-  const answerPoints = this.$refs.editor.querySelectorAll(
-    "[data-is-answer-point]"
-  );
-  // console.log(answerPoints);
-  const answerPointsChanged = [];
-  [...answerPoints].forEach((answerPoint, index) => {
-    answerPointsChanged.push(+answerPoint.dataset.order); // 发现是0时,在answer里面增加一个元素
-    answerPoint.dataset.order = index + 1;
-    answerPoint.src = getAnswerPointImg(index + 1);
-  });
-  // console.log({ answerPointsChanged });
-  this.$emit("emitJSON");
-  this.$emit("answer-point-changed", answerPointsChanged);
 }
 
 /**
  * 答题点拖动后更新,通过判断是否有 [data-is-answer-point-x] 来判断是否是拖动
  * 因为drag会触发两次input,第一次事件是删除,要忽略第一次事件
  *
- * @param {InputEvent} event
  * @this {Object} VEditor 因为VEditor会带很多选项,所以绑定this传过来
  */
-export async function answerPointDragHandle(event) {
-  // console.log(event);
-  if (!["insertFromDrop", "deleteContentBackward"].includes(event.inputType)) {
-    // 只监听drop事件,因为会造成删除
-    return;
-  }
-  const answerPointX = this.$refs.editor.querySelectorAll(
-    "[data-is-answer-point-x]"
-  );
-  // console.log(answerPointX);
+export async function answerPointRebuild() {
   const answerPoints = this.$refs.editor.querySelectorAll(
     "[data-is-answer-point]"
   );
-  // console.log(answerPoints);
-  // 没有答题点也会进入这里
-  if (answerPoints.length === 0 || answerPointX.length > 0) {
-    this.$emit("emitJSON");
-    this.$emit("answer-point-changed", []);
-    return;
-  }
-  // console.log("is drag", answerPoints);
-  const answerPointsChanged = [];
   [...answerPoints].forEach((answerPoint, index) => {
-    answerPointsChanged.push(+answerPoint.dataset.order); // 发现是0时,在answer里面增加一个元素
     answerPoint.dataset.order = index + 1;
     answerPoint.src = getAnswerPointImg(index + 1);
   });
-  // console.log({ answerPointsChanged });
-  this.$emit("emitJSON");
-  this.$emit("answer-point-changed", answerPointsChanged);
 }

+ 1 - 1
src/modules/card/components/CardDesign.vue

@@ -28,8 +28,8 @@
             >
               <el-button><i class="el-icon-plus"></i>{{ item.name }}</el-button>
             </div>
-            <p class="tips-info">提示:拖动插入元素</p>
           </div>
+          <p class="tips-info">提示:拖动插入元素</p>
         </div>
       </div>
     </div>

+ 8 - 2
src/modules/questions/views/EditOtherQuestion.vue

@@ -351,7 +351,11 @@ export default {
   },
   computed: {
     saveDisabled() {
-      if (!this.questionId && this.quesModel.quesOptions.length == 0) {
+      if (
+        !this.questionId &&
+        this.quesModel.quesOptions &&
+        this.quesModel.quesOptions.length == 0
+      ) {
         return true;
       }
       return false;
@@ -432,7 +436,9 @@ export default {
 
       let newAnswer = [];
       for (let i = 0; i < curPonitCount; i++) {
-        newAnswer.push(this.quesAnswer[i] || { sections: [] });
+        newAnswer.push(
+          (this.quesAnswer && this.quesAnswer[i]) || { sections: [] }
+        );
       }
 
       this.resetNumberAndSaveAnswerPoints(newAnswer);

+ 3 - 1
src/modules/questions/views/EditPaper.vue

@@ -1997,7 +1997,9 @@ export default {
 
         let newAnswer = [];
         for (let i = 0; i < curPonitCount; i++) {
-          newAnswer.push(this.quesAnswer[i] || { sections: [] });
+          newAnswer.push(
+            (this.quesAnswer && this.quesAnswer[i]) || { sections: [] }
+          );
         }
 
         this.resetNumberAndSaveAnswerPoints(newAnswer);

+ 3 - 1
src/modules/questions/views/EditPaperPendingTrial.vue

@@ -2100,7 +2100,9 @@ export default {
 
         let newAnswer = [];
         for (let i = 0; i < curPonitCount; i++) {
-          newAnswer.push(this.quesAnswer[i] || { sections: [] });
+          newAnswer.push(
+            (this.quesAnswer && this.quesAnswer[i]) || { sections: [] }
+          );
         }
 
         this.resetNumberAndSaveAnswerPoints(newAnswer);