From 25f5d91e8711f9bcda18565447226cbfeb2d62a6 Mon Sep 17 00:00:00 2001 From: MTrun <1262327911@qq.com> Date: Sun, 30 Jan 2022 22:56:29 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=9B=BE?= =?UTF-8?q?=E8=A1=A8=E6=8B=96=E6=8B=BD=E7=9A=84=E4=BD=8D=E7=BD=AE=E9=A2=84?= =?UTF-8?q?=E7=95=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chart/ContentEdit/hooks/useDrop.hook.ts | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/views/chart/ContentEdit/hooks/useDrop.hook.ts b/src/views/chart/ContentEdit/hooks/useDrop.hook.ts index f6f8099c..bd97707b 100644 --- a/src/views/chart/ContentEdit/hooks/useDrop.hook.ts +++ b/src/views/chart/ContentEdit/hooks/useDrop.hook.ts @@ -70,9 +70,11 @@ export const useMouseHandle = () => { // 获取编辑区域 Dom const editcontentDom = chartEditStore.getEditCanvas.editContentDom - // 记录图表初始位置 + // 记录图表初始位置和大小 const itemAttrX = item.attr.x const itemAttrY = item.attr.y + const itemAttrW = item.attr.w + const itemAttrH = item.attr.h // 记录点击初始位置 const startX = e.screenX @@ -83,13 +85,15 @@ export const useMouseHandle = () => { let currX = itemAttrX + (moveEvent.screenX - startX) / scale let currY = itemAttrY + (moveEvent.screenY - startY) / scale - // 位置检测 - currX = currX < 0 ? 0 : currX - currY = currY < 0 ? 0 : currY + // 要预留的距离 + const distance = 50 + // 基于左上角位置检测 + currX = currX < -itemAttrW + distance ? -itemAttrW + distance : currX + currY = currY < -itemAttrH + distance ? -itemAttrH + distance : currY - // 预留 20px 边距 - currX = currX > width - 20 ? width - 20 : currX - currY = currY > height - 20 ? height - 20 : currY + // 基于右下角位置检测 + currX = currX > width - distance ? width - distance : currX + currY = currY > height - distance ? height - distance : currY item.attr.x = currX item.attr.y = currY