BaseNode.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * Created by jacky on 2016/7/18.
  3. */
  4. import {Node,MsgBox} from 'flowdesigner';
  5. export default class BaseNode extends Node{
  6. getNodeName(type){
  7. switch (type){
  8. case "ActionNode":
  9. return 'action';
  10. case "DecisionNode":
  11. return 'decision';
  12. case "ForkNode":
  13. return 'fork';
  14. case "JoinNode":
  15. return 'join';
  16. case "PackageNode":
  17. return 'rule-package';
  18. case "RuleNode":
  19. return 'rule';
  20. case "ScriptNode":
  21. return 'script';
  22. case "StartNode":
  23. return 'start';
  24. default:
  25. MsgBox.alert(`不支持的节点类型[${type}]`);
  26. }
  27. }
  28. initFromJson(json){
  29. const {width,height}=json;
  30. if(parseInt(width)<30){
  31. json.width=30;
  32. }
  33. if(parseInt(height)<65){
  34. json.height=65;
  35. }
  36. super.initFromJson(json);
  37. this.eventBean=json.eventBean;
  38. }
  39. validate(){
  40. let errorInfo=null;
  41. if(!this.name || this.name.length<1){
  42. errorInfo=`节点名不能为空!`;
  43. return errorInfo;
  44. }
  45. if(this.in===-1 || this.in>0){
  46. if(this.out===-1 || this.out>0){
  47. if(this.fromConnections.length===0 && this.toConnections.length===0){
  48. errorInfo=`${this.name}节点未和其它节点连接!`;
  49. }
  50. }else{
  51. if(this.toConnections.length===0){
  52. errorInfo=`${this.name}节点未和其它节点连接!`;
  53. }
  54. }
  55. }else{
  56. if(this.out===-1 || this.out>0){
  57. if(this.fromConnections.length===0){
  58. errorInfo=`${this.name}节点未和其它节点连接!`;
  59. }
  60. }
  61. }
  62. return errorInfo;
  63. }
  64. getFromConnectionsXML(){
  65. let xml='';
  66. for(let conn of this.fromConnections){
  67. xml+=this.buildConnectionXML(conn);
  68. }
  69. return xml;
  70. }
  71. buildConnectionXML(connection){
  72. const json=connection.toJSON();
  73. const path=json.path;
  74. let pathInfo='',i=0;
  75. for(let p of path){
  76. if(i>0 && i!==path.length-1){
  77. if(pathInfo!==''){
  78. pathInfo+=',';
  79. }
  80. pathInfo+=parseInt(p[1])+','+parseInt(p[2]);
  81. }
  82. i++;
  83. }
  84. let xml=`<connection g="${pathInfo}" type="${json.type}" to="${json.to}"`;
  85. if(json.name){
  86. xml+=` name="${json.name}"`;
  87. }
  88. xml+='>';
  89. xml+='</connection>';
  90. return xml;
  91. }
  92. getXMLNodeBaseProps(json){
  93. let xml=`name="${json.name}" `;
  94. xml+=`x="${json.x}" `;
  95. xml+=`y="${json.y}" `;
  96. xml+=`width="${json.w}" `;
  97. xml+=`height="${json.h}" `;
  98. if(this.eventBean){
  99. xml+=`event-bean="${this.eventBean}"`;
  100. }
  101. return xml;
  102. }
  103. }