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