mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Demo:支持粘贴知犀思维导图的节点数据
This commit is contained in:
parent
2a8b71497f
commit
b135f6a61c
@ -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) => {
|
||||
|
||||
70
web/src/utils/handleClipboardText.js
Normal file
70
web/src/utils/handleClipboardText.js
Normal file
@ -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
|
||||
Loading…
Reference in New Issue
Block a user