Demo:支持导入和导出FreeMind文件

This commit is contained in:
街角小林 2024-09-05 09:40:41 +08:00
parent bd0fc37f03
commit c8d5a34640
7 changed files with 80 additions and 12 deletions

View File

@ -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'
}
]

View File

@ -589,6 +589,12 @@ export const downTypeList = [
type: 'txt',
icon: 'iconTXT',
desc: '纯文本文件'
},
{
name: 'FreeMind',
type: 'mm',
icon: 'iconTXT',
desc: 'FreeMind软件格式'
}
]

View File

@ -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',

View File

@ -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: '文件内容有误',

View File

@ -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) //
//

View File

@ -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)
}

View File

@ -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) {