diff --git a/src/components/Canvas/DepthCanvas/components/depth-header-tools.vue b/src/components/Canvas/DepthCanvas/components/depth-header-tools.vue index 42c82f9..e2614aa 100644 --- a/src/components/Canvas/DepthCanvas/components/depth-header-tools.vue +++ b/src/components/Canvas/DepthCanvas/components/depth-header-tools.vue @@ -178,7 +178,8 @@ } const onWorkbench = async () => { exportCanvasToImage(canvasManager.canvas).then((url) => { - emit('workbench', { url }) + const json = canvasManager.getCanvasJSON() + emit('workbench', { url, json }) }) } diff --git a/src/components/Canvas/DepthCanvas/depth-canvas.vue b/src/components/Canvas/DepthCanvas/depth-canvas.vue index 44741ef..d9dc6dd 100644 --- a/src/components/Canvas/DepthCanvas/depth-canvas.vue +++ b/src/components/Canvas/DepthCanvas/depth-canvas.vue @@ -99,7 +99,7 @@ canvasHeight: props.config.height || 600, url: json ? '' : url }) - if (!url && json) await canvasManager.loadJSON(json) + if (json) await canvasManager.loadJSON(json) stateManager.onMounted() canvasManager.onMounted() @@ -185,7 +185,7 @@ const importCanvasFromLocalStorage = () => { const json = localStorage.getItem('canvasJSON') if (!json) return - canvasManager.loadJSON(json, (success) => { + canvasManager.loadJSON(json).then((success) => { if (success) { console.log('导入成功') } else { diff --git a/src/components/Canvas/DepthCanvas/index.vue b/src/components/Canvas/DepthCanvas/index.vue index 5deb00d..a4da0c4 100644 --- a/src/components/Canvas/DepthCanvas/index.vue +++ b/src/components/Canvas/DepthCanvas/index.vue @@ -19,12 +19,16 @@ const open = (options) => { config.value = options + console.log(config.value) + config.value.json = sessionStorage.getItem('canvasJson_' + config.value.id) dialogVisible.value = true } // 工作区 const onWorkbench = (options) => { dialogVisible.value = false - config.value.onWorkbench?.(options) + const json = options.json + sessionStorage.setItem('canvasJson_' + config.value.id, json) + config.value.onWorkbench?.({ url: options.url, json }) } // 关闭 const onClose = () => { diff --git a/src/components/Canvas/DepthCanvas/manager/LayerManager.ts b/src/components/Canvas/DepthCanvas/manager/LayerManager.ts index 032ae2b..91a81e9 100644 --- a/src/components/Canvas/DepthCanvas/manager/LayerManager.ts +++ b/src/components/Canvas/DepthCanvas/manager/LayerManager.ts @@ -343,10 +343,11 @@ export class LayerManager { const index = this.canvasManager.getObjects().indexOf(targetLayer); this.deleteLayerById(targetLayer.info.id, false) this.setActiveID(mergedImage.info.id, false) - await this.canvasManager.add(mergedImage); + await this.canvasManager.add(mergedImage, false); this.canvasManager.canvas.moveTo(mergedImage, index); this.canvasManager.renderAll() this.updateLayers() + this.stateManager.recordState() return true; } /** 设置激活对象可擦除 */ diff --git a/src/components/Canvas/DepthCanvas/manager/StateManager.ts b/src/components/Canvas/DepthCanvas/manager/StateManager.ts index 20f8ad5..d1c569d 100644 --- a/src/components/Canvas/DepthCanvas/manager/StateManager.ts +++ b/src/components/Canvas/DepthCanvas/manager/StateManager.ts @@ -92,7 +92,7 @@ export class StateManager { if (!state) return this.running.value = true this.historyIndex.value = index - this.canvasManager.loadJSON(state.canvas, () => { + this.canvasManager.loadJSON(state.canvas).then(() => { this.event.emit('canvas:undo', state) this.running.value = false }) @@ -105,7 +105,7 @@ export class StateManager { if (!state) return this.running.value = true this.historyIndex.value = index - this.canvasManager.loadJSON(state.canvas, () => { + this.canvasManager.loadJSON(state.canvas).then(() => { this.event.emit('canvas:redo', state) this.running.value = false })