From 852087e4438dd970d2934ea7411c4c877ecac568 Mon Sep 17 00:00:00 2001 From: June <1601745371@qq.com> Date: Tue, 7 Nov 2023 21:58:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86svg=E7=9A=84text?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E7=BC=96=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/ServersPlugin.ts | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/core/ServersPlugin.ts b/src/core/ServersPlugin.ts index 5cdd50fd..97f8f764 100644 --- a/src/core/ServersPlugin.ts +++ b/src/core/ServersPlugin.ts @@ -1,8 +1,8 @@ /* * @Author: 秦少卫 * @Date: 2023-06-20 12:52:09 - * @LastEditors: 秦少卫 - * @LastEditTime: 2023-07-29 21:32:54 + * @LastEditors: June + * @LastEditTime: 2023-11-07 21:57:19 * @Description: 内部插件 */ import { v4 as uuid } from 'uuid'; @@ -22,6 +22,17 @@ function downFile(fileStr: string, fileType: string) { anchorEl.remove(); } +function transformText(objects) { + if (!objects) return; + objects.forEach((item) => { + if (item.objects) { + transformText(item.objects); + } else { + item.type === 'text' && (item.type = 'textbox'); + } + }); +} + class ServersPlugin { public canvas: fabric.Canvas; public editor: IEditor; @@ -58,9 +69,7 @@ class ServersPlugin { insertSvgFile(jsonFile) { // 加载前钩子 this.editor.hooksEntity.hookImportBefore.callAsync(jsonFile, () => { - console.log(jsonFile, '2222'); this.canvas.loadFromJSON(jsonFile, () => { - console.log(jsonFile, '33333'); this.canvas.renderAll(); // 加载后钩子 this.editor.hooksEntity.hookImportAfter.callAsync(jsonFile, () => { @@ -99,8 +108,10 @@ class ServersPlugin { clipboardText(JSON.stringify(jsonStr, null, '\t')); } - saveJson() { + async saveJson() { const dataUrl = this.getJson(); + // 把文本text转为textgroup,让导入可以编辑 + await transformText(dataUrl.objects); const fileStr = `data:text/json;charset=utf-8,${encodeURIComponent( JSON.stringify(dataUrl, null, '\t') )}`;