Vue中實現(xiàn)在線畫流程圖的方法
概述
最近在調(diào)研一些在線文檔的實現(xiàn),包括文檔編輯器、在線思維導圖、在線流程圖等,前面的文章基于語雀編輯器的在線文檔編輯與查看實現(xiàn)了文檔編輯器。在本文,分享在Vue框架下基于metaeditor-mxgraph實現(xiàn)在線流程圖。
實現(xiàn)效果

實現(xiàn)
1. 添加依賴
{
"metaeditor-mxgraph": "^2.0.7"
}2. 編輯器簡介
metaeditor-mxgraph,圖元編輯器,支持獨立的流程圖編輯器,以及 DrawIO 嵌入方案。文檔地址為:https://npm.io/package/metaeditor-mxgraph。
3. 編輯器實現(xiàn)
<template>
<div class="flow-chart" ref="flowChart"></div>
</template>
<script>
import 'metaeditor-mxgraph/assets/index.scss'
import { MetaEditor } from 'metaeditor-mxgraph'
const { MetaGraphEditor, getLanguage, stringToXml, xmlToString } = MetaEditor
export default {
props: {
chartData: {
type: Object,
default: () => null,
},
},
mounted() {
this.$nextTick(() => {
this.init()
})
},
watch: {
chartData() {
this.init()
},
},
unmounted() {
this.destroy()
},
methods: {
destroy() {
if (window.metaGraphEditor) window.metaGraphEditor.destroy()
window.metaGraphEditor = null
},
init() {
this.destroy()
const xml = stringToXml(this.chartData || '<mxGraphModel></mxGraphModel>')
const dom = this.$refs.flowChart
const metaGraphEditor = new MetaGraphEditor({
container: dom,
})
const lan = getLanguage('zh')
metaGraphEditor.init(lan, xml)
window.metaGraphEditor = metaGraphEditor
},
},
}
</script>
<style scoped lang="scss">
.flow-chart {
width: 100%;
height: 100%;
}
</style>需要注意的是,編輯器默認是絕對定位的,想要跟隨設(shè)定dom大小,需要設(shè)置其樣式為:
.metagraph-container {
position: relative;
width: 100%;
height: 100%;
user-select: none;
}設(shè)置完樣式后,菜單的位置會出錯,這個還沒修復,使用時請注意。
4. 文檔預覽
<template>
<div class="flow-chart" ref="flowChart"></div>
</template>
<script>
import 'metaeditor-mxgraph/assets/index.scss'
import { MetaEditor } from 'metaeditor-mxgraph'
const { MetaGraphViewer, stringToXml} = MetaEditor
export default {
props: {
chartData: {
type: Object,
default: () => null,
},
},
mounted() {
this.$nextTick(() => {
this.init()
})
},
watch: {
chartData() {
this.init()
},
},
methods: {
init() {
const xml = stringToXml(this.chartData || '<mxGraphModel></mxGraphModel>')
const dom = this.$refs.flowChart
const metaGraphEditor = new MetaGraphViewer({
xml: xml,
})
const { offsetWidth, offsetHeight } = dom
const svg = metaGraphEditor.renderSVGDom(null, 1, 1, {
width: offsetWidth,
height: offsetHeight,
})
dom.appendChild(svg)
},
},
}
</script>
<style scoped lang="scss">
.flow-chart {
width: 100%;
height: 100%;
}
</style>到此這篇關(guān)于Vue中實現(xiàn)在線畫流程圖實現(xiàn)的文章就介紹到這了,更多相關(guān)Vue畫流程圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中使用vue-router切換頁面時滾動條自動滾動到頂部的方法
這篇文章主要介紹了vue項目中在使用vue-router切換頁面的時候滾動條自動滾動到頂部的實現(xiàn)方法,一般使用Window scrollTo() 方法實現(xiàn),本文給大家簡單介紹了crollTop的使用,需要的朋友可以參考下2017-11-11
Vue Router4與Router3路由配置與區(qū)別說明
這篇文章主要介紹了Vue Router4與Router3路由配置與區(qū)別說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-12-12
vue實現(xiàn)錄音并轉(zhuǎn)文字功能包括PC端web手機端web(實現(xiàn)過程)
vue實現(xiàn)錄音并轉(zhuǎn)文字功能,包括PC端,手機端和企業(yè)微信自建應用端,本文通過實例代碼介紹vue實現(xiàn)錄音并轉(zhuǎn)文字功能包括PC端web手機端web,感興趣的朋友跟隨小編一起看看吧2024-08-08
Vue.js如何利用v-for循環(huán)生成動態(tài)標簽
這篇文章主要給大家介紹了關(guān)于Vue.js如何利用v-for循環(huán)生成動態(tài)標簽的相關(guān)資料,文中通過實例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2022-01-01

