Explorar o código

fix: 选择框变形问题

zhangjie hai 8 meses
pai
achega
e935d9fe47
Modificáronse 1 ficheiros con 31 adicións e 22 borrados
  1. 31 22
      src/render/components/ElementResize/index.vue

+ 31 - 22
src/render/components/ElementResize/index.vue

@@ -138,7 +138,10 @@ function initControlPoints() {
     return {
       classes: ["control-point", `control-point-${type}`],
       movePoint: actions[type],
-      movePointOver: moveOver,
+      movePointOver: (data: PositionData) => {
+        actions[type](data);
+        movePointOver();
+      },
     };
   });
 }
@@ -159,6 +162,9 @@ function fetchValidSizePos(
 ) {
   if (sizeData.w <= props.minWidth) {
     sizeData.w = props.minWidth;
+
+    if (actionType.includes("l"))
+      sizeData.x = lastSizePos.x + lastSizePos.w - sizeData.w;
   }
   if (props.maxWidth !== 0 && sizeData.w >= props.maxWidth) {
     sizeData.w = props.maxWidth;
@@ -166,6 +172,9 @@ function fetchValidSizePos(
 
   if (sizeData.h <= props.minHeight) {
     sizeData.h = props.minHeight;
+
+    if (actionType.includes("t"))
+      sizeData.y = lastSizePos.y + lastSizePos.h - sizeData.h;
   }
   if (props.maxHeight !== 0 && sizeData.h >= props.maxHeight) {
     sizeData.h = props.maxHeight;
@@ -185,23 +194,29 @@ function fetchValidSizePos(
   if (fitParentTypeWidth.value) {
     if (sizeData.x <= 0) {
       sizeData.x = 0;
-      if (actionType.includes("l")) sizeData.w = lastSizePos.w;
+      if (actionType.includes("l")) sizeData.w = lastSizePos.w + lastSizePos.x;
     }
 
-    if (sizeData.x + sizeData.w > parentNodeSize.w) {
-      sizeData.x = lastSizePos.x;
-      sizeData.w = parentNodeSize.w - sizeData.x;
+    if (sizeData.x + sizeData.w >= parentNodeSize.w) {
+      if (actionType === "move") {
+        sizeData.x = parentNodeSize.w - sizeData.w;
+      } else {
+        sizeData.w = parentNodeSize.w - sizeData.x;
+      }
     }
   }
 
   if (fitParentTypeHeight.value) {
     if (sizeData.y <= 0) {
       sizeData.y = 0;
-      if (actionType.includes("t")) sizeData.h = lastSizePos.h;
+      if (actionType.includes("t")) sizeData.h = lastSizePos.h + lastSizePos.y;
     }
-    if (sizeData.y + sizeData.h > parentNodeSize.h) {
-      sizeData.y = lastSizePos.y;
-      sizeData.h = parentNodeSize.h - sizeData.y;
+    if (sizeData.y + sizeData.h >= parentNodeSize.h) {
+      if (actionType === "move") {
+        sizeData.y = parentNodeSize.h - sizeData.h;
+      } else {
+        sizeData.h = parentNodeSize.h - sizeData.y;
+      }
     }
   }
 
@@ -295,19 +310,9 @@ function moveRightBottomPoint({ left, top }: PositionData) {
   emitChange();
 }
 
-function moveOver({ left, top }: PositionData) {
-  const sp = {
-    ...sizePos,
-    ...{
-      x: left + sizePosOrigin.x,
-      y: top + sizePosOrigin.y,
-    },
-  };
-  objModifyAssign(sizePos, fetchValidSizePos(sp, "move"));
-
+function movePointOver() {
   objModifyAssign(sizePosOrigin, sizePos);
   objModifyAssign(lastSizePos, sizePos);
-  emitChange();
   emit("resizeOver", sizePos);
 }
 
@@ -329,9 +334,13 @@ function moveElement({ left, top }: PositionData) {
   emitChange();
 }
 
-function moveElementOver(pos: PositionData) {
+function moveElementOver({ left, top }: PositionData) {
   if (!props.move) return;
-  moveOver(pos);
+  moveElement({ left, top });
+
+  objModifyAssign(sizePosOrigin, sizePos);
+  objModifyAssign(lastSizePos, sizePos);
+  emit("resizeOver", sizePos);
 }
 
 function emitChange() {