Skip to content

Commit d64d8d9

Browse files
author
lisx10
committedJul 9, 2021
拓扑展示禁止用户操作
1 parent 3027681 commit d64d8d9

29 files changed

+66
-229
lines changed
 

‎README.md

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
## 拓扑在线编辑器
1+
## 在线拓扑编辑器
22

33
前后用了有点久的时间,都不知道怎么描述该项目了~
4-
---
4+
55
首先,如你所见,这是一个vue与mxGraph的编辑器融合的项目,我在原有功能基础上,与vue项目结合到一起。并改变了编辑器样式,扩展/改写了一些功能。
66
---
77
想要驾驭这款编辑器,你必须得分成3步
88
- 第一:学习mxGraph的基本语法和用法
99
- 第二:了解编辑器源代码的目录结构/总体思路,之后是细节
1010
- 第三:就是vue与他们如何融合在一起了
1111

12-
---
1312

1413
关于[mxGraph](https://github.com/maxGraph/maxGraph):没有中文文档,也没有很好的翻译文章,最有效的方式就是将所有案例都看一遍,案例很多,一定要看完,至少你要知道你可以做什么/大概怎么做。
1514
---
@@ -18,8 +17,8 @@
1817
关于vue+Graph结合:我空想了一天多,找不到能给我的参考的项目,有也不适合我的情况。我很想把Editor的DOM统统换成Vue的虚拟DOM,但是在看了部分Edit的代码以后我就知道这根本不可能,所以就有了现在的样子。它一定不完美,以后肯定会有人给出更完美的方案,如果没有我这个也还不错哈~
1918

2019
---
21-
好家伙功能实在太多了,我自己也扩展了JS导出XML和导出,和浏览模式
22-
Edit本身加导入导出,但是这种功能几乎都是借助了服务器,我是纯JS实现~
20+
好家伙功能实在太多了,我自己也扩展了JS导出XML和导出,和浏览模式,也屏蔽了一下用不到的功能
21+
Edit本身有导入导出,但是这种功能几乎都是借助了服务器,我是纯JS实现~
2322

2423
# vue-maxgraph-edit
2524
## Project setup

‎public/images/stencils/CSOFTX3000.png

-19 KB
Binary file not shown.

‎public/images/stencils/HLR.png

-16.6 KB
Binary file not shown.

‎public/images/stencils/MMSC.png

-28.9 KB
Binary file not shown.

‎public/images/stencils/SCP.png

-22.5 KB
Binary file not shown.

‎public/images/stencils/SIWF.png

-17 KB
Binary file not shown.

‎public/images/stencils/SMSC.png

-20.6 KB
Binary file not shown.

‎public/images/stencils/UMG8900.png

-22.8 KB
Binary file not shown.

‎public/images/stencils/business.png

13.5 KB
Loading

‎public/images/stencils/government.png

18.8 KB
Loading

‎public/images/stencils/hard_water.png

14.5 KB
Loading
19.2 KB
Loading
14.4 KB
Loading

‎public/images/stencils/nsmf.png

12.8 KB
Loading

‎public/images/stencils/oss.png

12.4 KB
Loading
13.5 KB
Loading

‎public/images/stencils/soft_water.png

17.5 KB
Loading

‎public/images/stencils/webcam.png

16 KB
Loading

‎public/resources/grapheditor.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ topLeft=左上角
295295
topRight=右上角
296296
transparent=透明
297297
turn=旋转90度
298-
uml=IP网
298+
uml=数据网
299299
underline=下划线
300300
undo=撤销
301301
ungroup=取消组合

‎src/components/GraphEdit/index.vue

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
<img src="~@/assets/add.svg" width="10" alt="" />
1010
新增
1111
</div>
12-
<!-- <div class="legendItem" @click="saveCurrentTopo = true">
12+
<div class="legendItem" @click="saveCurrentTopo = true">
1313
<img src="~@/assets/save.svg" width="10" alt="" />
14-
导出
14+
保存
1515
</div>
1616
<div class="legendItem" @click="importFile = true">
1717
<i class="el-icon-folder-opened"></i>
1818
导入
19-
</div> -->
19+
</div>
2020
<div class="legendItem" @click="openEditCellDialog">
2121
<img src="~@/assets/edit.svg" width="10" alt="" />
2222
编辑数据

‎src/components/ImportFile/index.vue

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
</template>
2222
<script>
2323
export default {
24-
name: 'ImportFile',
24+
name: 'importFile',
25+
emits: ['onDialogClose', 'onDialogConfirm'],
2526
props: {
2627
isVisible: Boolean || false,
2728
},

‎src/core/graphEdit/js/Editor.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
/**
269269
* Specifies if the canvas should be extended in all directions. Default is true.
270270
*/
271-
Editor.prototype.extendCanvas = true;
271+
Editor.prototype.extendCanvas = false;
272272

273273
/**
274274
* Specifies if the app should run in chromeless mode. Default is false.
@@ -2426,15 +2426,14 @@
24262426
if (graph.view.backgroundPageShape != null)
24272427
{
24282428
var bds = this.getBackgroundPageBounds();
2429-
24302429
x0 = 1 + bds.x;
24312430
y0 = 1 + bds.y;
24322431
}
2433-
2434-
// Computes the offset to maintain origin for grid
2432+
24352433
position = -Math.round(phase - mxUtils.mod(this.translate.x * this.scale - x0, phase)) + 'px ' +
24362434
-Math.round(phase - mxUtils.mod(this.translate.y * this.scale - y0, phase)) + 'px';
2437-
}
2435+
2436+
}
24382437

24392438
var canvas = graph.view.canvas;
24402439

@@ -2512,7 +2511,7 @@
25122511
var phase = this.gridSize * this.view.scale * this.view.gridSteps;
25132512
var position = -Math.round(phase - mxUtils.mod(this.view.translate.x * this.view.scale + dx, phase)) + 'px ' +
25142513
-Math.round(phase - mxUtils.mod(this.view.translate.y * this.view.scale + dy, phase)) + 'px';
2515-
canvas.style.backgroundPosition = position;
2514+
canvas.style.backgroundPosition = position;
25162515
}
25172516
};
25182517

@@ -2658,15 +2657,14 @@
26582657

26592658
var pw = fmt.width * ps;
26602659
var ph = fmt.height * ps;
2661-
2660+
26622661
var x0 = Math.floor(Math.min(0, x) / pw);
26632662
var y0 = Math.floor(Math.min(0, y) / ph);
26642663
var xe = Math.ceil(Math.max(1, x + w) / pw);
26652664
var ye = Math.ceil(Math.max(1, y + h) / ph);
26662665

26672666
var rows = xe - x0;
26682667
var cols = ye - y0;
2669-
26702668
var bounds = new mxRectangle(this.scale * (this.translate.x + x0 * pw), this.scale *
26712669
(this.translate.y + y0 * ph), this.scale * rows * pw, this.scale * cols * ph);
26722670
return bounds;

‎src/core/graphEdit/js/Format.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6614,7 +6614,7 @@
66146614
btn.setAttribute('title', mxResources.get('clearDefaultStyle') + ' (' + this.editorUi.actions.get('clearDefaultStyle').shortcut + ')');
66156615
btn.style.width = '202px';
66166616
div.appendChild(btn);
6617-
6617+
66186618
return div;
66196619
};
66206620

‎src/core/graphEdit/js/Graph.js

-2
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,6 @@ Graph.prototype.init = function(container)
21342134
this.scale = this.graph.currentScale;
21352135
this.translate = this.graph.currentTranslate;
21362136
}
2137-
21382137
graphViewValidateBackgroundPage.apply(this, arguments);
21392138

21402139
if (useCssTranforms)
@@ -2465,7 +2464,6 @@ Graph.prototype.getPageLayout = function()
24652464
this.view.translate.x) / size.width) - x0;
24662465
var h0 = Math.ceil((Math.floor((bounds.y + bounds.height) / this.view.scale) -
24672466
this.view.translate.y) / size.height) - y0;
2468-
24692467
return new mxRectangle(x0, y0, w0, h0);
24702468
}
24712469
};

‎src/core/graphEdit/js/Sidebar.js

+31-21
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ Sidebar.prototype.init = function()
8989
// 传输网
9090
this.addAdvancedPalette(false);
9191

92-
// IP网
92+
// 数据网
9393
this.addUmlPalette(false);
9494
// 其他组件
9595
this.addBpmnPalette(dir, false);
@@ -1168,13 +1168,13 @@ Sidebar.prototype.addUmlPalette = function(expand)
11681168
this.setCurrentSearchEntryLibrary('uml');
11691169

11701170
const fns = [];
1171-
const list = ['CSOFTX3000','UMG8900','SIWF','HLR','SCP','SMSC','MMSC'];
1172-
list.forEach(type=>{
1173-
fns.push(
1174-
this.createVertexTemplateEntry(`image;html=1;image=/images/stencils/${type}.png`,
1175-
this.defaultImageWidth, this.defaultImageHeight, '', type, true, null, type)
1176-
)
1177-
});
1171+
// const list = ['CSOFTX3000','UMG8900','SIWF','HLR','SCP','SMSC','MMSC'];
1172+
// list.forEach(type=>{
1173+
// fns.push(
1174+
// this.createVertexTemplateEntry(`image;html=1;image=/images/stencils/${type}.png`,
1175+
// this.defaultImageWidth, this.defaultImageHeight, '', type, true, null, type)
1176+
// )
1177+
// });
11781178

11791179
this.addPaletteFunctions('uml', mxResources.get('uml'), expand || false, fns);
11801180
this.setCurrentSearchEntryLibrary();
@@ -1190,22 +1190,32 @@ Sidebar.prototype.addBpmnPalette = function(dir, expand)
11901190
this.setCurrentSearchEntryLibrary('bpmn');
11911191

11921192
const list = [
1193-
{type: 'operator',title: '操作员'},
1194-
{type: 'computer',title: '电脑'},
1195-
{type:'firewall',title: '防护墙'},
1196-
{type: 'server',title: '服务器'},
1197-
{type: 'user',title: '用户'},
1198-
{type: 'client',title: '客户'},
1199-
{type: 'pad',title: 'pad'},
1200-
{type: 'phone',title: '手机'},
1201-
{type: 'lightning',title: '闪电'},
1202-
{type: 'customer',title: '客户群'},
1203-
{type: 'router',title: '路由'},
1204-
{type: 'switch',title: '交换机'},
1193+
{type: 'operator',title: '操作员',format: 'svg'},
1194+
{type: 'computer',title: '电脑',format: 'svg'},
1195+
{type:'firewall',title: '防护墙',format: 'svg'},
1196+
{type: 'server',title: '服务器',format: 'svg'},
1197+
{type: 'user',title: '用户',format: 'svg'},
1198+
{type: 'client',title: '客户',format: 'svg'},
1199+
{type: 'pad',title: 'pad',format: 'svg'},
1200+
{type: 'phone',title: '手机',format: 'svg'},
1201+
{type: 'lightning',title: '闪电',format: 'svg'},
1202+
{type: 'customer',title: '客户群',format: 'svg'},
1203+
{type: 'router',title: '路由',format: 'svg'},
1204+
{type: 'switch',title: '交换机',format: 'svg'},
1205+
{type: 'government',title:'政企业务编排', format: 'png' },
1206+
{type: 'oss',title:'故障管理中心', format: 'png' },
1207+
{type: 'maintenance',title:'运维管理中心', format: 'png' },
1208+
{type: 'performance',title:'性能管理中心', format: 'png' },
1209+
{type: 'business',title:'业务编排中心', format: 'png' },
1210+
{type: 'nsmf',title:'NSMF', format: 'png' },
1211+
{type: 'webcam',title:'摄像头', format: 'png' },
1212+
{type: 'soft_water',title:'软水准仪', format: 'png' },
1213+
{type: 'hard_water',title:'硬水准仪', format: 'png' },
1214+
{type: 'media_server',title:'流媒体服务器', format: 'png' },
12051215
];
12061216
list.forEach(item=>{
12071217
fns.push(
1208-
this.createVertexTemplateEntry(`image;html=1;image=/images/stencils/${item.type}.svg`,
1218+
this.createVertexTemplateEntry(`image;html=1;image=/images/stencils/${item.type}.${item.format}`,
12091219
this.defaultImageWidth, this.defaultImageHeight, '', item.title, true, null, item.title)
12101220
)
12111221
});
158 Bytes
Binary file not shown.
156 Bytes
Binary file not shown.

‎src/views/Open.vue

+18-11
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ export default {
3434
importFile: false,
3535
};
3636
},
37-
created(){
38-
this.bindEvents();
39-
},
4037
methods: {
4138
initEditGraph(editorUiInit){
4239
this.editorUiInit = editorUiInit;
@@ -46,16 +43,20 @@ export default {
4643
this.editorUiInit.editor.graph.setSelectionCells(
4744
this.editorUiInit.editor.graph.importGraphModel(doc.documentElement)
4845
);
46+
this.editorUiInit.actions.get("lockUnlock").funct()
47+
mxPopupMenu.prototype.enabled = false
4948
this.importFile = false;
49+
this.handleRender();
5050
},
51-
bindEvents(){
52-
document.oncontextmenu=(event)=>{
53-
event.returnValue=false;
54-
};
55-
// document.body.contextmenu = (e)=>{
56-
// e.preventDefault();
57-
// e.stopPropagation();
58-
// }
51+
handleRender(){
52+
const model = this.editorUiInit.editor.graph.getModel();
53+
const cells = model.cells || [];
54+
for(let index in cells){
55+
if(model.isVertex(cells[index])) {
56+
const value = model.getValue(cells[index]);
57+
console.log('这是个图形 图形属性值',value);
58+
}else console.log('这是个边边');
59+
}
5960
}
6061
},
6162
};
@@ -88,9 +89,15 @@ export default {
8889
}
8990
.geDiagramContainer{
9091
inset: 0 !important;
92+
&>svg{
93+
background-image: none !important;
94+
}
9195
}
9296
.geHsplit{
9397
display: none;
9498
}
99+
div.mxPopupMenu{
100+
display: none !important;
101+
}
95102
}
96103
</style>

‎src/views/temp.vue

-176
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.