Skip to content

Commit

Permalink
fixBug[Area]: Area组件,在画布缩放的时候,会有出现位置不准的问题 vangleer#83
Browse files Browse the repository at this point in the history
  • Loading branch information
康辉 黄 committed Jan 14, 2025
1 parent 55979f1 commit c57ec7b
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/editor/src/components/editor/Area.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@

<script setup lang="ts">
import { computed, ref } from 'vue'
interface AreaData {
scale: number
}
// 定义 props 并设置默认值
const props = withDefaults(defineProps<AreaData>(), {
scale: 1
})
const emit = defineEmits(['move', 'up'])
const show = ref(false)
const areaData = ref({
Expand All @@ -28,14 +34,14 @@ function onMouseDown(e: MouseEvent) {
const { pageX: downX, pageY: downY } = e
const elRect = (e.target as HTMLElement)!.getBoundingClientRect()
// 鼠标在编辑器中的偏移量
const offsetX = downX - elRect.left
const offsetY = downY - elRect.top
// 鼠标在编辑器中的偏移量(考虑 scale)
const offsetX = (downX - elRect.left) / props.scale
const offsetY = (downY - elRect.top) / props.scale
const onMouseMove = (e: MouseEvent) => {
// 移动的距离
const disX = e.pageX - downX
const disY = e.pageY - downY
const disX = (e.pageX - downX) / props.scale
const disY = (e.pageY - downY) / props.scale
// 得到默认的left、top
let left = offsetX,
Expand Down

0 comments on commit c57ec7b

Please sign in to comment.