Skip to content

导入导出到 xmind 不支持概要 #402

@doyouhaobaby

Description

@doyouhaobaby

最近使用发现导入导出到xmind 概要丢失了,这个挺重要的。
尝试改了一下,支持了新版本xmind导入保留概要,导出试了一下没搞定,还在研究。

应该支持一下,JS 不太会。

gy1
gy2

xmind 的概要支持合并,这个不支持,不过可以拆分多个副本,没问题不大。
导出的时候尝试生成它的结构样式,发现提示损坏。

web/node_modules/.store/simple-mind-map@0.8.0-fix.1/node_modules/simple-mind-map/src/parse/xmind.js

//  转换xmind数据
const transformXmind = async (content, files) => {
  let data = JSON.parse(content)[0]
  console.log(data)
  let nodeTree = data.rootTopic
  let newTree = {}
  let waitLoadImageList = []
  let walk = async (node, newNode) => {
    newNode.data = {
      // 节点内容
      text: isUndef(node.title) ? '' : node.title
    }
    // 节点备注
    if (node.notes) {
      let notesData = node.notes.realHTML || node.notes.plain
      newNode.data.note = notesData ? notesData.content || '' : ''
    }
    // 超链接
    if (node.href && /^https?:\/\//.test(node.href)) {
      newNode.data.hyperlink = node.href
    }
    // 标签
    if (node.labels && node.labels.length > 0) {
      newNode.data.tag = node.labels
    }
    // 概要
    if (node.currentSummary) {
      newNode.data.generalization = {
          text: node.currentSummary.title,
          expand: true,
          isActive: false,
      }
    }

    // 图片
    if (node.image && /\.(jpg|jpeg|png|gif|webp)$/.test(node.image.src)) {
      // 处理异步逻辑
      let resolve = null
      let promise = new Promise(_resolve => {
        resolve = _resolve
      })
      waitLoadImageList.push(promise)
      try {
        // 读取图片
        let imageType = /\.([^.]+)$/.exec(node.image.src)[1]
        let imageBase64 =
          `data:image/${imageType};base64,` +
          (await files['resources/' + node.image.src.split('/')[1]].async(
            'base64'
          ))
        newNode.data.image = imageBase64
        // 如果图片尺寸不存在
        if (!node.image.width && !node.image.height) {
          let imageSize = await getImageSize(imageBase64)
          newNode.data.imageSize = {
            width: imageSize.width,
            height: imageSize.height
          }
        } else {
          newNode.data.imageSize = {
            width: node.image.width,
            height: node.image.height
          }
        }
        resolve()
      } catch (error) {
        console.log(error)
        resolve()
      }
    }
    // 子节点
    newNode.children = []
    if (
      node.children &&
      node.children.attached &&
      node.children.attached.length > 0
    ) {
      // 分析概要位置
      // xmind 支持合并概要,现在的组件不支持合并概要,分别拆分开来
      let summariesPosition = {}
      node.summaries.forEach(item => {
        // 使用正则表达式提取第二个数字,例如 (2,3)
        const match = item.range.match(/\((\d+),(\d+)\)/)
        const firstNumber = match ? parseInt(match[1], 10) : null
        const secondNumber = match ? parseInt(match[2], 10) : null
        summariesPosition[item.topicId] = []
        for (let i = firstNumber; i <= secondNumber; i++) {
          summariesPosition[item.topicId].push(i)
        }
      })

      let summariesPositionData = {}
      if (node.children.summary && node.children.summary.length > 0) {
        node.children.summary.forEach(summary => {
          if (Object.prototype.hasOwnProperty.call(summariesPosition, summary.id)) {
            summariesPosition[summary.id].forEach (index => {
              summariesPositionData[index] = summary
            })
          }
        })
      }

      node.children.attached.forEach((item, index) => {
        let currentSummary = null
        if (Object.prototype.hasOwnProperty.call(summariesPositionData, index)) {
          currentSummary = summariesPositionData[index]
        }

        let newChild = {}
        newNode.children.push(newChild)
        item.currentSummary = currentSummary
        walk(item, newChild)
      })
    }
  }
  walk(nodeTree, newTree)
  await Promise.all(waitLoadImageList)
  return newTree
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions