equipment.ts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SMouseEvent } from "@persagy-web/base";
  27. import { SEquipItem } from "@persagy-web/big";
  28. import { SGraphItem, STextItem, SGraphCircleItem } from "@persagy-web/graph/lib";
  29. import { SColor, SFont, SPoint, SPainter } from "@persagy-web/draw/lib";
  30. import { SCircleItem } from "./SCircleItem";
  31. // 样式接口
  32. interface Style {
  33. // 字体颜色
  34. color: string;
  35. // 字体大小
  36. fontSize: number;
  37. // 公式(信息点)
  38. formula: any[];
  39. // 图标地址
  40. url: string;
  41. }
  42. /**
  43. * 平面图派生设备类
  44. *
  45. * @author 贠星 <yunxing0102@163.com>
  46. */
  47. export class EquipItem extends SEquipItem {
  48. StatusPoint: SCircleItem | null = null;
  49. // 颜色
  50. private _color: SColor = new SColor();
  51. get color() {
  52. return this._color;
  53. }
  54. set color(val) {
  55. this._color = val;
  56. }
  57. // 字体
  58. private _font: SFont = new SFont("sans-serif", 12);
  59. get font() {
  60. return this._font;
  61. }
  62. set font(val) {
  63. this._font = val;
  64. }
  65. // 设置设备类样式
  66. setStyle(style: Style) {
  67. const { color, fontSize, formula, url } = style;
  68. this.url = url;
  69. // 更改颜色,字体
  70. this.color = new SColor(color);
  71. this.font = new SFont("sans-serif", fontSize);
  72. this.formula = formula;
  73. this.update();
  74. }
  75. /** 公式(信息点) */
  76. private _formula: any[] = [];
  77. get formula(): any[] {
  78. return this._formula;
  79. }
  80. set formula(val) {
  81. this._formula = val;
  82. try {
  83. // const textList = JSON.parse(this._formula);
  84. if (this.scene) {
  85. this.textItemList.forEach((textItem) => {
  86. this.scene?.removeItem(textItem);
  87. });
  88. }
  89. if (this._formula.length) {
  90. // if (textList.length) {
  91. const textItemList: any[] = [];
  92. this._formula.forEach((item: any, index: number) => {
  93. // textList.forEach((item: any, index: number) => {
  94. const obj = new STextItem(this);
  95. // @ts-ignore
  96. obj.propertyData = { ...item };
  97. obj.text = item.name;
  98. if (item.pos) {
  99. obj.moveTo(item.pos.x, item.pos.y);
  100. } else {
  101. obj.moveTo(this.img.width * 0.5, this.font.size * (index - 0.125 - 0.5 * this._formula.length));
  102. }
  103. // TODO: obj.moveTo(this.img.width * 0.5, -(this.font.size * 1.25 * 0.5) + (index * this.font.size) - (textList.length - 1) * 0.5 * this.font.size);
  104. // obj.moveTo(this.img.width * 0.5, this.font.size * (index - 0.125 - 0.5 * textList.length));
  105. // obj.connect("onMove", this, this.textMove.bind(this));
  106. // console.log("::::", this.font, this.color);
  107. obj.font = this.font;
  108. obj.color = this.color;
  109. obj.isTransform = false;
  110. obj.showSelect = false;
  111. // console.log("::::::", obj);
  112. textItemList.push(obj);
  113. });
  114. this.textItemList = textItemList;
  115. } else {
  116. this.textItemList = [];
  117. }
  118. this.update();
  119. } catch (error) {
  120. console.error("公式数据错误", error);
  121. }
  122. }
  123. constructor(parent: SGraphItem | null, data: Style) {
  124. super(parent);
  125. this.zOrder = 9700;
  126. this.isTransform = false;
  127. this.sWidth = 32;
  128. this.sHeight = 32;
  129. this.img.showSelect = false;
  130. this.setStyle(data);
  131. }
  132. // 设置设备名称
  133. setEquipName() {
  134. const item = new STextItem(this);
  135. item.text = this.data.localName;
  136. // item.strokeColor = new SColor('#6b7086');
  137. item.color = new SColor("#6b7086");
  138. item.font = new SFont("sans-serif", 12);
  139. item.isTransform = true;
  140. // item.font = new SFont("sans-serif", 16);
  141. // item.moveTo(-this.width / 2, this.height / 2);
  142. item.moveTo(-this.width / 2, 20);
  143. this.setStatusPoint(item);
  144. }
  145. /**
  146. * 设置状态点
  147. *
  148. * @param parent 父类
  149. */
  150. setStatusPoint(parent: STextItem | null) {
  151. const item = new SCircleItem(parent);
  152. const h = parent ? parent.height : 0;
  153. item.localtion = new SPoint(0, 0);
  154. item.radius = 4;
  155. item.fillColor = new SColor("#de6466");
  156. item.strokeColor = new SColor("#de6466");
  157. item.moveTo(-item.radius * 2, h);
  158. this.StatusPoint = item;
  159. }
  160. /**
  161. * 设置状态远点颜色
  162. *
  163. * @param val 颜色字符
  164. */
  165. setStatusPointColor(val: string) {
  166. if (!this.StatusPoint) return;
  167. this.StatusPoint.fillColor = new SColor(val);
  168. this.StatusPoint.strokeColor = new SColor(val);
  169. }
  170. /**
  171. * 获取信息点数组
  172. */
  173. getMsgList(): any {
  174. return this.textItemList;
  175. }
  176. onMouseMove(event: SMouseEvent): boolean {
  177. const scene = this.scene;
  178. if (null != scene) {
  179. if (scene.hoverItem == null || scene.hoverItem !== this) {
  180. if (scene.hoverItem != null) {
  181. scene.hoverItem.onMouseLeave(event);
  182. }
  183. this.onMouseEnter(event);
  184. scene.hoverItem = this;
  185. }
  186. }
  187. return true;
  188. }
  189. /**
  190. * 鼠标进入事件
  191. *''
  192. * @param event 保存事件参数
  193. * @return 是否处理事件
  194. */
  195. onMouseEnter(event: SMouseEvent): boolean {
  196. this.$emit("onMouseEnter");
  197. return false;
  198. }
  199. /**
  200. * 鼠标离开事件
  201. *
  202. * @param event 保存事件参数
  203. * @return 是否处理事件
  204. */
  205. onMouseLeave(event: SMouseEvent): boolean {
  206. this.$emit("onMouseLeave");
  207. return false;
  208. }
  209. // 显示图片阴影
  210. _showImgShadow = false;
  211. get showImgShadow(): boolean {
  212. return this._showImgShadow;
  213. }
  214. set showImgShadow(v: boolean) {
  215. this._showImgShadow = v;
  216. this.update();
  217. }
  218. onDraw(painter: SPainter): void {
  219. if (this.showImgShadow) {
  220. painter.shadow.shadowBlur = 20;
  221. painter.shadow.shadowColor = new SColor(`#000000`);
  222. painter.shadow.shadowOffsetX = 10;
  223. painter.shadow.shadowOffsetY = 10;
  224. } else {
  225. painter.shadow.shadowColor = SColor.Transparent;
  226. }
  227. }
  228. }