欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Vue中實(shí)現(xiàn)在線畫流程圖的方法

 更新時間:2024年07月12日 12:14:49   作者:牛老師講GIS  
最近在調(diào)研一些在線文檔的實(shí)現(xiàn),包括文檔編輯器、在線思維導(dǎo)圖、在線流程圖等,本文分享在Vue框架下基于metaeditor-mxgraph實(shí)現(xiàn)在線流程圖,感興趣的朋友一起看看吧

概述

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

實(shí)現(xiàn)效果

image.png

實(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引入騰訊地圖全過程(搜索獲取定位)

    最近需要在項(xiàng)目中使用地圖顯示點(diǎn)位信息,所以引入了騰訊地圖,這篇文章主要給大家介紹了關(guān)于Vue引入騰訊地圖(搜索獲取定位)的相關(guān)資料,需要的朋友可以參考下
    2023-10-10
  • vue中使用vue-router切換頁面時滾動條自動滾動到頂部的方法

    vue中使用vue-router切換頁面時滾動條自動滾動到頂部的方法

    這篇文章主要介紹了vue項(xiàng)目中在使用vue-router切換頁面的時候滾動條自動滾動到頂部的實(shí)現(xiàn)方法,一般使用Window scrollTo() 方法實(shí)現(xiàn),本文給大家簡單介紹了crollTop的使用,需要的朋友可以參考下
    2017-11-11
  • Vue Router4與Router3路由配置與區(qū)別說明

    Vue Router4與Router3路由配置與區(qū)別說明

    這篇文章主要介紹了Vue Router4與Router3路由配置與區(qū)別說明,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-12-12
  • Vue3實(shí)現(xiàn)計算屬性的代碼詳解

    Vue3實(shí)現(xiàn)計算屬性的代碼詳解

    計算屬性對于前端開發(fā)來說算是經(jīng)常使用的一個能力了,本文將從代碼層面來給大家介紹下Vue3是如何實(shí)現(xiàn)計算屬性的,需要的朋友可以參考下
    2023-07-07
  • vue中實(shí)現(xiàn)代碼高亮與語法著色的方法介紹

    vue中實(shí)現(xiàn)代碼高亮與語法著色的方法介紹

    在Vue的開發(fā)過程中,我們經(jīng)常需要展示代碼片段或者進(jìn)行代碼高亮與語法著色,Vue提供了多種方式來實(shí)現(xiàn)代碼高亮與語法著色,本文將為你詳細(xì)介紹這些方法,需要的朋友可以參考下
    2023-06-06
  • vue實(shí)現(xiàn)錄音并轉(zhuǎn)文字功能包括PC端web手機(jī)端web(實(shí)現(xiàn)過程)

    vue實(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-08
  • Vue.js如何利用v-for循環(huán)生成動態(tài)標(biāo)簽

    Vue.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
  • vue跳轉(zhuǎn)后不記錄歷史記錄的問題

    vue跳轉(zhuǎn)后不記錄歷史記錄的問題

    這篇文章主要介紹了vue跳轉(zhuǎn)后不記錄歷史記錄的問題及解決,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue下使用fullcalendar案例講解

    vue下使用fullcalendar案例講解

    這篇文章主要介紹了vue下使用fullcalendar及簡單案例,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友參考下吧
    2024-01-01
  • Vue2.0 從零開始_環(huán)境搭建操作步驟

    Vue2.0 從零開始_環(huán)境搭建操作步驟

    下面小編就為大家?guī)硪黄猇ue2.0 從零開始_環(huán)境搭建操作步驟。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-06-06

最新評論