FlowChart.razor 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. 
  2. @if (flowChartUtility != null)
  3. {
  4. <svg width="@ChartWidth" height="@ChartHeight" id="FlowChartContainer" xmlns="http://www.w3.org/2000/svg">
  5. <defs>
  6. <marker id="idArrow"
  7. viewBox="0 0 20 20" refX="0" refY="10"
  8. markerUnits="strokeWidth" markerWidth="5" markerHeight="10"
  9. orient="auto">
  10. <path d="M 0 0 L 20 10 L 0 20 z" fill="black" stroke="black" />
  11. </marker>
  12. </defs>
  13. <text x="@(ChartWidth/2)" y="@(TitleHeight/2)" fill="black" alignment-baseline="middle" text-anchor="middle" font-size="30" font-weight="800">@workflow.Name</text>
  14. @{
  15. dynamic startLine = flowChartUtility.GetStartInitLine();
  16. <line x1="@startLine.x1" y1="@startLine.y1 " x2="@startLine.x2" y2="@startLine.y2" stroke="black" stroke-width="2" marker-end="url(#idArrow)" />
  17. }
  18. @for (int iLevel = 0; iLevel < flowChartUtility.LevelNodes.Count; iLevel++)
  19. {
  20. @foreach (var node in flowChartUtility.LevelNodes[iLevel])
  21. {
  22. if (node.Type == 0)
  23. {
  24. <circle cx="@(node.x)" cy="@node.y" r="@(node.width / 2) " stroke="black" stroke-width="2" fill="@(node.FillColor)" />
  25. <a>
  26. <text x="@(node.x)" y="@node.y" fill="black" alignment-baseline="middle" text-anchor="middle" font-size="14">
  27. @if (node == flowChartUtility.startNode)
  28. {
  29. @("开始")
  30. }
  31. else
  32. {
  33. if (node == flowChartUtility.endNode)
  34. {
  35. @("结束")
  36. }
  37. else
  38. {
  39. if (node.NodeObject is entity.workflowDefine.Step)
  40. {
  41. @(((entity.workflowDefine.Step)node.NodeObject).Name)
  42. }
  43. }
  44. }
  45. </text>
  46. </a>
  47. }
  48. if (node.Type == 1)
  49. {
  50. <rect x="@(node.x - node.width / 2)" y="@(node.y - node.height / 2)" rx="10" ry="10" width="@node.width" height="@node.height" style="fill:@(node.FillColor);stroke:black;stroke-width:3;opacity:0.5" />
  51. <a @ondblclick="() => DoubleClickNode(node)" @onclick="()=>ClickNode(node)">
  52. <text x="@node.x" y="@node.y" fill="black" alignment-baseline="middle" text-anchor="middle" font-size="@rectFontSize" font-weight="700">
  53. @if (node.NodeObject is entity.workflowDefine.Action)
  54. {
  55. @((workflow.InitAction == null || string.IsNullOrEmpty(workflow.InitAction.Name)) ? $"启动{workflow.Name}" : workflow.InitAction.Name)
  56. }
  57. else
  58. {
  59. @(((entity.workflowDefine.Step)node.NodeObject).Name)
  60. }
  61. </text>
  62. </a>
  63. @if (flowChartUtility.SelectedShape == node)
  64. {
  65. <circle cx="@(node.x - node.width / 2)" cy="@(node.y)" r="3" stroke="black" stroke-width="1" fill="white" />
  66. <circle cx="@(node.x + node.width / 2)" cy="@(node.y)" r="3" stroke="black" stroke-width="1" fill="white" />
  67. <circle cx="@(node.x)" cy="@(node.y - node.height / 2)" r="3" stroke="black" stroke-width="1" fill="white" />
  68. <circle cx="@(node.x)" cy="@(node.y + node.height / 2)" r="3" stroke="black" stroke-width="1" fill="white" />
  69. }
  70. }
  71. }
  72. }
  73. @foreach (var t in Transfers)
  74. {
  75. dynamic ret = flowChartUtility.GetLineParater(t);
  76. <line x1="@ret.x1" y1="@ret.y1" x2="@ret.x2" y2="@ret.y2" stroke="black" stroke-width="2" marker-end="url(#idArrow)" />
  77. <circle cx="@((ret.x1 + ret.x2) / 2)" cy="@((ret.y1 + ret.y2) / 2)" r="7" stroke="black" stroke-width="1.5" fill="white" />
  78. <a @ondblclick="() => DoubleClickTrasfer(t)" @onclick ="()=>ClickTrasfer(t)">
  79. <text x="@((ret.x1 + ret.x2) / 2)" y="@((ret.y1 + ret.y2) / 2)" fill="black" alignment-baseline="middle" text-anchor="middle" font-size="12">c</text>
  80. </a>
  81. }
  82. </svg>
  83. }
  84. else
  85. {
  86. <Spin />
  87. }