From b135f6a61c3c2dd2a7237b8799ef8c367f14402b Mon Sep 17 00:00:00 2001 From: wanglin2 <1013335014@qq.com> Date: Sun, 13 Aug 2023 11:43:44 +0800 Subject: [PATCH] =?UTF-8?q?Demo:=E6=94=AF=E6=8C=81=E7=B2=98=E8=B4=B4?= =?UTF-8?q?=E7=9F=A5=E7=8A=80=E6=80=9D=E7=BB=B4=E5=AF=BC=E5=9B=BE=E7=9A=84?= =?UTF-8?q?=E8=8A=82=E7=82=B9=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/pages/Edit/components/Edit.vue | 2 + web/src/utils/handleClipboardText.js | 70 ++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 web/src/utils/handleClipboardText.js diff --git a/web/src/pages/Edit/components/Edit.vue b/web/src/pages/Edit/components/Edit.vue index 1a8ae5f1..e5df8e27 100644 --- a/web/src/pages/Edit/components/Edit.vue +++ b/web/src/pages/Edit/components/Edit.vue @@ -70,6 +70,7 @@ import NodeIconSidebar from './NodeIconSidebar.vue' import NodeIconToolbar from './NodeIconToolbar.vue' import OutlineEdit from './OutlineEdit.vue' import { showLoading, hideLoading } from '@/utils/loading' +import handleClipboardText from '@/utils/handleClipboardText' // 注册插件 MindMap.usePlugin(MiniMap) @@ -277,6 +278,7 @@ export default { useLeftKeySelectionRightKeyDrag: this.useLeftKeySelectionRightKeyDrag, customInnerElsAppendTo: null, enableAutoEnterTextEditWhenKeydown: true, + customHandleClipboardText: handleClipboardText, // isUseCustomNodeContent: true, // 示例1:组件里用到了router、store、i18n等实例化vue组件时需要用到的东西 // customCreateNodeContent: (node) => { diff --git a/web/src/utils/handleClipboardText.js b/web/src/utils/handleClipboardText.js new file mode 100644 index 00000000..4a9f5623 --- /dev/null +++ b/web/src/utils/handleClipboardText.js @@ -0,0 +1,70 @@ +import { imgToDataUrl } from 'simple-mind-map/src/utils/index' + +// 处理知犀 +const handleZHIXI = async text => { + text = text.replace('￿', '') + try { + // 只处理一项 + const node = JSON.parse(text)[0] + const newNode = {} + const waitLoadImageList = [] + const walk = async (root, newRoot) => { + newRoot.data = { + text: root.data.text, + hyperlink: root.data.hyperlink, + hyperlinkTitle: root.data.hyperlinkTitle, + note: root.data.note + } + // 图片 + if (root.data.image) { + let resolve = null + let promise = new Promise(_resolve => { + resolve = _resolve + }) + waitLoadImageList.push(promise) + try { + newRoot.data.image = await imgToDataUrl(root.data.image) + newRoot.data.imageSize = root.data.imageSize + resolve() + } catch (error) { + resolve() + } + } + // 子节点 + newRoot.children = [] + if (root.children && root.children.length > 0) { + root.children.forEach(item => { + // 概要 + if (item.data.type === 'generalize') { + newRoot.data.generalization = { + text: item.data.text + } + return + } + let newChild = {} + newRoot.children.push(newChild) + walk(item, newChild) + }) + } + } + walk(node, newNode) + await Promise.all(waitLoadImageList) + return { + simpleMindMap: true, + data: newNode + } + } catch (error) { + return '' + } +} + +const handleClipboardText = async text => { + // 处理知犀数据 + if (text.includes('￿')) { + const res = await handleZHIXI(text) + return res + } + return '' +} + +export default handleClipboardText