diff --git a/src/assets/images/canvas/xiangao.png b/src/assets/images/canvas/xiangao.png index 89774ded..330e0b1e 100644 Binary files a/src/assets/images/canvas/xiangao.png and b/src/assets/images/canvas/xiangao.png differ diff --git a/src/assets/images/canvas/xiangaofenge.png b/src/assets/images/canvas/xiangaofenge.png index a7c53528..02d9a49b 100644 Binary files a/src/assets/images/canvas/xiangaofenge.png and b/src/assets/images/canvas/xiangaofenge.png differ diff --git a/src/component/Canvas/CanvasEditor/commands/FillRepeatCommand.js b/src/component/Canvas/CanvasEditor/commands/FillRepeatCommand.js index a866c299..d223957e 100644 --- a/src/component/Canvas/CanvasEditor/commands/FillRepeatCommand.js +++ b/src/component/Canvas/CanvasEditor/commands/FillRepeatCommand.js @@ -52,83 +52,112 @@ export class FillRepeatCommand extends Command { console.warn("当前对象不能平铺", object.type); return false; } - console.log("===========", object.toObject(["id", "layerId", "layerName"])) this.oldObjects = object; - const img = await new Promise((resolve, reject) => { - if (object.type === "rect") { - let source = object.fill.source; - resolve(source); - } else if (object.type === "image") { - // resolve(object.getElement()); - // fabric.Image.fromURL( - // object.src, - // v => resolve(v), - // { crossOrigin: "anonymous" } - // ); - const imgElement = object.getElement(); - // 创建透明 Canvas - const tcanvas = document.createElement('canvas'); - tcanvas.width = imgElement.width; - tcanvas.height = imgElement.height; - const ctx = tcanvas.getContext('2d'); - ctx.clearRect(0, 0, tcanvas.width, tcanvas.height); - ctx.drawImage(imgElement, 0, 0); - resolve(tcanvas); - } - }); - const fill_ = { - source: FillSourceToBase64(img), - gapX: 0, - gapY: 0, - width: img.width, - height: img.height, - }; - const bgObject = this.canvasManager.getBackgroundLayerObject(); - const pattern = new fabric.Pattern({ - source: img, - repeat: this.fillRepeat, - patternTransform: object.fill?.hasOwnProperty("patternTransform") ? object.fill.patternTransform : createPatternTransform(scale, 0), - offsetX: object.fill?.hasOwnProperty("offsetX") ? object.fill.offsetX : bgObject.width / 2, // 水平偏移 - offsetY: object.fill?.hasOwnProperty("offsetY") ? object.fill.offsetY : bgObject.height / 2, // 垂直偏移 - }); - const rect = new fabric.Rect({ - id: object.id, - layerId: object.layerId, - layerName: object.layerName, - fill_, - }); - layer.fabricObjects = [rect.toObject(["id", "layerId", "layerName"])]; - this.oldLocked = layer.locked; - // this.oldIsDisableUnlock = layer.isDisableUnlock; - // layer.isDisableUnlock = true; - if (this.oldObjects.type === "rect") { - rect.set({ - width: object.width, - height: object.height, - top: object.top, - left: object.left, - originX: object.originX, - originY: object.originY, - angle: object.angle, - scaleX: object.scaleX, - scaleY: object.scaleY, - flipX: object.flipX, - flipY: object.flipY, + if (this.fillRepeat === "no-repeat") { + const fill_ = object.fill_; + const image = await new Promise((resolve, reject) => { + fabric.Image.fromURL( + fill_.source, + v => resolve(v), + { crossOrigin: "anonymous" } + ); }); + image.set({ + id: object.id, + layerId: object.layerId, + layerName: object.layerName, + ...(fill_.originalInfo || { + top: object.top, + left: object.left, + }) + }); + layer.fabricObjects = [image.toObject(["id", "layerId", "layerName"])]; + this.oldLocked = layer.locked; + layer.locked = false; + + this.canvas.add(image); + this.canvas.remove(object); } else { - rect.set({ - width: bgObject.width, - height: bgObject.height, - top: bgObject.top, - left: bgObject.left, - originX: bgObject.originX, - originY: bgObject.originY, + const img = await new Promise((resolve, reject) => { + if (object.type === "rect") { + let source = object.fill.source; + resolve(source); + } else if (object.type === "image") { + const imgElement = object.getElement(); + // 创建透明 Canvas + const tcanvas = document.createElement('canvas'); + tcanvas.width = imgElement.width; + tcanvas.height = imgElement.height; + const ctx = tcanvas.getContext('2d'); + ctx.clearRect(0, 0, tcanvas.width, tcanvas.height); + ctx.drawImage(imgElement, 0, 0); + resolve(tcanvas); + } }); - layer.locked = true; + const fill_ = object.fill_ || { + source: FillSourceToBase64(img), + gapX: 0, + gapY: 0, + width: img.width, + height: img.height, + originalInfo: { + top: object.top, + left: object.left, + scaleX: object.scaleX, + scaleY: object.scaleY, + width: object.width, + height: object.height, + } + }; + const bgObject = this.canvasManager.getBackgroundLayerObject(); + const pattern = new fabric.Pattern({ + source: img, + repeat: this.fillRepeat, + patternTransform: object.fill?.hasOwnProperty("patternTransform") ? object.fill.patternTransform : createPatternTransform(scale, 0), + offsetX: object.fill?.hasOwnProperty("offsetX") ? object.fill.offsetX : bgObject.width / 2, // 水平偏移 + offsetY: object.fill?.hasOwnProperty("offsetY") ? object.fill.offsetY : bgObject.height / 2, // 垂直偏移 + }); + const rect = new fabric.Rect({ + id: object.id, + layerId: object.layerId, + layerName: object.layerName, + fill_, + }); + layer.fabricObjects = [rect.toObject(["id", "layerId", "layerName"])]; + this.oldLocked = layer.locked; + // this.oldIsDisableUnlock = layer.isDisableUnlock; + // layer.isDisableUnlock = true; + if (this.oldObjects.type === "rect") { + rect.set({ + width: object.width, + height: object.height, + top: object.top, + left: object.left, + originX: object.originX, + originY: object.originY, + angle: object.angle, + scaleX: object.scaleX, + scaleY: object.scaleY, + flipX: object.flipX, + flipY: object.flipY, + }); + } else { + let scaleX = bgObject.scaleX || 1; + let scaleY = bgObject.scaleY || 1; + rect.set({ + width: bgObject.width, + height: bgObject.height, + top: bgObject.top - bgObject.height * scaleY / 2, + left: bgObject.left - bgObject.width * scaleX / 2, + scaleX, + scaleY, + }); + layer.locked = true; + } + rect.set("fill", pattern); + this.canvas.add(rect); + this.canvas.remove(object); } - rect.set("fill", pattern); - this.canvas.add(rect); - this.canvas.remove(object); await this.layerManager?.updateLayersObjectsInteractivity(); await this.layerManager?.sortLayersWithTool?.(); await this.canvasManager.thumbnailManager?.generateLayerThumbnail( diff --git a/src/component/Canvas/CanvasEditor/commands/LayerCommands.js b/src/component/Canvas/CanvasEditor/commands/LayerCommands.js index 0aa04417..54bee584 100644 --- a/src/component/Canvas/CanvasEditor/commands/LayerCommands.js +++ b/src/component/Canvas/CanvasEditor/commands/LayerCommands.js @@ -144,7 +144,7 @@ export class AddLayerCommand extends Command { // 先在一级图层中查找 for (let i = 0; i < layers.length; i++) { const layer = layers[i]; - + if (layer.isPrintTrimsGroup) continue; if (layer.id === layerId) { return { layer: layer, diff --git a/src/component/Canvas/CanvasEditor/commands/TextCommands.js b/src/component/Canvas/CanvasEditor/commands/TextCommands.js index 8e6c80c0..a9e5699f 100644 --- a/src/component/Canvas/CanvasEditor/commands/TextCommands.js +++ b/src/component/Canvas/CanvasEditor/commands/TextCommands.js @@ -493,7 +493,7 @@ export class CreateTextCommand extends Command { // 先在一级图层中查找 for (let i = 0; i < layers.length; i++) { const layer = layers[i]; - + if (layer.isPrintTrimsGroup) continue; if (layer.id === layerId) { return { layer: layer, diff --git a/src/component/Canvas/CanvasEditor/components/LayersPanel/LayersList.vue b/src/component/Canvas/CanvasEditor/components/LayersPanel/LayersList.vue index 5bab1e49..e2d574e7 100644 --- a/src/component/Canvas/CanvasEditor/components/LayersPanel/LayersList.vue +++ b/src/component/Canvas/CanvasEditor/components/LayersPanel/LayersList.vue @@ -287,7 +287,7 @@ const canDeleteComputed = computed(() => { :is-child="isChild" :is-active="layer.id === activeLayerId" :is-selected="isLayerSelected(layer.id)" - :is-multi-select-mode="isMultiSelectMode" + :is-multi-select-mode="isMultiSelectMode && !layer.specialType" :is-editing="editingLayerId === layer.id" :editing-name="editingLayerName" :can-delete=" @@ -296,7 +296,7 @@ const canDeleteComputed = computed(() => { :expanded-group-ids="expandedGroupIds" @click="(...args) => forwardEvent('layer-click', ...args)" @double-click="(...args) => forwardEvent('layer-double-click', ...args)" - @context-menu="(...args) => forwardEvent('context-menu', ...args)" + @context-menu="(...args) => !layer.specialType && forwardEvent('context-menu', ...args)" @checkbox-change="(...args) => forwardEvent('checkbox-change', ...args)" @toggle-visibility="(...args) => forwardEvent('toggle-visibility', ...args)" @toggle-lock="(...args) => forwardEvent('toggle-lock', ...args)" @@ -337,7 +337,7 @@ const canDeleteComputed = computed(() => { :expanded-group-ids="expandedGroupIds" :isChild="true" :parentLayerId="layer.id" - :group-name="groupName" + :group-name="layer.specialType || groupName" @layer-click="(...args) => forwardEvent('layer-click', ...args)" @layer-double-click="(...args) => forwardEvent('layer-double-click', ...args)" @context-menu="(...args) => forwardEvent('context-menu', ...args)" @@ -385,17 +385,10 @@ const canDeleteComputed = computed(() => { \ No newline at end of file diff --git a/src/component/Canvas/OverallCanvas/index.vue b/src/component/Canvas/OverallCanvas/index.vue new file mode 100644 index 00000000..a73ec8a5 --- /dev/null +++ b/src/component/Canvas/OverallCanvas/index.vue @@ -0,0 +1,305 @@ + + + + + + + \ No newline at end of file diff --git a/src/component/Canvas/canvasExample.vue b/src/component/Canvas/canvasExample.vue index 772e1ce0..be04b46a 100644 --- a/src/component/Canvas/canvasExample.vue +++ b/src/component/Canvas/canvasExample.vue @@ -71,8 +71,8 @@ const editorConfig = { const exportImage = async () => { if (canvasEditor.value) { const base64 = await canvasEditor.value.exportImage({ - isContainFixed: false, // 是否导出底图 - isContainFixedOther: false, // 是否导出其他固定图层 + isContainFixed: true, // 是否导出底图 + isContainFixedOther: true, // 是否导出其他固定图层 isContainBg: false, // 是否导出背景 isEnhanceImg: false, // 是否导出增强图片 }); @@ -109,7 +109,33 @@ const exportExtraInfo = async () => { } }; - +// 更新其他图层颜色 +const updateOtherLayersColor = async () => { + const obj = { + color: {rgba: {r:255,g:255,b:0,a:1}}, + } + await canvasEditor?.value?.updateOtherLayers?.(obj); +}; +// 更新其他图层印花 +const updateOtherLayersPrint = async () => { +// document.querySelector(".app-container").style.width = "50vw" + const obj = { + printObject: { + prints: [ + { + ifSingle: true, + level2Type: "Pattern", + designType: "Library", + path: "/src/assets/images/canvas/yinhua1.jpg", + location: [250, 780], + scale: [0.3, 0.4], + angle: 0, + }, + ] + }, + } + await canvasEditor?.value?.updateOtherLayers?.(obj); +}; const changeCanvas = (command) => { console.log(command); @@ -219,6 +245,20 @@ const customToolsList = ref([ label: "导E", class: "export-btn", }, + { + id: "updateExtraInfo_color", + title: "更新颜色", + action: updateOtherLayersColor, + label: "更C", + class: "export-btn", + }, + { + id: "updateExtraInfo_print", + title: "更新印花", + action: updateOtherLayersPrint, + label: "更P", + class: "export-btn", + }, { id: "exportPNG", title: "导出PNG", //导出画布图片 @@ -295,22 +335,22 @@ 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.5 * 0.7, 0.272541 * 0.7], - 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", designType: "Library", path: "/src/assets/images/canvas/yinhua1.jpg", - location: [250, 780], - scale: [0.5 * 0.7, 0.272541 * 0.7], + location: [550, 650], + scale: [0.15, 0.2], angle: 0, }, { @@ -318,8 +358,8 @@ const otherData = { level2Type: "Pattern", designType: "Library", path: "/src/assets/images/canvas/yinhua1.jpg", - location: [300, 500], - scale: [0.5 * 0.4, 0.272541 * 0.4], + location: [700, 400], + scale: [0.1, 0.133], angle: 0, } ] diff --git a/src/component/Canvas/pingpu.vue b/src/component/Canvas/pingpu.vue deleted file mode 100644 index 525e3017..00000000 --- a/src/component/Canvas/pingpu.vue +++ /dev/null @@ -1,156 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/src/component/Canvas/test.vue b/src/component/Canvas/test.vue index dc21c59a..0bdc03af 100644 --- a/src/component/Canvas/test.vue +++ b/src/component/Canvas/test.vue @@ -1,73 +1,95 @@ - - - - 偏移X - - - - 偏移Y - - - - 角度 - - - - 缩放 - - - - 水平间距 - - - - 垂直间距 - - - - - - + + \ No newline at end of file