TipelineItem.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import { SPolylineItem, ItemOrder } from '@saga-web/big/lib';
  2. import { SPoint } from "@saga-web/draw/lib";
  3. /**
  4. * 管道item
  5. *
  6. * */
  7. export class TipelineItem extends SPolylineItem {
  8. constructor(parent, data) {
  9. super(parent, []);
  10. /** 起始锚点 */
  11. this.startAnchor = null;
  12. /** 结束锚点 */
  13. this.endAnchor = null;
  14. /** 对应的图例ID */
  15. this._graphElementId = "";
  16. /** 关联节点1ID */
  17. this._node1Id = "";
  18. /** 关联节点2ID */
  19. this._node2Id = "";
  20. /** 关联锚点1ID */
  21. this._anchor1ID = "";
  22. /** 关联锚点2ID */
  23. this._anchor2ID = "";
  24. /** 数据存储 */
  25. this.data = null;
  26. this.zOrder = ItemOrder.polylineOrder;
  27. this.pointList = data.PointList.map(item => {
  28. return new SPoint(item.X, item.Y);
  29. });
  30. this.data = data;
  31. this.id = data.ID;
  32. if (data.GraphElementId) {
  33. this._graphElementId = data.GraphElementId;
  34. }
  35. if (data.Node1ID) {
  36. this._node1Id = data.Node1ID;
  37. }
  38. if (data.Node2ID) {
  39. this._node2Id = data.Node2ID;
  40. }
  41. if (data.Anchor1ID) {
  42. this._anchor1ID = data.Anchor1ID;
  43. }
  44. if (data.Anchor2ID) {
  45. this._anchor2ID = data.Anchor2ID;
  46. }
  47. if (data.Properties && data.Properties.Color) {
  48. this.strokeColor = data.Properties.Color;
  49. }
  50. // if(data.Properties && data.Properties.LineDash){
  51. // this.LineDash = data.Properties.LineDash
  52. // }
  53. if (data.Properties && data.Properties.LineWidth) {
  54. this.lineWidth = data.Properties.LineWidth;
  55. }
  56. }
  57. get graphElementId() {
  58. return this._graphElementId;
  59. }
  60. set graphElementId(v) {
  61. this._graphElementId = v;
  62. if (this.data) {
  63. this.data.GraphElementId = this._graphElementId;
  64. }
  65. }
  66. get node1Id() {
  67. return this._node1Id;
  68. }
  69. set node1Id(v) {
  70. this._node1Id = v;
  71. if (this.data) {
  72. this.data.Node1ID = this._node1Id;
  73. }
  74. }
  75. get node2Id() {
  76. return this._node2Id;
  77. }
  78. set node2Id(v) {
  79. this._node2Id = v;
  80. if (this.data) {
  81. this.data.Node2ID = this._node2Id;
  82. }
  83. }
  84. get anchor1ID() {
  85. return this._anchor1ID;
  86. }
  87. set anchor1ID(v) {
  88. this._anchor1ID = v;
  89. if (this.data) {
  90. this.data.Anchor1ID = this._anchor1ID;
  91. }
  92. }
  93. get anchor2ID() {
  94. return this._anchor2ID;
  95. }
  96. set anchor2ID(v) {
  97. this._anchor2ID = v;
  98. if (this.data) {
  99. this.data.Anchor2ID = this._anchor2ID;
  100. }
  101. }
  102. /** 接收事件作出修改 */
  103. changePos() {
  104. if (this.startAnchor) {
  105. // 判断删除equip后,不移动
  106. if (this.startAnchor.parent && this.startAnchor.parent.parent) {
  107. this.pointList[0] = this.startAnchor.mapToScene(0, 0);
  108. }
  109. }
  110. if (this.endAnchor) {
  111. // 删除equip后
  112. if (this.endAnchor.parent && this.endAnchor.parent.parent) {
  113. this.pointList[this.pointList.length - 1] = this.endAnchor.mapToScene(0, 0);
  114. }
  115. }
  116. }
  117. /** 获取data数据 */
  118. toData() {
  119. let pointList = this.pointList.map(item => {
  120. return {
  121. X: item.x,
  122. Y: item.y
  123. };
  124. });
  125. if (this.data) {
  126. this.data.PointList = pointList;
  127. this.data.Properties.LineWidth = this.lineWidth;
  128. // this.data.Properties.LineDash = this.LineDash;
  129. this.data.Properties.Color = this.strokeColor;
  130. }
  131. return this.data;
  132. }
  133. }