From 7bc666be36b371f7d70e25cc66f699573a2c3ce2 Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Mon, 16 Oct 2023 15:52:52 +0800 Subject: [PATCH] =?UTF-8?q?Feat=EF=BC=9A=E7=B2=98=E8=B4=B4=E5=B8=A6?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E7=9A=84=E6=96=87=E6=9C=AC=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E6=98=AF=E5=90=A6=E6=8C=89=E6=8D=A2=E8=A1=8C?= =?UTF-8?q?=E5=88=86=E5=89=B2=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/constants/defaultOptions.js | 5 ++- simple-mind-map/src/core/render/Render.js | 34 +++++++++++++++++-- web/src/pages/Edit/components/Edit.vue | 16 +++++++-- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/simple-mind-map/src/constants/defaultOptions.js b/simple-mind-map/src/constants/defaultOptions.js index 078653cf..0050ff1c 100644 --- a/simple-mind-map/src/constants/defaultOptions.js +++ b/simple-mind-map/src/constants/defaultOptions.js @@ -214,5 +214,8 @@ export const defaultOpt = { // false:即创建关联线和激活关联线时处于最顶层,其他情况下处于节点下方 associativeLineIsAlwaysAboveNode: true, // 插入概要的默认文本 - defaultGeneralizationText: '概要' + defaultGeneralizationText: '概要', + // 粘贴文本的方式创建新节点时,控制是否按换行自动分割节点,即如果存在换行,那么会根据换行创建多个节点,否则只会创建一个节点 + // 可以传递一个函数,返回promise,resolve代表根据换行分割,reject代表忽略换行 + handleIsSplitByWrapOnPasteCreateNewNode: null } diff --git a/simple-mind-map/src/core/render/Render.js b/simple-mind-map/src/core/render/Render.js index 64a24d7e..bcc11852 100644 --- a/simple-mind-map/src/core/render/Render.js +++ b/simple-mind-map/src/core/render/Render.js @@ -819,7 +819,8 @@ class Render { // 粘贴事件 async onPaste() { - const { errorHandler } = this.mindMap.opt + const { errorHandler, handleIsSplitByWrapOnPasteCreateNewNode } = + this.mindMap.opt // 读取剪贴板的文字和图片 let text = null let img = null @@ -884,9 +885,36 @@ class Render { Array.isArray(smmData) ? smmData : [smmData] ) } else { - this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { - text + const textArr = text.split(/\r?\n|(? { + return !!item }) + // 判断是否需要根据换行自动分割节点 + if (textArr.length > 1 && handleIsSplitByWrapOnPasteCreateNewNode) { + handleIsSplitByWrapOnPasteCreateNewNode() + .then(() => { + this.mindMap.execCommand( + 'INSERT_MULTI_CHILD_NODE', + [], + textArr.map(item => { + return { + data: { + text: item + }, + children: [] + } + }) + ) + }) + .catch(() => { + this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { + text + }) + }) + } else { + this.mindMap.execCommand('INSERT_CHILD_NODE', false, [], { + text + }) + } } } // 存在图片,则添加到当前激活节点 diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 5696a551..aa1641f1 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -96,7 +96,7 @@ MindMap.usePlugin(MiniMap) .usePlugin(Painter) .usePlugin(ScrollbarPlugin) .usePlugin(Formula) - // .usePlugin(Cooperate)// 协同插件 +// .usePlugin(Cooperate)// 协同插件 // 注册自定义主题 customThemeList.forEach(item => { @@ -306,7 +306,14 @@ export default { useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag, customInnerElsAppendTo: null, enableAutoEnterTextEditWhenKeydown: true, - customHandleClipboardText: handleClipboardText + customHandleClipboardText: handleClipboardText, + handleIsSplitByWrapOnPasteCreateNewNode: () => { + return this.$confirm('是否按换行自动分割节点?', '提示', { + confirmButtonText: '是', + cancelButtonText: '否', + type: 'warning' + }) + } // isUseCustomNodeContent: true, // 示例1:组件里用到了router、store、i18n等实例化vue组件时需要用到的东西 // customCreateNodeContent: (node) => { @@ -598,7 +605,10 @@ export default { color: ['#409EFF', '#67C23A', '#E6A23C', '#F56C6C', '#909399'][ Math.floor(Math.random() * 5) ], - avatar: Math.random() > 0.5 ? 'https://img0.baidu.com/it/u=4270674549,2416627993&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1696006800&t=4d32871d14a7224a4591d0c3c7a97311' : '' + avatar: + Math.random() > 0.5 + ? 'https://img0.baidu.com/it/u=4270674549,2416627993&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1696006800&t=4d32871d14a7224a4591d0c3c7a97311' + : '' }) } }