|  | @@ -19,6 +19,17 @@
 | 
	
		
			
				|  |  |            </div>
 | 
	
		
			
				|  |  |          </li>
 | 
	
		
			
				|  |  |        </ul>
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +      <div v-if="isShowRightAnswer" class="right-answer">
 | 
	
		
			
				|  |  | +        <div class="title">正确答案</div>
 | 
	
		
			
				|  |  | +        <ul ref="answerList" class="option-list">
 | 
	
		
			
				|  |  | +          <li v-for="(item, i) in data.option_list" :key="i" class="list-item">
 | 
	
		
			
				|  |  | +            <div v-for="{ content, mark } in item" :key="mark" :class="['item-wrapper', `answer-item-${mark}`]">
 | 
	
		
			
				|  |  | +              <span class="content rich-text" v-html="sanitizeHTML(content)"></span>
 | 
	
		
			
				|  |  | +            </div>
 | 
	
		
			
				|  |  | +          </li>
 | 
	
		
			
				|  |  | +        </ul>
 | 
	
		
			
				|  |  | +      </div>
 | 
	
		
			
				|  |  |      </div>
 | 
	
		
			
				|  |  |    </div>
 | 
	
		
			
				|  |  |  </template>
 | 
	
	
		
			
				|  | @@ -58,6 +69,22 @@ export default {
 | 
	
		
			
				|  |  |        },
 | 
	
		
			
				|  |  |        immediate: true,
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  | +    isJudgingRightWrong(cur) {
 | 
	
		
			
				|  |  | +      if (cur) {
 | 
	
		
			
				|  |  | +        this.clearLine();
 | 
	
		
			
				|  |  | +        this.circulateAnswerList();
 | 
	
		
			
				|  |  | +      } else {
 | 
	
		
			
				|  |  | +        this.clearLine();
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +    isShowRightAnswer(cur) {
 | 
	
		
			
				|  |  | +      if (cur) {
 | 
	
		
			
				|  |  | +        this.$nextTick(() => {
 | 
	
		
			
				|  |  | +          this.circulateAnswerList(true);
 | 
	
		
			
				|  |  | +          this.judgeRichTextIsImgAndText(true);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  |    },
 | 
	
		
			
				|  |  |    created() {
 | 
	
		
			
				|  |  |      document.addEventListener('click', this.handleEventConnection);
 | 
	
	
		
			
				|  | @@ -201,15 +228,42 @@ export default {
 | 
	
		
			
				|  |  |        this.createLine(mark);
 | 
	
		
			
				|  |  |      },
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    // 循环答案列表
 | 
	
		
			
				|  |  | +    circulateAnswerList(isShowRightAnswer = false) {
 | 
	
		
			
				|  |  | +      let answer_list = isShowRightAnswer ? this.data.answer.answer_list : this.answer.answer_list;
 | 
	
		
			
				|  |  | +      answer_list.forEach((item) => {
 | 
	
		
			
				|  |  | +        item.forEach((mark, j) => {
 | 
	
		
			
				|  |  | +          if (mark.length <= 0 || j >= item.length - 1) return;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +          let cur = { i: -1, j: -1 }; // 当前连线点
 | 
	
		
			
				|  |  | +          this.answerList.findIndex((item, i) => {
 | 
	
		
			
				|  |  | +            return item.some((li, j) => {
 | 
	
		
			
				|  |  | +              if (li.mark === mark) {
 | 
	
		
			
				|  |  | +                cur = { i, j };
 | 
	
		
			
				|  |  | +                return true;
 | 
	
		
			
				|  |  | +              }
 | 
	
		
			
				|  |  | +            });
 | 
	
		
			
				|  |  | +          });
 | 
	
		
			
				|  |  | +          this.curConnectionPoint = { i: cur.i, j: cur.j, mark };
 | 
	
		
			
				|  |  | +          this.createLine(item[j + 1], false, isShowRightAnswer);
 | 
	
		
			
				|  |  | +        });
 | 
	
		
			
				|  |  | +      });
 | 
	
		
			
				|  |  | +    },
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 创建连接线
 | 
	
		
			
				|  |  |       * @param {String} mark 选项标识
 | 
	
		
			
				|  |  |       * @param {Boolean} isDrag 是否是拖拽
 | 
	
		
			
				|  |  | +     * @param {Boolean} isShowRightAnswer 是否是显示正确答案
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    createLine(mark, isDrag = false) {
 | 
	
		
			
				|  |  | -      let { offsetWidth, offsetLeft, offsetTop, offsetHeight } = document.getElementsByClassName(`item-${mark}`)[0];
 | 
	
		
			
				|  |  | -      const { curOffsetWidth, curOffsetLeft, curOffsetTop, curOffsetHeight, curMark } =
 | 
	
		
			
				|  |  | -        this.computedCurConnectionPoint(isDrag);
 | 
	
		
			
				|  |  | +    createLine(mark, isDrag = false, isShowRightAnswer = false) {
 | 
	
		
			
				|  |  | +      const { offsetWidth, offsetLeft, offsetTop, offsetHeight } = document.getElementsByClassName(
 | 
	
		
			
				|  |  | +        `${isShowRightAnswer ? 'answer-' : ''}item-${mark}`,
 | 
	
		
			
				|  |  | +      )[0];
 | 
	
		
			
				|  |  | +      const { curOffsetWidth, curOffsetLeft, curOffsetTop, curOffsetHeight, curMark } = this.computedCurConnectionPoint(
 | 
	
		
			
				|  |  | +        isDrag,
 | 
	
		
			
				|  |  | +        isShowRightAnswer,
 | 
	
		
			
				|  |  | +      );
 | 
	
		
			
				|  |  |        let top = Math.min(offsetTop + offsetHeight / 2, curOffsetTop + curOffsetHeight / 2);
 | 
	
		
			
				|  |  |        // 判断是否是同一行
 | 
	
		
			
				|  |  |        const isSameRow = Math.abs(offsetTop + offsetHeight / 2 - (curOffsetTop + curOffsetHeight / 2)) <= 2;
 | 
	
	
		
			
				|  | @@ -239,7 +293,7 @@ export default {
 | 
	
		
			
				|  |  |        path.setAttribute('d', `M ${size ? 0 : width} 0 L ${size ? width : 0} ${height}`); // 设置路径数据
 | 
	
		
			
				|  |  |        this.setPathAttr(path);
 | 
	
		
			
				|  |  |        svg.appendChild(path);
 | 
	
		
			
				|  |  | -      this.$refs.list.appendChild(svg); // 将SVG元素插入到文档中
 | 
	
		
			
				|  |  | +      this.$refs[isShowRightAnswer ? 'answerList' : 'list'].appendChild(svg); // 将SVG元素插入到文档中
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |        // 清除当前连线点
 | 
	
		
			
				|  |  |        this.resetCurConnectionPoint();
 | 
	
	
		
			
				|  | @@ -254,10 +308,12 @@ export default {
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 计算当前连线点的位置
 | 
	
		
			
				|  |  |       * @param {Boolean} isDrag 是否是拖拽
 | 
	
		
			
				|  |  | +     * @param {Boolean} isShowRightAnswer 是否是显示正确答案
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    computedCurConnectionPoint(isDrag = false) {
 | 
	
		
			
				|  |  | +    computedCurConnectionPoint(isDrag = false, isShowRightAnswer = false) {
 | 
	
		
			
				|  |  |        const { mark } = isDrag ? this.mousePointer : this.curConnectionPoint;
 | 
	
		
			
				|  |  | -      let dom = document.getElementsByClassName(`item-${mark}`)[0];
 | 
	
		
			
				|  |  | +      const dom = document.getElementsByClassName(`${isShowRightAnswer ? 'answer-' : ''}item-${mark}`)[0];
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |        return {
 | 
	
		
			
				|  |  |          curOffsetWidth: dom.offsetWidth,
 | 
	
		
			
				|  |  |          curOffsetLeft: dom.offsetLeft,
 | 
	
	
		
			
				|  | @@ -383,5 +439,11 @@ export default {
 | 
	
		
			
				|  |  |        }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  .right-answer {
 | 
	
		
			
				|  |  | +    .title {
 | 
	
		
			
				|  |  | +      margin-bottom: 24px;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  </style>
 |