mirror of
https://github.com/wanglin2/mind-map.git
synced 2026-02-21 18:37:43 +08:00
Feat:支持在url中通过fileURL查询参数打开指定的在线文件
This commit is contained in:
parent
32c17921ca
commit
075e578bb4
@ -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)
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user