feat: 拖拽按住shift键限制水平或垂直移动

This commit is contained in:
pipipi-pikachu 2022-09-06 22:08:49 +08:00
parent bee403bc70
commit 91041be25c

View File

@ -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()
@ -123,8 +124,13 @@ export default (
}
if (!isMouseDown || isMisoperation) return
const moveX = (currentPageX - startPageX) / canvasScale.value
const moveY = (currentPageY - startPageY) / canvasScale.value
let moveX = (currentPageX - startPageX) / canvasScale.value
let 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