画布组件卸载清理资源

This commit is contained in:
李志鹏
2025-11-13 14:54:50 +08:00
parent 4c951b3a0a
commit 1c33d42f99
5 changed files with 14 additions and 37 deletions

View File

@@ -277,16 +277,6 @@
clipData.left = x;
clipData.img_width = elInfo.width;
clipData.img_height = elInfo.height;
if (!el.value) return;
const elh = el.value.offsetHeight;
const elsh = el.value.scrollHeight;
const elst = el.value.scrollTop;
if (y < elst) {
el.value.scrollTop = y;
} else if (y + clipInfo.height > elst + elh) {
el.value.scrollTop = y + clipInfo.height - elh;
}
};
const mouseup = () => {
window.removeEventListener("mousemove", mousemove);

View File

@@ -279,9 +279,7 @@
layerManager: props.layerManager,
canvas: props.canvas,
toolManager: props.toolManager,
}).then(res=>{
console.log("========",res);
});
})
});
};

View File

@@ -530,15 +530,15 @@ onBeforeUnmount(() => {
// return; // 开发环境下不卸载组件
// }
console.log("onBeforeUnmount 组件卸载,清理资源...");
// canvasManager?.dispose?.();
// commandManager?.dispose?.();
// layerManager?.dispose?.();
// keyboardManager?.dispose?.();
// toolManager?.dispose?.();
// liquifyManager?.dispose?.();
// selectionManager?.dispose?.();
// redGreenModeManager?.dispose?.();
// minimapManager?.dispose?.();
canvasManager?.dispose?.();
commandManager?.dispose?.();
layerManager?.dispose?.();
keyboardManager?.dispose?.();
toolManager?.dispose?.();
liquifyManager?.dispose?.();
selectionManager?.dispose?.();
redGreenModeManager?.dispose?.();
// minimapManager?.dispose?.();
canvasManager = null;
commandManager = null;
layerManager = null;

View File

@@ -2303,9 +2303,9 @@ export class LayerManager {
*/
dispose() {
// 清空画布
if (this.canvas) {
this.canvas.clear();
}
// if (this.canvas) {
// this.canvas.clear();
// }
// 清空图层数据
if (this.layers && this.layers.value) {

View File

@@ -728,18 +728,7 @@ export class KeyboardManager {
*/
dispose() {
// 移除事件监听
this.container.removeEventListener("keydown", this._handleKeyDown);
this.container.removeEventListener("keyup", this._handleKeyUp);
this.container.removeEventListener("paste", this._handlePaste);
// 如果有触摸事件,也移除它们
if (this.isTouchDevice) {
this.container.removeEventListener("touchstart", this._handleTouchStart);
this.container.removeEventListener("touchmove", this._handleTouchMove);
this.container.removeEventListener("touchend", this._handleTouchEnd);
this.container.removeEventListener("touchcancel", this._handleTouchEnd);
}
this.removeEvents();
// 清除引用
this.toolManager = null;
this.commandManager = null;