vue 动态生成拓扑图的示例


Posted in Vue.js onJanuary 03, 2021

横向拓扑

在 index.html 文件中引入文件。

<link href="https://magicbox.bk.tencent.com/static_api/v3/assets/bootstrap-3.3.4/css/bootstrap.min.css" rel="external nofollow" rel="stylesheet">
 <link href="https://magicbox.bk.tencent.com/static_api/v3/assets/bkTopology-1.1/css/bkTopology.css" rel="external nofollow" rel="stylesheet">
 <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/js/jquery-1.10.2.min.js"></script>
 <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/bootstrap-3.3.4/js/bootstrap.min.js"></script>
 <script src="https://magicbox.bk.tencent.com/static_api/v3/assets/bkTopology-1.2/js/bkTopology.js"></script>

在需要绘制拓扑图的组件进行编程。

<template>
 <div>
  <span>S型拓扑图</span>
  <div class="bktopo-container">
   <div class="bktopo_demo" id="bktopo_demo2">
    <div class="none node" id="node-templates" data-container="body" data-placement="top" data-html="true"
     data-trigger="hover">
     <div class="node-container"><span class="node-text"></span></div>
    </div>
    <div class="bktopo_box" style="height:350px;"></div>
   </div>
  </div>
 </div>
</template>
<script>
 export default {
  data() {
   return {
    data: {
     "nodes": [
      { "id": "root", "x": 10, "y": 152, "height": 50, "width": 120, "text": "卡机健康度", "className": "info" },
      { "id": "child1", "x": 200, "y": 30, "height": 50, "width": 120, "text": "进程CPU监控", "className": "info" },
      { "id": "child2", "x": 200, "y": 90, "height": 50, "width": 120, "text": "网管网络故障监控", "className": "info" },
      { "id": "child3", "x": 200, "y": 150, "height": 50, "width": 120, "text": "进程内在泄露监控", "className": "info" },
      { "id": "child4", "x": 200, "y": 210, "height": 50, "width": 120, "text": "进程存活监控", "className": "info" },
      { "id": "child5", "x": 200, "y": 270, "height": 50, "width": 120, "text": "用户内在使用监控", "className": "info" },
      { "id": "child1_1", "x": 380, "y": 30, "height": 50, "width": 120, "text": "监控正常无触发自愈", "className": "success" },
      { "id": "child2_1", "x": 380, "y": 90, "height": 50, "width": 120, "text": "监控正常无触发自愈", "className": "success" },
      { "id": "child3_1", "x": 380, "y": 150, "height": 50, "width": 120, "text": "发现异常触发自愈", "className": "danger" },
      { "id": "child3_2", "x": 560, "y": 150, "height": 50, "width": 120, "text": "重启进程正常", "className": "success" },
      { "id": "child4_1", "x": 380, "y": 210, "height": 50, "width": 120, "text": "发现异常触发自愈", "className": "danger" },
      { "id": "child4_2", "x": 560, "y": 210, "height": 50, "width": 120, "text": "重启进程正常", "className": "success" },
      { "id": "child5_1", "x": 380, "y": 270, "height": 50, "width": 120, "text": "发现异常触发自愈", "className": "success" },
     ],
     "edges": [
      { "source": "root", "sDirection": 'right', "target": "child1", "tDirection": 'left', "edgesType": "info" },
      { "source": "root", "sDirection": 'right', "target": "child2", "tDirection": 'left', "edgesType": "info" },
      { "source": "root", "sDirection": 'right', "target": "child3", "tDirection": 'left', "edgesType": "info" },
      { "source": "root", "sDirection": 'right', "target": "child4", "tDirection": 'left', "edgesType": "info" },
      { "source": "root", "sDirection": 'right', "target": "child5", "tDirection": 'left', "edgesType": "info" },
      { "source": "child1", "sDirection": 'right', "target": "child1_1", "tDirection": 'left', "edgesType": "success" },
      { "source": "child2", "sDirection": 'right', "target": "child2_1", "tDirection": 'left', "edgesType": "success" },
      { "source": "child3", "sDirection": 'right', "target": "child3_1", "tDirection": 'left', "edgesType": "danger" },
      { "source": "child3_1", "sDirection": 'right', "target": "child3_2", "tDirection": 'left', "edgesType": "success" },
      { "source": "child4", "sDirection": 'right', "target": "child4_1", "tDirection": 'left', "edgesType": "danger" },
      { "source": "child4_1", "sDirection": 'right', "target": "child4_2", "tDirection": 'left', "edgesType": "success" },
      { "source": "child5", "sDirection": 'right', "target": "child5_1", "tDirection": 'left', "edgesType": "success" }
     ]
    }
   }
  },
  mounted() {
   this.init()
  },
  methods: {
   init() {
    $('#bktopo_demo2 .bktopo_box').bkTopology({
     data: this.data, //配置数据源
     lineType: [ //配置线条的类型
      { type: 'success', lineColor: '#46C37B' },
      { type: 'info', lineColor: '#4A9BFF' },
      { type: 'warning', lineColor: '#f0a63a' },
      { type: 'danger', lineColor: '#c94d3c' },
      { type: 'default', lineColor: '#aaa' }
     ]
    });
   }
  },
 }
</script>
<style scoped>

</style>

S型拓扑

和上面横向一样,需要在 index.html 文件中引用 js 文件。

<template>
 <div>
  <span>横向拓扑图</span>
  <div class="bktopo-container">
   <div class="bktopo_demo" id="bktopo_demo2">
    <div class="none node" id="node-templates" data-container="body" data-placement="top" data-html="true"
     data-trigger="hover">
     <div class="node-container"><span class="node-text"></span></div>
    </div>
    <div class="bktopo_box" style="height:350px;"></div>
   </div>
  </div>
 </div>
</template>
<script>
 export default {
  data() {
   return {
    data: {
     "nodes": [
      {
       "id": "demo3_node1", "x": 100, "y": 50, "height": 50,
       "width": 100, "text": "发起", "className": "node success"
      },
      {
       "id": "demo3_node2", "x": 250, "y": 50, "height": 50,
       "width": 100, "text": "过程1", "className": "node success"
      },
      {
       "id": "demo3_node3", "x": 400, "y": 50, "height": 50,
       "width": 100, "text": "过程2", "className": "node danger"
      },
      {
       "id": "demo3_node4", "x": 550, "y": 50, "height": 50,
       "width": 100, "text": "过程3", "className": "node success"
      },
      {
       "id": "demo3_node5", "x": 550, "y": 150, "height": 50,
       "width": 100, "text": "过程4", "className": "node success"
      },
      {
       "id": "demo3_node6", "x": 400, "y": 150, "height": 50,
       "width": 100, "text": "过程5", "className": "node warning"
      },
      {
       "id": "demo3_node7", "x": 250, "y": 150, "height": 50,
       "width": 100, "text": "过程6", "className": "node success"
      },
      {
       "id": "demo3_node8", "x": 100, "y": 150, "height": 50,
       "width": 100, "text": "过程7", "className": "node success"
      },
     ],
     "edges": [
      {
       "source": "demo3_node1", "sDirection": 'right',
       "target": "demo3_node2", "tDirection": 'left', "edgesType": "success"
      },
      {
       "source": "demo3_node2", "sDirection": 'right',
       "target": "demo3_node3", "tDirection": 'left', "edgesType": "danger"
      },
      {
       "source": "demo3_node3", "sDirection": 'right',
       "target": "demo3_node4", "tDirection": 'left', "edgesType": "success"
      },
      {
       "source": "demo3_node4", "sDirection": 'right',
       "target": "demo3_node5", "tDirection": 'right', "edgesType": "success"
      },
      {
       "source": "demo3_node5", "sDirection": 'right',
       "target": "demo3_node6", "tDirection": 'right', "edgesType": "warning"
      },
      {
       "source": "demo3_node6", "sDirection": 'right',
       "target": "demo3_node7", "tDirection": 'right', "edgesType": "success"
      },
      {
       "source": "demo3_node7", "sDirection": 'right',
       "target": "demo3_node8", "tDirection": 'right', "edgesType": "success"
      },
     ]
    }
   }
  },
  mounted() {
   this.init()
  },
  methods: {
   init() {
    $('#bktopo_demo2 .bktopo_box').bkTopology({
     data: this.data, //配置数据源
     lineType: [ //配置线条的类型
      { type: 'success', lineColor: '#46C37B' },
      { type: 'info', lineColor: '#4A9BFF' },
      { type: 'warning', lineColor: '#f0a63a' },
      { type: 'danger', lineColor: '#c94d3c' },
      { type: 'default', lineColor: '#aaa' }
     ]
    });
   }
  },
 }
</script>
<style scoped>

</style>

纵向拓扑

和上面横向一样,需要在 index.html 文件中引用 js 文件。

<template>
 <div>
  <span>纵向拓扑图</span>
  <div class="bktopo-container">
   <div class="bktopo_demo" id="bktopo_demo2">
    <div class="none node" id="node-templates" data-container="body" data-placement="top" data-html="true"
     data-trigger="hover">
     <div class="node-container"><span class="node-text"></span></div>
    </div>
    <div class="bktopo_box" style="height:350px;"></div>
   </div>
  </div>
 </div>
</template>
<script>
 export default {
  data() {
   return {
    data: {
     "nodes": [
      {
       "id": "node1", "x": 361, "y": 20, "height": 50, "width": 180,
       "text": "浏览器发起'www.qq.com'请求", "className": "node success"
      },
      {
       "id": "node2",
       "x": 391, "y": 100, "height": 50, "width": 120, "text": "本地hosts文件解析",
       "className": "node success"
      },
      {
       "id": "node3", "x": 301, "y": 200, "height": 50, "width": 100, "text": "客户接入联通网", "className": "node"
      },
      {
       "id": "node4", "x": 400, "y": 200, "height": 50, "width": 100, "text": "客户接入移动网", "className": "node"
      },
      {
       "id": "node5", "x": 499, "y": 200, "height": 50, "width": 100, "text": "客户接入电信网",
       "className": "node success", "title": "如果hosts匹配成功则不经过DNS服务器解析。直接使用IP访问"
      },
      {
       "id": "node6", "x": 233, "y": 300, "height": 50, "width": 140, "text": "联通DNS服务器", "className": "node"
      },
      {
       "id": "node7", "x": 372, "y": 300, "height": 50, "width": 140, "text": "移动DNS服务器", "className": "node"
      },
      {
       "id": "node8", "x": 511, "y": 300, "height": 50, "width": 140, "text": "电信DNS服务器",
       "className": "node success"
      },
      {
       "id": "node9", "x": 233, "y": 400, "height": 50, "width": 370,
       "text": "核心骨干交换网集群", "className": "node success"
      },
      {
       "id": "node19", "x": 343, "y": 500, "height": 50, "width": 150,
       "text": "WEb服务器", "className": "node success"
      },
     ],
     "edges": [
      { "source": "node1", "sDirection": 'bottom', "target": "node2", "tDirection": 'top', "edgesType": "success" },
      { "source": "node2", "sDirection": 'bottom', "target": "node5", "tDirection": 'top', "edgesType": "success" },
      { "source": "node3", "sDirection": 'bottom', "target": "node6", "tDirection": 'top', "edgesType": "danger" },
      { "source": "node6", "sDirection": 'bottom', "target": "node9", "tDirection": 'left', "edgesType": "danger" },
      { "source": "node4", "sDirection": 'bottom', "target": "node7", "tDirection": 'top', "edgesType": "danger" },
      { "source": "node5", "sDirection": 'bottom', "target": "node8", "tDirection": 'top', "edgesType": "success" },
      { "source": "node7", "sDirection": 'bottom', "target": "node9", "tDirection": 'top', "edgesType": "danger" },
      { "source": "node8", "sDirection": 'bottom', "target": "node9", "tDirection": 'right', "edgesType": "danger" },
      { "source": "node9", "sDirection": 'bottom', "target": "node19", "tDirection": 'top', "edgesType": "success" }
     ]
    }
   }
  },
  mounted() {
   this.init()
  },
  methods: {
   init() {
    $('#bktopo_demo2 .bktopo_box').bkTopology({
     data: this.data, //配置数据源
     lineType: [ //配置线条的类型
      { type: 'success', lineColor: '#46C37B' },
      { type: 'info', lineColor: '#4A9BFF' },
      { type: 'warning', lineColor: '#f0a63a' },
      { type: 'danger', lineColor: '#c94d3c' },
      { type: 'default', lineColor: '#aaa' }
     ]
    });
   }
  },
 }
</script>
<style scoped>

</style>

vue 动态生成拓扑图的示例

以上就是vue 动态生成拓扑图的示例的详细内容,更多关于vue 生成拓扑图的资料请关注三水点靠木其它相关文章!

Vue.js 相关文章推荐
vue 插槽简介及使用示例
Nov 19 Vue.js
vue3.0中setup使用(两种用法)
Dec 02 Vue.js
Vue如何跨组件传递Slot的实现
Dec 14 Vue.js
vue 使用class创建和清除水印的示例代码
Dec 25 Vue.js
Vue实现todo应用的示例
Feb 20 Vue.js
详解Vue3.0 + TypeScript + Vite初体验
Feb 22 Vue.js
Vue基本指令实例图文讲解
Feb 25 Vue.js
vue 数据双向绑定的实现方法
Mar 04 Vue.js
vue实现同时设置多个倒计时
May 20 Vue.js
Vue中使用import进行路由懒加载的原理分析
Apr 01 Vue.js
vue生命周期钩子函数以及触发时机
Apr 26 Vue.js
vue css 相对路径导入问题级踩坑记录
Jun 05 Vue.js
Vue中强制组件重新渲染的正确方法
Jan 03 #Vue.js
vue中activated的用法
Jan 03 #Vue.js
vue实现登录功能
Dec 31 #Vue.js
vue 实现图片懒加载功能
Dec 31 #Vue.js
vue 动态创建组件的两种方法
Dec 31 #Vue.js
Vue 修改网站图标的方法
Dec 31 #Vue.js
Vue中inheritAttrs的使用实例详解
Dec 31 #Vue.js
You might like
Yii2针对游客、用户防范规则和限制的解决方法分析
2016/10/08 PHP
php之可变函数的实例详解
2017/09/13 PHP
PHP unlink与rmdir删除目录及目录下所有文件实例代码
2018/02/07 PHP
php定期拉取数据对比方法实例
2019/09/22 PHP
基于jquery的滚动鼠标放大缩小图片效果
2011/10/27 Javascript
jquery遍历筛选数组的几种方法和遍历解析json对象
2013/12/13 Javascript
javascript数组快速打乱重排的方法
2014/01/02 Javascript
js关于字符长度限制的问题示例探讨
2014/01/24 Javascript
js不能获取隐藏的div的宽度只能先显示后获取
2014/09/04 Javascript
javascript异步编程代码书写规范Promise学习笔记
2015/02/11 Javascript
Bootstrap4一次重大更新 几乎涉及每行代码
2016/05/16 Javascript
动态设置form表单的action属性的值的简单方法
2016/05/25 Javascript
AngularJs表单验证实例详解
2016/05/30 Javascript
vue mint-ui tabbar变组件使用
2018/05/04 Javascript
vue解决一个方法同时发送多个请求的问题
2018/09/25 Javascript
[43:35]EG vs Winstrike 2018国际邀请赛小组赛BO2 第一场 8.18
2018/08/19 DOTA
老生常谈python函数参数的区别(必看篇)
2017/05/29 Python
基于Python批量生成指定尺寸缩略图代码实例
2019/11/20 Python
Python3.7黑帽编程之病毒篇(基础篇)
2020/02/04 Python
运行tensorflow python程序,限制对GPU和CPU的占用操作
2020/02/06 Python
From CSV to SQLite3 by python 导入csv到sqlite实例
2020/02/14 Python
Python使用Selenium实现淘宝抢单的流程分析
2020/06/23 Python
阿玛尼美国官方网站:Armani.com
2016/11/25 全球购物
美国班级戒指、帽子和礼服、毕业产品、年鉴:Balfour
2018/11/01 全球购物
Java里面如何创建一个内部类的实例
2015/01/19 面试题
成人高等教育毕业生自我鉴定
2013/10/22 职场文书
司机检讨书
2014/02/13 职场文书
学校党员对照检查材料
2014/08/28 职场文书
反对四风自我剖析材料
2014/10/07 职场文书
员工辞退通知书
2015/04/17 职场文书
团组织关系介绍信
2019/06/24 职场文书
Redis分布式锁Redlock的实现
2021/08/07 Redis
css 边框添加四个角的实现代码
2021/10/16 HTML / CSS
pt-archiver 主键自增
2022/04/26 MySQL
instantclient客户端 连接oracle数据库
2022/04/26 Oracle
java版 简单三子棋游戏
2022/05/04 Java/Android