فهرست منبع

答题点调整关联修改逻辑调整

zhangjie 2 سال پیش
والد
کامیت
06e53e0c77

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

@@ -1,6 +1,6 @@
 <template>
   <div class="v-editor">
-    <VMenu class="v-editor-head" @audio-added="emitJSON" />
+    <VMenu class="v-editor-head" />
     <div
       :id="'ved' + _uid"
       ref="editor"
@@ -96,13 +96,13 @@ export default {
         renderRichText(content, this.$refs.editor, false);
       }
     },
-    emitJSON() {
+    emitJSON($event) {
       if (!this.$refs.editor.contentEditable) {
         // 不是出于contentEditable则不更新
         return;
       }
 
-      if (this.enableAnswerPoint) answerPointRebuild.bind(this)();
+      if (this.enableAnswerPoint) answerPointRebuild.bind(this)($event);
 
       if (this.emitType === "html") {
         const content = this.$refs.editor.innerHTML;

+ 7 - 2
src/components/vEditor/components/answerPoint.js

@@ -27,13 +27,18 @@ export async function answerPointHandle() {
  *
  * @this {Object} VEditor 因为VEditor会带很多选项,所以绑定this传过来
  */
-export async function answerPointRebuild() {
+export async function answerPointRebuild($event) {
+  // console.log($event.inputType);
+  if ($event.inputType === "deleteByDrag") return;
+
   const answerPoints = this.$refs.editor.querySelectorAll(
     "[data-is-answer-point]"
   );
+  let answerPointsChanged = [];
   [...answerPoints].forEach((answerPoint, index) => {
+    answerPointsChanged.push(answerPoint.dataset.order);
     answerPoint.dataset.order = index + 1;
     answerPoint.src = getAnswerPointImg(index + 1);
   });
-  this.$emit("answer-point-changed", answerPoints.length);
+  this.$emit("answer-point-changed", answerPointsChanged);
 }

+ 13 - 13
src/modules/question/components/edit/BankedClozeQuestion.vue

@@ -216,20 +216,20 @@ export default {
         this.modalForm.subQuestions[index].newQuestion.questionKey;
       this.activeNames = this.activeNames.filter((k) => k !== delQuestionKey);
     },
-    answerPointsChange(answerPointsCount) {
-      let curSubQuestionCount = this.modalForm.subQuestions.length;
-      if (curSubQuestionCount === answerPointsCount) return;
-
-      if (curSubQuestionCount > answerPointsCount) {
-        this.modalForm.subQuestions = this.modalForm.subQuestions.slice(
-          0,
-          answerPointsCount
-        );
-      } else {
-        for (let i = curSubQuestionCount; i < answerPointsCount; i++) {
-          this.addSubQuestion();
+    answerPointsChange(answerPointsChanged) {
+      let subQuestions = [];
+      answerPointsChanged.forEach((item) => {
+        const order = Number(item);
+        if (order === 0) {
+          let newQuestion = getMatchQuestionModel();
+          newQuestion.questionKey = randomCode();
+          newQuestion.courseId = this.question.courseId;
+          subQuestions.push(newQuestion);
+        } else {
+          subQuestions.push(this.modalForm.subQuestions[order - 1]);
         }
-      }
+      });
+      this.modalForm.subQuestions = subQuestions;
     },
     quesBodyChange() {
       this.$refs.modalFormComp.validateField(`quesBody`, () => {});

+ 11 - 14
src/modules/question/components/edit/FillBlankQuestion.vue

@@ -98,23 +98,20 @@ export default {
         };
       });
     },
-    answerPointsChange(answerPointsCount) {
-      console.log(answerPointsCount);
-      let curAnswerPointsCount = this.modalForm.quesAnswer.length;
-      if (curAnswerPointsCount === answerPointsCount) return;
-
-      if (curAnswerPointsCount > answerPointsCount) {
-        this.modalForm.quesAnswer = this.modalForm.quesAnswer.slice(
-          0,
-          answerPointsCount
-        );
-      } else {
-        for (let i = curAnswerPointsCount; i < answerPointsCount; i++) {
-          this.modalForm.quesAnswer.push({
+    answerPointsChange(answerPointsChanged) {
+      console.log(answerPointsChanged);
+      let quesAnswer = [];
+      answerPointsChanged.forEach((item) => {
+        const order = Number(item);
+        if (order === 0) {
+          quesAnswer.push({
             body: null,
           });
+        } else {
+          quesAnswer.push(this.modalForm.quesAnswer[order - 1]);
         }
-      }
+      });
+      this.modalForm.quesAnswer = quesAnswer;
     },
     quesBodyChange() {
       this.$refs.modalFormComp.validateField(`quesBody`, () => {});

+ 13 - 13
src/modules/question/components/edit/NestedQuestion.vue

@@ -183,20 +183,20 @@ export default {
         this.modalForm.subQuestions[index].newQuestion.questionKey;
       this.activeNames = this.activeNames.filter((k) => k !== delQuestionKey);
     },
-    answerPointsChange(answerPointsCount) {
-      let curSubQuestionCount = this.modalForm.subQuestions.length;
-      if (curSubQuestionCount === answerPointsCount) return;
-
-      if (curSubQuestionCount > answerPointsCount) {
-        this.modalForm.subQuestions = this.modalForm.subQuestions.slice(
-          0,
-          answerPointsCount
-        );
-      } else {
-        for (let i = curSubQuestionCount; i < answerPointsCount; i++) {
-          this.addSubQuestion("SINGLE_ANSWER_QUESTION");
+    answerPointsChange(answerPointsChanged) {
+      let subQuestions = [];
+      answerPointsChanged.forEach((item) => {
+        const order = Number(item);
+        if (order === 0) {
+          let newQuestion = getInitQuestionModel("SINGLE_ANSWER_QUESTION");
+          newQuestion.questionKey = randomCode();
+          newQuestion.courseId = this.question.courseId;
+          subQuestions.push(newQuestion);
+        } else {
+          subQuestions.push(this.modalForm.subQuestions[order - 1]);
         }
-      }
+      });
+      this.modalForm.subQuestions = subQuestions;
     },
     quesBodyChange() {
       this.$refs.modalFormComp.validateField(`quesBody`, () => {});