印花图层禁用画笔等工具

This commit is contained in:
李志鹏
2026-01-08 16:37:35 +08:00
parent 5bbc71654a
commit d863376b41
3 changed files with 39 additions and 20 deletions

View File

@@ -153,7 +153,7 @@ const canvasManagerLoaded = ref(false); // 画布是否加载完成
// 红绿图模式状态
const isRedGreenMode = ref(false);
const isShowLayerPanel = ref(true); // 是否显示图层面板
const isShowLayerPanel = ref(false); // 是否显示图层面板
provide("isShowLayerPanel", isShowLayerPanel); // 提供红绿图模式状态给子组件
@@ -546,13 +546,9 @@ watchEffect(() => {
});
onBeforeUnmount(async () => {
// if (import.meta.hot) {
// // 热更新
// console.log("onBeforeUnmount 开发环境热更新不卸载组件...");
// return; // 开发环境下不卸载组件
// }
const extraInfo = await canvasManager.exportExtraInfo();
emit("before-unmount-export-extra-info", extraInfo);
observer.unobserve(canvasContainerRef.value);
// const extraInfo = await canvasManager.exportExtraInfo();
// emit("before-unmount-export-extra-info", extraInfo);
console.log("onBeforeUnmount 组件卸载,清理资源...");
canvasManager?.dispose?.();
@@ -576,7 +572,6 @@ onBeforeUnmount(async () => {
// 移除window resize事件监听
// window.removeEventListener("resize", handleWindowResize);
observer.unobserve(canvasContainerRef.value);
});
// 窗口大小变化处理函数
@@ -584,6 +579,7 @@ function handleWindowResize() {
console.log(132);
// 使用requestAnimationFrame来防止频繁更新
setTimeout(() => {
if(!canvasManager) return;
// 更新画布大小并自动居中所有元素
updateCanvasSize();

View File

@@ -376,8 +376,8 @@ export class ToolManager {
// 设置工具特定的状态
const tool = this.tools[toolId];
if (tool && typeof tool.setup === "function") {
console.log(`画布切换工具:${tool.name}(${toolId})`)
this.canvas.toolId = toolId;
console.log(`画布切换工具:${tool.name}(${toolId})`)
this.canvas.toolId = toolId;
tool.setup();
}
@@ -458,11 +458,31 @@ export class ToolManager {
}
/**
* 检查当前工具是否禁止操作当前选中的对象
* @param {Boolean} isBrushTool 是否为画笔工具
* @returns {Boolean} 是否可以切换
*/
checkToolCanOperateSelectedObject(isBrushTool = false) {
const layer = this.layerManager?.getActiveLayer();
const isSpecialLayer = !!layer?.specialType;
if (isSpecialLayer) {
if(isBrushTool){
this._disableBrushIndicator();
}
this.canvas.defaultCursor = "not-allowed";
}
console.log("===========",isSpecialLayer, this.canvas.defaultCursor);
return isSpecialLayer;
}
/**
* 设置画笔工具
*/
setupBrushTool() {
if (!this.canvas) return;
if (this.checkToolCanOperateSelectedObject(true)) return;
this.canvas.isDrawingMode = true;
this.canvas.selection = false;
@@ -506,6 +526,8 @@ export class ToolManager {
*/
setupEraserTool() {
if (!this.canvas) return;
if (this.checkToolCanOperateSelectedObject(true)) return;
this.canvas.isDrawingMode = true;
this.canvas.selection = false;
@@ -654,6 +676,7 @@ export class ToolManager {
*/
setupLiquifyTool() {
if (!this.canvas || !this.layerManager) return;
if (this.checkToolCanOperateSelectedObject(true)) return;
this.canvas.isDrawingMode = false;
this.canvas.selection = false;

View File

@@ -295,15 +295,15 @@ const otherData = {
color: {rgba: {r:255,g:0,b:0,a:1}},
printObject: {
prints: [
{
ifSingle: false,
level2Type: "Pattern",
designType: "Library",
path: "/src/assets/images/canvas/yinhua1.jpg",
location: [250, 780],
scale: [0.3, 0.4],
angle: 0,
},
// {
// ifSingle: false,
// level2Type: "Pattern",
// designType: "Library",
// path: "/src/assets/images/canvas/yinhua1.jpg",
// location: [250, 780],
// scale: [0.3, 0.4],
// angle: 0,
// },
{
ifSingle: true,
level2Type: "Pattern",