课堂展示:画布拖选问题修复

This commit is contained in:
白了个白 2024-12-26 10:25:54 +08:00
parent 1a3598d7c0
commit 1f9111a89d
1 changed files with 34 additions and 32 deletions

View File

@ -1,6 +1,12 @@
<template>
<div class="whiteboart-container" :style="{ height: height + 'px' }">
<div class="canvasBox" ref="box" @mouseleave="handleMouseLeave" ></div>
<div class="canvasBox" ref="box"
@mousedown="handleMouseDown"
@mousemove="handleMouseMove"
@mouseup="handleMouseUp"
@mouseleave="handleMouseLeave"
></div>
<div class="footerLeft" @click.stop
:style="type == 'design' ? ['top: 10px', 'justify-content: space-between'] : ['bottom: 10px', 'justify-content: center']">
@ -352,6 +358,10 @@ const currentType = ref('selection')
// dom
const box = ref(null)
const startX= ref(0)
const startY= ref(0)
const endX= ref(0)
const endY= ref(0)
//
let app = null
@ -745,6 +755,7 @@ const init = () => {
})
//
app.on('activeElementChange', element => {
console.log('点击元素 监听 activeElementChange-----------', element)
if (activeElement.value) {
activeElement.value.off('elementRotateChange', onElementRotateChange)
}
@ -794,44 +805,35 @@ const init = () => {
})
}
const isDragging = ref(false);
/**
* 课堂展示-鼠标离开白板监听事件该事件是避免选中状态在其他地方点击后退删除等事件会删除白板内选中的元素
*/
const handleMouseLeave = () => {
console.log('离开白板')
//
// app.cancelActiveElement()
// --
app.cancelActiveElement()
const rect = proxy.$refs.box.getBoundingClientRect();
const x = event.clientX - rect.left;
const y = event.clientY - rect.top;
const selectedShape = this.shapes.find(shape => {
return x >= shape.x && x <= shape.x + shape.width && y >= shape.y && y <= shape.y + shape.height;
});
if (selectedShape) {
console.log('选中的元素:', selectedShape);
}
//
// console.log(", selection", currentType.value)
// //
// console.log("", activeElement.value)
// // if (activeElement.value) {
// // console.log("")
// // activeElement.value = null
// // }
// // //
// console.log("", selectedElements.value)
// if( selectedElements.value.length > 0) {
// console.log("")
// selectedElements.value = []
// }
// const canvas = box.value;
// canvas.blur(); //
// this.isDragging = false;
// this.drawRectangle();
};
const handleMouseDown = (event) =>{
// this.isDragging = true;
// this.startX = event.clientX;
// this.startY = event.clientY;
}
const handleMouseMove =(event)=> {
// if (this.isDragging) {
// this.endX = event.clientX;
// this.endY = event.clientY;
// this.drawRectangle();
// }
}
const handleMouseUp = () =>{
// this.isDragging = false;
// this.drawRectangle();
}
//
defineExpose({