|
@ -15,16 +15,27 @@ const props = defineProps({ |
|
|
type: Boolean, |
|
|
type: Boolean, |
|
|
default: true, |
|
|
default: true, |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const emits = defineEmits(['touchstart', 'touchmove', 'touchend']) |
|
|
|
|
|
|
|
|
const stage = ref() |
|
|
const stage = ref() |
|
|
const layer = ref() |
|
|
const layer = ref() |
|
|
const rect = ref() |
|
|
const rect = ref() |
|
|
const tr = ref() |
|
|
const tr = ref() |
|
|
const lines = ref<Konva.Line[]>([]) // 修改: 将 line 改为 lines 数组 |
|
|
const lines = ref<Konva.Line[]>([]) // 修改: 将 line 改为 lines 数组 |
|
|
|
|
|
|
|
|
|
|
|
const graphRef = ref() |
|
|
onMounted(() => { |
|
|
onMounted(() => { |
|
|
addStage() |
|
|
addStage() |
|
|
|
|
|
graphRef.value.addEventListener('touchstart', (e: any) => { |
|
|
|
|
|
emits('touchstart', e) |
|
|
|
|
|
}) |
|
|
|
|
|
graphRef.value.addEventListener('touchmove', (e: any) => { |
|
|
|
|
|
emits('touchmove', e) |
|
|
|
|
|
}) |
|
|
|
|
|
graphRef.value.addEventListener('touchend', (e: any) => { |
|
|
|
|
|
emits('touchend', e) |
|
|
|
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
const zoom = 5 |
|
|
const zoom = 5 |
|
@ -46,7 +57,7 @@ const addStage = () => { |
|
|
layer.value.draw() |
|
|
layer.value.draw() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
let newWidth = (25) * zoom |
|
|
|
|
|
|
|
|
let newWidth = 25 * zoom |
|
|
let newHeight = (75 - 15 * 2) * zoom |
|
|
let newHeight = (75 - 15 * 2) * zoom |
|
|
|
|
|
|
|
|
const addSelect = () => { |
|
|
const addSelect = () => { |
|
@ -76,7 +87,12 @@ const addSelect = () => { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// 在onMounted中rect创建后添加拖拽监听 |
|
|
// 在onMounted中rect创建后添加拖拽监听 |
|
|
|
|
|
rect.value.on('dragstart', (event: any) => { |
|
|
|
|
|
event.evt.stopPropagation() |
|
|
|
|
|
event.cancelBubble = true // 阻止事件冒泡 |
|
|
|
|
|
}) |
|
|
rect.value.on('dragmove', (event: any) => { |
|
|
rect.value.on('dragmove', (event: any) => { |
|
|
|
|
|
event.evt.stopPropagation() |
|
|
event.cancelBubble = true // 阻止事件冒泡 |
|
|
event.cancelBubble = true // 阻止事件冒泡 |
|
|
const pos = rect.value.position() |
|
|
const pos = rect.value.position() |
|
|
const width = newWidth |
|
|
const width = newWidth |
|
@ -123,14 +139,6 @@ const addSelect = () => { |
|
|
return newBoundBox |
|
|
return newBoundBox |
|
|
}, |
|
|
}, |
|
|
}) |
|
|
}) |
|
|
// 监听 Transformer 的事件以阻止冒泡 |
|
|
|
|
|
tr.value.on('dragmove', (event: any) => { |
|
|
|
|
|
event.cancelBubble = true // 阻止事件冒泡 |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
tr.value.on('dragend', (event: any) => { |
|
|
|
|
|
event.cancelBubble = true // 阻止事件冒泡 |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
layer.value.add(rect.value) |
|
|
layer.value.add(rect.value) |
|
|
layer.value.add(tr.value) |
|
|
layer.value.add(tr.value) |
|
@ -265,7 +273,7 @@ defineExpose({ |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- </div> --> |
|
|
<!-- </div> --> |
|
|
<div :id="container" /> |
|
|
|
|
|
|
|
|
<div :id="container" ref="graphRef" /> |
|
|
<!-- <div class="right-line"> --> |
|
|
<!-- <div class="right-line"> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|
<!-- <div class="line" /> --> |
|
|