web-课程任务

This commit is contained in:
2025-10-22 18:00:27 +08:00
parent d0cebe1995
commit 3158a85934
16 changed files with 2965 additions and 235 deletions

View File

@@ -31,12 +31,10 @@ export class ImageResize {
this.quill = quill;
this.options = options;
console.log('🔄 ImageResize 模块初始化');
// 等待编辑器完全初始化
setTimeout(() => {
this.initEventListeners();
console.log('✅ ImageResize 事件监听器已添加');
}, 100);
}
@@ -51,14 +49,11 @@ export class ImageResize {
handleClick(e: MouseEvent) {
const target = e.target as HTMLElement;
console.log('🖱️ 点击事件:', target.tagName, target);
// 检查是否点击了图片或视频
if (this.isResizableElement(target)) {
console.log('📷 检测到图片/视频点击,显示缩放控件');
this.showResizer(target as HTMLImageElement | HTMLVideoElement);
} else if (!this.overlay || !this.overlay.contains(target)) {
console.log('❌ 隐藏缩放控件');
this.hideResizer();
}
}
@@ -79,7 +74,6 @@ export class ImageResize {
showResizer(element: HTMLImageElement | HTMLVideoElement) {
this.element = element;
console.log('🎯 显示缩放控件,元素:', element);
// 创建遮罩层
if (!this.overlay) {
@@ -91,7 +85,6 @@ export class ImageResize {
// 更新遮罩层位置和大小
this.updateOverlayPosition(element);
console.log('✅ 缩放控件已显示');
}
private updateOverlayPosition(element: HTMLImageElement | HTMLVideoElement) {
@@ -99,13 +92,7 @@ export class ImageResize {
const rect = element.getBoundingClientRect();
const containerRect = this.quill.root.getBoundingClientRect();
console.log('📐 元素尺寸:', {
width: rect.width,
height: rect.height,
left: rect.left,
top: rect.top
});
this.overlay.style.display = 'block';
this.overlay.style.left = `${rect.left - containerRect.left + this.quill.root.scrollLeft}px`;
@@ -305,7 +292,6 @@ export class ImageResize {
private onResizeEnd() {
if (!this.element) return;
console.log('🔄 拉伸结束触发HTML更新');
// 调用自定义回调
if (this.options.onResizeEnd) {
@@ -324,19 +310,16 @@ export class ImageResize {
range: null,
source: 'user'
});
console.log('✅ Quill text-change 事件已触发');
}
// 方案2: 触发 DOM 事件
const inputEvent = new Event('input', { bubbles: true });
this.quill.root.dispatchEvent(inputEvent);
console.log('✅ DOM input 事件已触发');
// 方案3: 强制更新 Quill 内容
setTimeout(() => {
if (this.quill.update) {
this.quill.update();
console.log('✅ Quill 内容已更新');
}
}, 0);
}