Feat:导入存在多个画布的xmind文件支持选择指定的画布进行导入

This commit is contained in:
街角小林 2024-05-28 17:27:19 +08:00
parent 7c82d16d66
commit f4800746a3

View File

@ -15,7 +15,7 @@ import {
} from '../utils/xmind' } from '../utils/xmind'
// 解析.xmind文件 // 解析.xmind文件
const parseXmindFile = file => { const parseXmindFile = (file, handleMultiCanvas) => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
JSZip.loadAsync(file).then( JSZip.loadAsync(file).then(
async zip => { async zip => {
@ -25,7 +25,7 @@ const parseXmindFile = file => {
let xmlFile = zip.files['content.xml'] || zip.files['/content.xml'] let xmlFile = zip.files['content.xml'] || zip.files['/content.xml']
if (jsonFile) { if (jsonFile) {
let json = await jsonFile.async('string') let json = await jsonFile.async('string')
content = await transformXmind(json, zip.files) content = await transformXmind(json, zip.files, handleMultiCanvas)
} else if (xmlFile) { } else if (xmlFile) {
let xml = await xmlFile.async('string') let xml = await xmlFile.async('string')
let json = xmlConvert.xml2json(xml) let json = xmlConvert.xml2json(xml)
@ -48,8 +48,15 @@ const parseXmindFile = file => {
} }
// 转换xmind数据 // 转换xmind数据
const transformXmind = async (content, files) => { const transformXmind = async (content, files, handleMultiCanvas) => {
const data = JSON.parse(content)[0] content = JSON.parse(content)
let data = null
if (content.length > 1 && typeof handleMultiCanvas === 'function') {
data = await handleMultiCanvas(content)
}
if (!data) {
data = content[0]
}
const nodeTree = data.rootTopic const nodeTree = data.rootTopic
const newTree = {} const newTree = {}
const waitLoadImageList = [] const waitLoadImageList = []