mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 10:27:44 +08:00
Demo:支持导入和导出FreeMind文件
This commit is contained in:
parent
bd0fc37f03
commit
c8d5a34640
@ -495,6 +495,12 @@ export const downTypeList = [
|
||||
type: 'txt',
|
||||
icon: 'iconTXT',
|
||||
desc: 'Plain text file'
|
||||
},
|
||||
{
|
||||
name: 'FreeMind',
|
||||
type: 'mm',
|
||||
icon: 'iconTXT',
|
||||
desc: 'FreeMind software format'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@ -589,6 +589,12 @@ export const downTypeList = [
|
||||
type: 'txt',
|
||||
icon: 'iconTXT',
|
||||
desc: '纯文本文件'
|
||||
},
|
||||
{
|
||||
name: 'FreeMind',
|
||||
type: 'mm',
|
||||
icon: 'iconTXT',
|
||||
desc: 'FreeMind软件格式'
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
@ -157,8 +157,8 @@ export default {
|
||||
import: {
|
||||
title: 'Import',
|
||||
selectFile: 'Select file',
|
||||
supportFile: 'Support .smm、.json、.xmind、.xlsx、.md file',
|
||||
enableFileTip: 'Please select .smm、.json、.xmind、.xlsx、.md file',
|
||||
supportFile: 'Support .smm、.json、.xmind、.xlsx、.md、 .mm file',
|
||||
enableFileTip: 'Please select .smm、.json、.xmind、.xlsx、.md、 .mm file',
|
||||
maxFileNum: 'At most one file can be selected',
|
||||
notSelectTip: 'Please select the file to import',
|
||||
fileContentError: 'The file content is incorrect',
|
||||
|
||||
@ -155,8 +155,8 @@ export default {
|
||||
import: {
|
||||
title: '导入',
|
||||
selectFile: '选取文件',
|
||||
supportFile: '支持.smm、.json、.xmind、.xlsx、.md文件',
|
||||
enableFileTip: '请选择.smm、.json、.xmind、.xlsx、.md文件',
|
||||
supportFile: '支持.smm、.json、.xmind、.xlsx、.md、 .mm文件',
|
||||
enableFileTip: '请选择.smm、.json、.xmind、.xlsx、.md、 .mm文件',
|
||||
maxFileNum: '最多只能选择一个文件',
|
||||
notSelectTip: '请选择要导入的文件',
|
||||
fileContentError: '文件内容有误',
|
||||
|
||||
@ -79,6 +79,8 @@ import OuterFrame from 'simple-mind-map/src/plugins/OuterFrame.js'
|
||||
// import Notation from 'simple-mind-map-plugin-notation'
|
||||
// 编号插件,该插件为付费插件,详情请查看开发文档
|
||||
// import Numbers from 'simple-mind-map-plugin-numbers'
|
||||
// Freemind软件格式导入导出插件,该插件为付费插件,详情请查看开发文档
|
||||
import Freemind from 'simple-mind-map-plugin-freemind'
|
||||
import OutlineSidebar from './OutlineSidebar'
|
||||
import Style from './Style'
|
||||
import BaseStyle from './BaseStyle'
|
||||
@ -135,6 +137,7 @@ MindMap.usePlugin(MiniMap)
|
||||
.usePlugin(RainbowLines)
|
||||
.usePlugin(Demonstrate)
|
||||
.usePlugin(OuterFrame)
|
||||
.usePlugin(Freemind)
|
||||
// .usePlugin(Cooperate) // 协同插件
|
||||
|
||||
// 注册自定义主题
|
||||
|
||||
@ -8,7 +8,7 @@
|
||||
element-loading-spinner="el-icon-loading"
|
||||
element-loading-background="rgba(0, 0, 0, 0.8)"
|
||||
:width="isMobile ? '90%' : '50%'"
|
||||
:top="isMobile? '20px' : '15vh'"
|
||||
:top="isMobile ? '20px' : '15vh'"
|
||||
>
|
||||
<div class="exportContainer" :class="{ isDark: isDark }">
|
||||
<div class="nameInputBox">
|
||||
@ -98,12 +98,14 @@
|
||||
import { mapState, mapMutations } from 'vuex'
|
||||
import { downTypeList } from '@/config'
|
||||
import { isMobile } from 'simple-mind-map/src/utils/index'
|
||||
import MarkdownIt from 'markdown-it'
|
||||
|
||||
/**
|
||||
* @Author: 王林
|
||||
* @Date: 2021-06-24 22:53:54
|
||||
* @Desc: 导出
|
||||
*/
|
||||
let md = null
|
||||
export default {
|
||||
name: 'Export',
|
||||
data() {
|
||||
@ -203,6 +205,22 @@ export default {
|
||||
this.fileName,
|
||||
this.isTransparent
|
||||
)
|
||||
} else if (this.exportType === 'mm') {
|
||||
this.$bus.$emit('export', this.exportType, true, this.fileName, {
|
||||
transformNote: note => {
|
||||
if (!md) {
|
||||
md = new MarkdownIt()
|
||||
}
|
||||
return md.render(note)
|
||||
},
|
||||
transformImage: img => {
|
||||
if (/^https?:\/\//.test(img)) {
|
||||
return img
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.$bus.$emit('export', this.exportType, true, this.fileName)
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
<el-upload
|
||||
ref="upload"
|
||||
action="x"
|
||||
accept=".smm,.json,.xmind,.xlsx,.md"
|
||||
accept=".smm,.json,.xmind,.xlsx,.md,.mm"
|
||||
:file-list="fileList"
|
||||
:auto-upload="false"
|
||||
:multiple="false"
|
||||
@ -40,9 +40,12 @@
|
||||
:show-close="false"
|
||||
>
|
||||
<el-radio-group v-model="selectCanvas" class="canvasList">
|
||||
<el-radio v-for="(item, index) in canvasList" :key="index" :label="index">{{
|
||||
item.title
|
||||
}}</el-radio>
|
||||
<el-radio
|
||||
v-for="(item, index) in canvasList"
|
||||
:key="index"
|
||||
:label="index"
|
||||
>{{ item.title }}</el-radio
|
||||
>
|
||||
</el-radio-group>
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button type="primary" @click="confirmSelect">{{
|
||||
@ -56,6 +59,7 @@
|
||||
<script>
|
||||
import xmind from 'simple-mind-map/src/parse/xmind.js'
|
||||
import markdown from 'simple-mind-map/src/parse/markdown.js'
|
||||
import { freemindToSmm } from 'simple-mind-map-plugin-freemind/freemindTo.js'
|
||||
import { fileToBuffer } from '@/utils'
|
||||
import { read, utils } from 'xlsx'
|
||||
import { mapMutations } from 'vuex'
|
||||
@ -106,7 +110,7 @@ export default {
|
||||
try {
|
||||
const fileURL = this.$route.query.fileURL
|
||||
if (!fileURL) return
|
||||
const macth = /\.(smm|json|xmind|md|xlsx)$/.exec(fileURL)
|
||||
const macth = /\.(smm|json|xmind|md|xlsx|mm)$/.exec(fileURL)
|
||||
if (!macth) {
|
||||
return
|
||||
}
|
||||
@ -124,6 +128,8 @@ export default {
|
||||
this.handleExcel(data)
|
||||
} else if (type === 'md') {
|
||||
this.handleMd(data)
|
||||
} else if (type === 'mm') {
|
||||
this.handleMm(data)
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
@ -132,7 +138,7 @@ export default {
|
||||
|
||||
// 文件选择
|
||||
onChange(file) {
|
||||
let reg = /\.(smm|xmind|json|xlsx|md)$/
|
||||
let reg = /\.(smm|xmind|json|xlsx|md|mm)$/
|
||||
if (!reg.test(file.name)) {
|
||||
this.$message.error(this.$t('import.enableFileTip'))
|
||||
this.fileList = []
|
||||
@ -171,6 +177,8 @@ export default {
|
||||
this.handleExcel(file)
|
||||
} else if (/\.md$/.test(file.name)) {
|
||||
this.handleMd(file)
|
||||
} else if (/\.mm$/.test(file.name)) {
|
||||
this.handleMm(file)
|
||||
}
|
||||
this.cancel()
|
||||
this.setActiveSidebar(null)
|
||||
@ -212,6 +220,33 @@ export default {
|
||||
}
|
||||
},
|
||||
|
||||
// 处理Freemind格式
|
||||
handleMm(file) {
|
||||
const fileReader = new FileReader()
|
||||
fileReader.readAsText(file.raw)
|
||||
fileReader.onload = async evt => {
|
||||
try {
|
||||
const data = await freemindToSmm(evt.target.result, {
|
||||
// withStyle: true,
|
||||
transformImg: image => {
|
||||
return new Promise(resolve => {
|
||||
if (/^https?:\/\//.test(image)) {
|
||||
resolve({ url: image })
|
||||
} else {
|
||||
resolve(null)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
this.$bus.$emit('setData', data)
|
||||
this.$message.success(this.$t('import.importSuccess'))
|
||||
} catch (error) {
|
||||
console.log(error)
|
||||
this.$message.error(this.$t('import.fileParsingFailed'))
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
// 显示xmind文件的多个画布选择弹窗
|
||||
showSelectXmindCanvasDialog(content) {
|
||||
this.canvasList = content
|
||||
@ -296,7 +331,7 @@ export default {
|
||||
fileReader.readAsText(file.raw)
|
||||
fileReader.onload = async evt => {
|
||||
try {
|
||||
let data = await markdown.transformMarkdownTo(evt.target.result)
|
||||
let data = markdown.transformMarkdownTo(evt.target.result)
|
||||
this.$bus.$emit('setData', data)
|
||||
this.$message.success(this.$t('import.importSuccess'))
|
||||
} catch (error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user