当前位置: 移动技术网 > IT编程>脚本编程>vue.js > vue 动态生成拓扑图的示例

vue 动态生成拓扑图的示例

2021年01月03日 vue.js 我要评论
横向拓扑在 文件中引入文件。 <link href="https://magicbox.bk.tencent.com/static_api/v3/assets/bootst

横向拓扑

在 文件中引入文件。

 <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型拓扑

和上面横向一样,需要在 文件中引用 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>

纵向拓扑

和上面横向一样,需要在 文件中引用 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 生成拓扑图的资料请关注移动技术网其它相关文章!

(0)
打赏 微信扫一扫 微信扫一扫

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。

发表评论

验证码:
移动技术网