项目作者: liuln0221

项目描述 :
基于mxGraph的拓扑图
高级语言: JavaScript
项目地址: git://github.com/liuln0221/topology.git
创建时间: 2019-10-11T02:56:08Z
项目社区:https://github.com/liuln0221/topology

开源协议:

下载


topology-graph

  1. 基于mxGraph的拓扑图,目前只有展示功能,编辑功能后续会更新。

Project setup

  1. yarn install
  2. npm install

Compiles and hot-reloads for development

  1. yarn run serve
  2. npm run serve

Compiles and minifies for production

  1. yarn run build
  2. npm run build

使用

  1. npm install topology-graph

示例

效果图

image

代码

1.引入(main.js)
  1. import Vue from 'vue';
  2. import TopologyGraph from 'topology-graph'; // 整体引入包
  3. import 'topology-graph/dist/topology-graph.css'; // 引入组件样式
  4. import App from './App.vue';
  5. Vue.use(TopologyGraph);
  6. new Vue({
  7. el: '#app',
  8. render: h => h(App)
  9. });

2.使用(example.vue)

  1. <template>
  2. <div class="example">
  3. <topology-graph
  4. :data="data"
  5. :connect-line="connectLines"
  6. node-key="instId"
  7. :props="defaultProps"
  8. @node-click="topologyClick"></topology-graph>
  9. </div>
  10. </template>
  11. <script>
  12. const nodeDetailConfig = {
  13. title: '设备信息',
  14. config: [
  15. { label: '序列号', value: 'sn' },
  16. { label: '名称', value: 'name' },
  17. { label: '资产编号', value: 'identifier' },
  18. { label: '机房', value: 'roomName' },
  19. { label: '机柜', value: 'cabinetName' },
  20. { label: '容占', value: 'startU' },
  21. { label: '设备类型', value: 'classify' }
  22. ]
  23. };
  24. const nodeChildDetailConfig = {
  25. title: '端口信息',
  26. config: [
  27. { label: '端口名称', value: 'name' },
  28. { label: '端口带宽', value: 'bandWidth' },
  29. { label: '端口类型', value: 'type' },
  30. { label: 'MAC/WWN', value: 'macOrWwn' },
  31. { label: 'IP', value: 'ip' },
  32. { label: 'VLAN', value: 'vlan' }
  33. ]
  34. };
  35. export default {
  36. name: 'Example',
  37. data() {
  38. return {
  39. defaultProps: {
  40. label: 'sn',
  41. detailConfig: 'detailModal',
  42. buildInName: 'ports',
  43. buildInKey: 'id'
  44. },
  45. data: [
  46. [{
  47. instId: 2933,
  48. sn: "交换机-02",
  49. iconClass: 'icon-title-switch',
  50. ports: [{
  51. bandWidth: "万兆口",
  52. id: 3385,
  53. macOrWwn: "",
  54. name: "交换机-02/0",
  55. type: "光口",
  56. iconClass: 'icon-title-port',
  57. detailModal: {
  58. title: '端口信息111',
  59. config: [
  60. { label: '端口名称', value: 'name' },
  61. { label: '端口带宽', value: 'bandWidth' },
  62. { label: '端口类型', value: 'type' },
  63. { label: 'MAC/WWN', value: 'macOrWwn' }
  64. ]
  65. }
  66. }, {
  67. bandWidth: "万兆口",
  68. id: 3386,
  69. name: "交换机-02/1",
  70. type: "光口",
  71. iconClass: 'icon-title-port'
  72. }, {
  73. bandWidth: "万兆口",
  74. id: 3387,
  75. name: "交换机-02/2",
  76. type: "光口",
  77. iconClass: 'icon-title-port'
  78. }, {
  79. bandWidth: "万兆口",
  80. id: 3388,
  81. name: "交换机-02/3",
  82. type: "光口",
  83. iconClass: 'icon-title-port'
  84. }, {
  85. bandWidth: "万兆口",
  86. id: 3389,
  87. name: "交换机-02/4",
  88. type: "光口",
  89. iconClass: 'icon-title-port'
  90. }]
  91. }],
  92. [{
  93. instId: 2941,
  94. sn: "服务器-02",
  95. iconClass: 'icon-title-server',
  96. ports: [{
  97. bandWidth: "万兆口",
  98. id: 2936,
  99. name: "服务器-02/0",
  100. type: "光口",
  101. iconClass: 'icon-title-port'
  102. }]
  103. }, {
  104. instId: 2925,
  105. sn: "服务器-01",
  106. iconClass: 'icon-title-server',
  107. ports: [{
  108. bandWidth: "万兆口",
  109. id: 2915,
  110. name: "服务器-01/1",
  111. type: "光口",
  112. iconClass: 'icon-title-port',
  113. detailModal: nodeChildDetailConfig
  114. }, {
  115. bandWidth: "万兆口",
  116. id: 2915,
  117. name: "服务器-01/2",
  118. type: "光口",
  119. iconClass: 'icon-title-port'
  120. }, {
  121. bandWidth: "万兆口",
  122. id: 2915,
  123. name: "服务器-01/3",
  124. type: "光口",
  125. iconClass: 'icon-title-port'
  126. }, {
  127. bandWidth: "万兆口",
  128. id: 2915,
  129. name: "服务器-01/4",
  130. type: "光口",
  131. iconClass: 'icon-title-port'
  132. }]
  133. }],
  134. [{
  135. instId: 2934,
  136. name: "分布式存储-01",
  137. ports: [{
  138. bandWidth: "万兆口",
  139. id: 3116,
  140. name: "分布式存储-01/1",
  141. type: "光口",
  142. iconClass: 'icon-title-port'
  143. }],
  144. children: [{
  145. instId: 3154,
  146. ports: [],
  147. sn: "服务器-03",
  148. iconClass: 'icon-title-server'
  149. }, {
  150. instId: 3155,
  151. sn: "服务器-04",
  152. iconClass: 'icon-title-server',
  153. ports: [{
  154. bandWidth: "万兆口",
  155. id: 3115,
  156. name: "服务器-04/1",
  157. type: "光口",
  158. iconClass: 'icon-title-port'
  159. }]
  160. }, {
  161. instId: 3156,
  162. ports: [],
  163. sn: "服务器-05",
  164. iconClass: 'icon-title-server'
  165. }]
  166. }, {
  167. instId: 3467,
  168. ports: [],
  169. sn: "防火墙-01",
  170. iconClass: 'icon-title-firewall',
  171. detailModal: nodeDetailConfig
  172. }]
  173. ],
  174. connectLines: [
  175. { local: 2933, opposite: 2941 },
  176. { local: 2933, opposite: 2925 },
  177. { local: 2933, opposite: 3467 },
  178. { local: 3385, opposite: 2915 },
  179. {
  180. local: 3388,
  181. opposite: 3115,
  182. style: 'color=#c5c5c5;emphColor=#1296db;dotted=true;arrow=false'
  183. }
  184. ] // 连线
  185. }
  186. },
  187. methods: {
  188. topologyClick(node) {
  189. alert(node.instId);
  190. }
  191. }
  192. }
  193. </script>
  194. <!-- Add "scoped" attribute to limit CSS to this component only -->
  195. <style scoped>
  196. h3 {
  197. margin: 40px 0 0;
  198. }
  199. ul {
  200. list-style-type: none;
  201. padding: 0;
  202. }
  203. li {
  204. display: inline-block;
  205. margin: 0 10px;
  206. }
  207. a {
  208. color: #42b983;
  209. }
  210. </style>

帮助信息

属性

参数 说明 类型 可选值 默认值
data 展示数据 array —— ——
node-key 每个节点用来作为唯一标识的属性,整个拓扑图应该是唯一的 string —— id
node-dbclick 点击事件是否双击 boolean —— false
connect-line 连线数据配置选项,具体看下表 array ——
connect-line-style 连线样式配置选项,具体看下表,各属性之间用分号(;)连接,如:width=1;color=#c5c5c5 string —— width=1;
color=#c5c5c5;
emphColor=#1296db;
dotted=false;
arrow=true
props 配置选项,具体看下表 object —— ——
operate-button 是否展示操作按钮 boolean —— true
operate-button-position 操作按钮位置 string left
center
right
center

connect-line

参数 说明 类型 可选值 默认值
local 起点,值为节点/内置节点唯一标识 string,number —— ——
opposite 终点,值为节点/内置节点唯一标识 string,number —— ——
style 样式 string —— 同connect-line-style

connect-line-style

参数 说明 类型 可选值 默认值
width 宽度,鼠标经过连线或者连线所在节点时,连线宽度为当前值得两倍 number —— 1
color 颜色 string —— #c5c5c5
emphColor 强调颜色,鼠标经过连线或者连线所在节点时的颜色 string —— #1296db
dotted 虚线 boolean —— false
arrow 箭头 boolean —— true

props

参数 说明 类型 可选值 默认值
label 指定节点标签为节点对象的某个属性值 string —— ——
children 指定子节点为节点对象的某个属性 string —— ——
iconClass 节点/内置节点图标样式 string —— icon-title-server/icon-title-port
detailConfig 指定节点详情展示的配置,配置选项,具体看下表 object —— ——
buildInName 指定节点的内置节点为节点对象的某个属性值 string —— ——
buildInKey 指定内置节点的唯一标识的属性,整个拓扑图应该是唯一的 string —— 同节点node-key

detailConfig

参数 说明 类型 可选值 默认值
title 标题 string —— ——
config 配置,对象数组,对象为需展示的详情,如:{label: ‘’, value: ‘’}
label为详情信息名称,value为指定详情信息值为节点/内置节点对象的某个属性值
array —— ——

事件

事件名称 说明 回调参数
node-click 节点被点击时的回调 共一个参数:传递给data属性的对象中该节点所对应的对象