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

This commit is contained in:
街角小林 2024-05-28 17:28:17 +08:00
parent f4800746a3
commit 27477e39de
3 changed files with 101 additions and 70 deletions

View File

@ -152,7 +152,8 @@ export default {
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',
importSuccess: 'Import success', importSuccess: 'Import success',
fileParsingFailed: 'File parsing failed' fileParsingFailed: 'File parsing failed',
xmindCanvasSelectDialogTitle: 'Select the canvas to import'
}, },
navigatorToolbar: { navigatorToolbar: {
openMiniMap: 'Open mini map', openMiniMap: 'Open mini map',

View File

@ -150,7 +150,8 @@ export default {
notSelectTip: '请选择要导入的文件', notSelectTip: '请选择要导入的文件',
fileContentError: '文件内容有误', fileContentError: '文件内容有误',
importSuccess: '导入成功', importSuccess: '导入成功',
fileParsingFailed: '文件解析失败' fileParsingFailed: '文件解析失败',
xmindCanvasSelectDialogTitle: '选择要导入的画布'
}, },
navigatorToolbar: { navigatorToolbar: {
openMiniMap: '开启小地图', openMiniMap: '开启小地图',

View File

@ -1,4 +1,5 @@
<template> <template>
<div>
<el-dialog <el-dialog
class="nodeImportDialog" class="nodeImportDialog"
:title="$t('import.title')" :title="$t('import.title')"
@ -31,6 +32,25 @@
}}</el-button> }}</el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog
class="xmindCanvasSelectDialog"
:title="$t('import.xmindCanvasSelectDialogTitle')"
:visible.sync="xmindCanvasSelectDialogVisible"
width="300px"
:show-close="false"
>
<el-radio-group v-model="selectCanvas" class="canvasList">
<el-radio v-for="(item, index) in canvasList" :label="index">{{
item.title
}}</el-radio>
</el-radio-group>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="confirmSelect">{{
$t('dialog.confirm')
}}</el-button>
</span>
</el-dialog>
</div>
</template> </template>
<script> <script>
@ -50,7 +70,11 @@ export default {
data() { data() {
return { return {
dialogVisible: false, dialogVisible: false,
fileList: [] fileList: [],
selectPromiseResolve: null,
xmindCanvasSelectDialogVisible: false,
selectCanvas: '',
canvasList: []
} }
}, },
watch: { watch: {
@ -106,11 +130,7 @@ export default {
} }
}, },
/** //
* @Author: 王林
* @Date: 2021-08-03 22:48:42
* @Desc: 文件选择
*/
onChange(file) { onChange(file) {
let reg = /\.(smm|xmind|json|xlsx|md)$/ let reg = /\.(smm|xmind|json|xlsx|md)$/
if (!reg.test(file.name)) { if (!reg.test(file.name)) {
@ -126,29 +146,17 @@ export default {
this.fileList = fileList this.fileList = fileList
}, },
/** //
* @Author: 王林
* @Date: 2021-08-03 22:48:47
* @Desc: 数量超出限制
*/
onExceed() { onExceed() {
this.$message.error(this.$t('import.maxFileNum')) this.$message.error(this.$t('import.maxFileNum'))
}, },
/** //
* @Author: 王林
* @Date: 2021-06-22 22:08:11
* @Desc: 取消
*/
cancel() { cancel() {
this.dialogVisible = false this.dialogVisible = false
}, },
/** //
* @Author: 王林
* @Date: 2021-06-06 22:28:20
* @Desc: 确定
*/
confirm() { confirm() {
if (this.fileList.length <= 0) { if (this.fileList.length <= 0) {
return this.$message.error(this.$t('import.notSelectTip')) return this.$message.error(this.$t('import.notSelectTip'))
@ -168,11 +176,7 @@ export default {
this.setActiveSidebar(null) this.setActiveSidebar(null)
}, },
/** // .smm
* @Author: 王林25
* @Date: 2022-10-24 14:19:33
* @Desc: 处理.smm文件
*/
handleSmm(file) { handleSmm(file) {
let fileReader = new FileReader() let fileReader = new FileReader()
fileReader.readAsText(file.raw) fileReader.readAsText(file.raw)
@ -191,14 +195,15 @@ export default {
} }
}, },
/** // .xmind
* @Author: 王林25
* @Date: 2022-10-24 14:19:41
* @Desc: 处理.xmind文件
*/
async handleXmind(file) { async handleXmind(file) {
try { try {
let data = await xmind.parseXmindFile(file.raw) let data = await xmind.parseXmindFile(file.raw, content => {
this.showSelectXmindCanvasDialog(content)
return new Promise(resolve => {
this.selectPromiseResolve = resolve
})
})
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) {
@ -207,11 +212,22 @@ export default {
} }
}, },
/** // xmind
* @Author: 王林25 showSelectXmindCanvasDialog(content) {
* @Date: 2022-10-24 14:19:51 this.canvasList = content
* @Desc: 处理.xlsx文件 this.selectCanvas = 0
*/ this.xmindCanvasSelectDialogVisible = true
},
//
confirmSelect() {
this.selectPromiseResolve(this.canvasList[this.selectCanvas])
this.xmindCanvasSelectDialogVisible = false
this.canvasList = []
this.selectCanvas = 0
},
// .xlsx
async handleExcel(file) { async handleExcel(file) {
try { try {
const wb = read(await fileToBuffer(file.raw)) const wb = read(await fileToBuffer(file.raw))
@ -306,4 +322,17 @@ export default {
<style lang="less" scoped> <style lang="less" scoped>
.nodeImportDialog { .nodeImportDialog {
} }
.canvasList {
display: flex;
flex-direction: column;
/deep/ .el-radio {
margin-bottom: 12px;
&:last-of-type {
margin-bottom: 0;
}
}
}
</style> </style>