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