@@ -329,7 +329,7 @@ const {
329329 mxConstants ,
330330 mxImage ,
331331 mxCellState ,
332- mxConnectionHandler ,
332+ // mxConnectionHandler,
333333 mxCodec ,
334334 mxRectangleShape ,
335335 mxPoint ,
@@ -347,6 +347,8 @@ const {
347347 mxConstraintHandler ,
348348 mxEllipse ,
349349 // mxTriangle,
350+ mxSvgCanvas2D ,
351+ mxImageExport ,
350352 mxConnectionConstraint ,
351353 mxPolyline ,
352354 mxVertexHandler ,
@@ -414,9 +416,9 @@ export default {
414416 createGraph () {
415417 // 创建graph
416418 // 方式一:直接构建graph实例
417- // this.graph = new mxGraph(this.$refs.container)
419+ this .graph = new mxGraph (this .$refs .container )
418420 this .editor = new mxEditor ();
419- this .graph = this .editor .graph ;
421+ // this.graph = this.editor.graph;
420422 this .editor .setGraphContainer (this .$refs .container );
421423 // 配置默认全局样式
422424 this .configureStylesheet (this .graph );
@@ -1146,8 +1148,8 @@ export default {
11461148 // mxGraph.prototype.collapsedImage = new mxImage('images/collapsed.gif', 15, 15);
11471149 // mxGraph.prototype.expandedImage = new mxImage('images/expanded.gif', 15, 15);
11481150
1149- // 配置节点中心的连接图标
1150- mxConnectionHandler .prototype .connectImage = new mxImage (' ./icon/connectionpoint.png' , 14 , 14 );
1151+ // 配置节点中心的连接图标(注釋掉即可指定錨點連接到另一個節點的錨點上)
1152+ // mxConnectionHandler.prototype.connectImage = new mxImage('./icon/connectionpoint.png', 14, 14);
11511153 // 显示中心端口图标
11521154 graph .connectionHandler .targetConnectImage = false ;
11531155 // 是否开启浮动自动连接
@@ -1158,7 +1160,7 @@ export default {
11581160 mxConstraintHandler .prototype .pointImage = new mxImage (' icon/dot.svg' , 10 , 10 )
11591161 // 设置锚点上的高亮颜色
11601162 mxConstraintHandler .prototype .createHighlightShape = function () {
1161- return new mxEllipse (null , ' #409eff99' , ' #409eff99' , 5 )
1163+ return new mxEllipse (null , ' #409eff99' , ' #409eff99' , 15 )
11621164 }
11631165
11641166 mxShape .prototype .constraints = [
@@ -1337,8 +1339,65 @@ export default {
13371339 // 生成图片
13381340 showImage () {
13391341 this .editor .execute (' show' );// 直接页面跳转,并以svg流程图
1342+ // 下载svg流程图
1343+ console .log (' this.gtaph' , this .graph )
1344+ const svg = this .exportModelSvg ();
1345+ const blob = new Blob ([svg], { type: ' image/svg+xml' });
1346+ const url = URL .createObjectURL (blob);
1347+ let link = document .createElement (' a' );
1348+ link .href = url;
1349+ link .download = ' model.svg' ;
1350+ link .click ();
13401351 },
13411352
1353+ exportModelSvg () {
1354+ let scale = this .graph .view .scale ;
1355+ let bounds = this .graph .getGraphBounds ();
1356+ let border = 10 ;
1357+
1358+ // Prepares SVG document that holds the output
1359+ let svgDoc = mxUtils .createXmlDocument ();
1360+ let root = (svgDoc .createElementNS != null ) ?
1361+ svgDoc .createElementNS (mxConstants .NS_SVG , ' svg' ) : svgDoc .createElement (' svg' );
1362+
1363+ if (root .style != null ) {
1364+ root .style .backgroundColor = ' #FFFFFF' ;
1365+ } else {
1366+ root .setAttribute (' style' , ' background-color:#FFFFFF' );
1367+ }
1368+
1369+ if (svgDoc .createElementNS == null ) {
1370+ root .setAttribute (' xmlns' , mxConstants .NS_SVG );
1371+ }
1372+ let width = Math .ceil (bounds .width * scale / scale + 2 * border);
1373+ let height = Math .ceil (bounds .height * scale / scale + 2 * border);
1374+ root .setAttribute (' class' , ' svg-container' );
1375+ root .setAttribute (' width' , width + ' px' );
1376+ root .setAttribute (' height' , height + ' px' );
1377+ root .setAttribute (' viewBox' , " 0 0 " + width + " " + height);
1378+ root .setAttribute (' xmlns:xlink' , mxConstants .NS_XLINK );
1379+ root .setAttribute (' version' , ' 1.1' );
1380+
1381+ // Adds group for anti-aliasing via transform
1382+ let group = (svgDoc .createElementNS != null ) ?
1383+ svgDoc .createElementNS (mxConstants .NS_SVG , ' g' ) : svgDoc .createElement (' g' );
1384+ group .setAttribute (' transform' , ' translate(0.5,0.5)' );
1385+ root .appendChild (group);
1386+ svgDoc .appendChild (root);
1387+
1388+ // Renders graph. Offset will be multiplied with state's scale when painting state.
1389+ let svgCanvas = new mxSvgCanvas2D (group);
1390+ svgCanvas .translate (Math .floor (border / scale - bounds .x ), Math .floor (border / scale - bounds .y ));
1391+ svgCanvas .scale (scale);
1392+
1393+ let imgExport = new mxImageExport ();
1394+ imgExport .drawState (this .graph .getView ().getState (this .graph .model .root ), svgCanvas);
1395+
1396+ // let xml = encodeURIComponent(mxUtils.getXml(root)); //no need
1397+ let xml = mxUtils .getXml (root);
1398+ return xml;
1399+
1400+ },
13421401 enGroup () {
13431402 this .editor .graph .setSelectionCell (this .editor .groupCells ());
13441403 this .$message .success (' 组合成功' );
0 commit comments