From 91041be25c45a4df05ba41748a5619f10c5894d0 Mon Sep 17 00:00:00 2001 From: pipipi-pikachu Date: Tue, 6 Sep 2022 22:08:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=8B=96=E6=8B=BD=E6=8C=89=E4=BD=8Fshi?= =?UTF-8?q?ft=E9=94=AE=E9=99=90=E5=88=B6=E6=B0=B4=E5=B9=B3=E6=88=96?= =?UTF-8?q?=E5=9E=82=E7=9B=B4=E7=A7=BB=E5=8A=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/Editor/Canvas/hooks/useDragElement.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/views/Editor/Canvas/hooks/useDragElement.ts b/src/views/Editor/Canvas/hooks/useDragElement.ts index 0a61515a..fe109969 100644 --- a/src/views/Editor/Canvas/hooks/useDragElement.ts +++ b/src/views/Editor/Canvas/hooks/useDragElement.ts @@ -1,6 +1,6 @@ import { Ref } from 'vue' import { storeToRefs } from 'pinia' -import { useMainStore, useSlidesStore } from '@/store' +import { useMainStore, useSlidesStore, useKeyboardStore } from '@/store' import { PPTElement } from '@/types/slides' import { AlignmentLineProps } from '@/types/edit' import { VIEWPORT_SIZE } from '@/configs/canvas' @@ -14,6 +14,7 @@ export default ( ) => { const slidesStore = useSlidesStore() const { activeElementIdList, activeGroupElementId } = storeToRefs(useMainStore()) + const { shiftKeyState } = storeToRefs(useKeyboardStore()) const { viewportRatio } = storeToRefs(slidesStore) const { addHistorySnapshot } = useHistorySnapshot() @@ -122,9 +123,14 @@ export default ( Math.abs(startPageY - currentPageY) < sorptionRange } if (!isMouseDown || isMisoperation) return + + let moveX = (currentPageX - startPageX) / canvasScale.value + let moveY = (currentPageY - startPageY) / canvasScale.value - const moveX = (currentPageX - startPageX) / canvasScale.value - const moveY = (currentPageY - startPageY) / canvasScale.value + if (shiftKeyState.value) { + if (Math.abs(moveX) > Math.abs(moveY)) moveY = 0 + if (Math.abs(moveX) < Math.abs(moveY)) moveX = 0 + } // 基础目标位置 let targetLeft = elOriginLeft + moveX