Vue中實(shí)現(xiàn)在線畫流程圖的方法
概述
最近在調(diào)研一些在線文檔的實(shí)現(xiàn),包括文檔編輯器、在線思維導(dǎo)圖、在線流程圖等,前面的文章基于語雀編輯器的在線文檔編輯與查看實(shí)現(xiàn)了文檔編輯器。在本文,分享在Vue框架下基于metaeditor-mxgraph
實(shí)現(xiàn)在線流程圖。
實(shí)現(xiàn)效果
實(shí)現(xiàn)
1. 添加依賴
{ "metaeditor-mxgraph": "^2.0.7" }
2. 編輯器簡介
metaeditor-mxgraph
,圖元編輯器,支持獨(dú)立的流程圖編輯器,以及 DrawIO 嵌入方案。文檔地址為:https://npm.io/package/metaeditor-mxgraph。
3. 編輯器實(shí)現(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>
需要注意的是,編輯器默認(rèn)是絕對定位的,想要跟隨設(shè)定dom大小,需要設(shè)置其樣式為:
.metagraph-container { position: relative; width: 100%; height: 100%; user-select: none; }
設(shè)置完樣式后,菜單的位置會出錯,這個還沒修復(fù),使用時請注意。
4. 文檔預(yù)覽
<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中實(shí)現(xiàn)在線畫流程圖實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)Vue畫流程圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue中使用vue-router切換頁面時滾動條自動滾動到頂部的方法
這篇文章主要介紹了vue項(xiàng)目中在使用vue-router切換頁面的時候滾動條自動滾動到頂部的實(shí)現(xiàn)方法,一般使用Window scrollTo() 方法實(shí)現(xiàn),本文給大家簡單介紹了crollTop的使用,需要的朋友可以參考下2017-11-11Vue Router4與Router3路由配置與區(qū)別說明
這篇文章主要介紹了Vue Router4與Router3路由配置與區(qū)別說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-12-12vue中實(shí)現(xiàn)代碼高亮與語法著色的方法介紹
在Vue的開發(fā)過程中,我們經(jīng)常需要展示代碼片段或者進(jìn)行代碼高亮與語法著色,Vue提供了多種方式來實(shí)現(xiàn)代碼高亮與語法著色,本文將為你詳細(xì)介紹這些方法,需要的朋友可以參考下2023-06-06vue實(shí)現(xiàn)錄音并轉(zhuǎn)文字功能包括PC端web手機(jī)端web(實(shí)現(xiàn)過程)
vue實(shí)現(xiàn)錄音并轉(zhuǎn)文字功能,包括PC端,手機(jī)端和企業(yè)微信自建應(yīng)用端,本文通過實(shí)例代碼介紹vue實(shí)現(xiàn)錄音并轉(zhuǎn)文字功能包括PC端web手機(jī)端web,感興趣的朋友跟隨小編一起看看吧2024-08-08Vue.js如何利用v-for循環(huán)生成動態(tài)標(biāo)簽
這篇文章主要給大家介紹了關(guān)于Vue.js如何利用v-for循環(huán)生成動態(tài)標(biāo)簽的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2022-01-01