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',
fileContentError: 'The file content is incorrect',
importSuccess: 'Import success',
fileParsingFailed: 'File parsing failed'
fileParsingFailed: 'File parsing failed',
xmindCanvasSelectDialogTitle: 'Select the canvas to import'
},
navigatorToolbar: {
openMiniMap: 'Open mini map',

View File

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

View File

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