|
|
@@ -1,5 +1,5 @@
|
|
|
<template>
|
|
|
- <div class="stage-wrapper" ref="stageWrapperRef" :style="getWrapperStyle">
|
|
|
+ <div class="stage-wrapper" ref="stageWrapperRef" :style="getWrapperStyle" @wheel="handleWheel">
|
|
|
<div class="stage" ref="stageRef" :style="getStyles.stageStyle">
|
|
|
<div ref="tipRef" class="tip-txt" :style="getStyles.tipStyle">
|
|
|
{{ screen?.name }}:{{ page?.name }}
|
|
|
@@ -34,7 +34,6 @@
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
-import type { Ref } from 'vue'
|
|
|
import type { StageState } from './type'
|
|
|
import type { Page } from '@/types/page'
|
|
|
import type { Screen } from '@/types/screen'
|
|
|
@@ -42,6 +41,8 @@ import type { Screen } from '@/types/screen'
|
|
|
import { ref, onMounted, computed, nextTick } from 'vue'
|
|
|
import { useScroll, useElementSize } from '@vueuse/core'
|
|
|
import { useProjectStore } from '@/store/modules/project'
|
|
|
+import { useCanvasMove } from './useCanvasMove'
|
|
|
+import { throttle } from 'lodash-es'
|
|
|
|
|
|
import Nodes from './Node.vue'
|
|
|
import Moveable from './Moveable.vue'
|
|
|
@@ -54,11 +55,13 @@ const props = defineProps<{
|
|
|
const emit = defineEmits<{
|
|
|
changeState: [Partial<StageState>]
|
|
|
}>()
|
|
|
-const stageWrapperRef: Ref<HTMLElement | null> = ref(null)
|
|
|
-const canvasRef: Ref<HTMLElement | null> = ref(null)
|
|
|
+const stageWrapperRef = ref<HTMLDivElement>()
|
|
|
+const canvasRef = ref<HTMLDivElement>()
|
|
|
const { width: clientWidth, height: clientHeight } = useElementSize(stageWrapperRef)
|
|
|
const projectStore = useProjectStore()
|
|
|
|
|
|
+useCanvasMove(stageWrapperRef, props.state)
|
|
|
+
|
|
|
const getWrapperStyle = computed(() => {
|
|
|
const { showRuler } = props.state
|
|
|
return {
|
|
|
@@ -138,6 +141,9 @@ const getStyles = computed(() => {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
+/**
|
|
|
+ * 监听滚动 更新标尺
|
|
|
+ */
|
|
|
useScroll(stageWrapperRef, {
|
|
|
throttle: 0,
|
|
|
onScroll: () => {
|
|
|
@@ -193,6 +199,22 @@ const initStagePosition = async () => {
|
|
|
stageWrapperRef.value!.scrollTo(centerX, centerY)
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 滚动缩放处理
|
|
|
+ * Ctrl + 鼠标滚轮缩放
|
|
|
+ */
|
|
|
+const handleWheel = throttle((e: WheelEvent) => {
|
|
|
+ if (e.ctrlKey) {
|
|
|
+ const { state } = props
|
|
|
+ //滚轮方向
|
|
|
+ const direction = e.deltaY > 0 ? 'down' : 'up'
|
|
|
+ const scale = direction === 'up' ? state.scale + 0.05 : state.scale - 0.05
|
|
|
+ emit('changeState', {
|
|
|
+ scale: scale < 0.1 ? 0.1 : scale > 4 ? 4 : scale
|
|
|
+ })
|
|
|
+ }
|
|
|
+}, 16)
|
|
|
+
|
|
|
defineExpose({
|
|
|
getPosition: () => canvasRef.value?.getBoundingClientRect(),
|
|
|
initScale,
|