Demo:支持粘贴知犀思维导图的节点数据

This commit is contained in:
wanglin2 2023-08-13 11:43:44 +08:00
parent 2a8b71497f
commit b135f6a61c
2 changed files with 72 additions and 0 deletions

View File

@ -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,
// 1routerstorei18nvue西
// customCreateNodeContent: (node) => {

View 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