Feat:支持在url中通过fileURL查询参数打开指定的在线文件

This commit is contained in:
wanglin2 2023-09-02 09:53:05 +08:00
parent 32c17921ca
commit 075e578bb4
2 changed files with 56 additions and 0 deletions

View File

@ -74,6 +74,7 @@ import OutlineEdit from './OutlineEdit.vue'
import { showLoading, hideLoading } from '@/utils/loading'
import handleClipboardText from '@/utils/handleClipboardText'
import Scrollbar from './Scrollbar.vue'
import exampleData from 'simple-mind-map/example/exampleData'
//
MindMap.usePlugin(MiniMap)
@ -261,7 +262,20 @@ export default {
* @Desc: 初始化
*/
init() {
let hasFileURL = this.hasFileURL()
let { root, layout, theme, view, config } = this.mindMapData
// url使
if (hasFileURL) {
root = {
"data": {
"text": "根节点"
},
"children": []
}
layout = exampleData.layout
theme = exampleData.theme
view = null
}
this.mindMap = new MindMap({
el: this.$refs.mindMapContainer,
data: root,
@ -376,6 +390,17 @@ export default {
if (window.takeOverApp) {
this.$bus.$emit('app_inited', this.mindMap)
}
// url
if (hasFileURL) {
this.$bus.$emit('handle_file_url')
}
},
// url
hasFileURL() {
const fileURL = this.$route.query.fileURL
if (!fileURL) return false
return /\.(smm|json|xmind|md|xlsx)$/.test(fileURL)
},
/**

View File

@ -59,15 +59,46 @@ export default {
},
created() {
this.$bus.$on('showImport', this.handleShowImport)
this.$bus.$on('handle_file_url', this.handleFileURL)
},
beforeDestroy() {
this.$bus.$off('showImport', this.handleShowImport)
this.$bus.$off('handle_file_url', this.handleFileURL)
},
methods: {
handleShowImport() {
this.dialogVisible = true
},
// url
async handleFileURL() {
try {
const fileURL = this.$route.query.fileURL
if (!fileURL) return
const macth = /\.(smm|json|xmind|md|xlsx)$/.exec(fileURL)
if (!macth) {
return
}
const type = macth[1]
const res = await fetch(fileURL)
const file = await res.blob()
const data = {
raw: file
}
if (type === 'smm' || type === 'json') {
this.handleSmm(data)
} else if (type === 'xmind') {
this.handleXmind(data)
} else if (type === 'xlsx') {
this.handleExcel(data)
} else if (type === 'md') {
this.handleMd(data)
}
} catch (error) {
console.log(error)
}
},
/**
* @Author: 王林
* @Date: 2021-08-03 22:48:42