瀏覽代碼

系统图的线支持点击事件

niuheng 3 年之前
父節點
當前提交
ef400fffce
共有 1 個文件被更改,包括 9 次插入0 次删除
  1. 9 0
      src/components/systemGraph/graph.vue

+ 9 - 0
src/components/systemGraph/graph.vue

@@ -240,6 +240,7 @@ export default {
         var lineColor = "0x" + _cLine.style.lineColor.substring(1);
         var lineInstance = new PIXI.Graphics();
         lineInstance.lineStyle(_cLine.style.lineWidth, lineColor, 1, 0, false);
+        lineInstance.name = _cLine.id;
 
         var _newStart = _this.convertCoordToLeftOrigina({
           x: _cLine.path[0].x,
@@ -254,6 +255,14 @@ export default {
         lineInstance.moveTo(_newStart.x, _newStart.y);
         lineInstance.lineTo(_newEnd.x, _newEnd.y);
 
+        //设置点击范围,不然click事件不会触发
+        lineInstance.hitArea = lineInstance.getBounds();
+        //启用事件
+        lineInstance.interactive = true;
+        lineInstance.on("click", (event) => {
+          _this.clickEventCall(event, 2);
+        });
+
         pixiApp.stage.addChild(lineInstance);
       });
     },