Explorar o código

解决练习题连线时不在中点问题

dusenyao hai 11 meses
pai
achega
1d55fd662d
Modificáronse 1 ficheiros con 10 adicións e 5 borrados
  1. 10 5
      src/views/exercise_questions/preview/MatchingPreview.vue

+ 10 - 5
src/views/exercise_questions/preview/MatchingPreview.vue

@@ -382,17 +382,22 @@ export default {
         isDrag,
         isShowRightAnswer,
       );
-      let top = Math.min(offsetTop + offsetHeight / 2, curOffsetTop + offsetHeight / 2);
+      let top = Math.min(offsetTop + offsetHeight / 2, curOffsetTop + curOffsetHeight / 2);
+      // 判断是否是同一行
+      const isSameRow = Math.abs(offsetTop + offsetHeight / 2 - (curOffsetTop + curOffsetHeight / 2)) <= 2;
       let left = Math.min(offsetLeft + offsetWidth, curOffsetLeft + curOffsetWidth);
       let width = Math.abs(
         offsetLeft > curOffsetLeft
           ? curOffsetLeft - offsetLeft + offsetWidth
           : offsetLeft - curOffsetLeft + curOffsetWidth,
       );
-      let height =
-        curOffsetTop > offsetTop
-          ? Math.abs(offsetTop + offsetHeight / 2 - (curOffsetTop + curOffsetHeight / 2))
-          : Math.abs(offsetTop - curOffsetTop);
+      let height = 0;
+      if (!isSameRow) {
+        height =
+          curOffsetTop > offsetTop
+            ? Math.abs(offsetTop + offsetHeight / 2 - (curOffsetTop + curOffsetHeight / 2))
+            : Math.abs(offsetTop - curOffsetTop + offsetHeight / 2 - curOffsetHeight / 2);
+      }
       let size = offsetLeft > curOffsetLeft ? offsetTop > curOffsetTop : offsetTop < curOffsetTop; // 判断是左上还是右下
       // 创建一个空的SVG元素
       let svg = document.createElementNS(svgNS, 'svg');