Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixBug[Area]: Area组件,在画布缩放的时候,会有出现位置不准的问题 #83 #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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