谢谢各位已经解决,贴一下自己的解决方法G6.registerNode("customNode", { draw(cfg, group) { const shape = group.addShape("rect", { attrs: { id: cfg.id || mainId, x: offsetX, y: offsetY + 20, width: width, height: height, stroke: color, fill: color,//此处必须有fill 不然不能触发事件 radius: [0, 0, 6, 6] } }); group.addShape("rect", { attrs: { x: offsetX, y: offsetY, width: width, height: 21, stroke: color, fill: "#fff", radius: [6, 6, 0, 0] } }); group.addShape("image", { attrs: { x: offsetX + width - 24, y: offsetY + 2, width: 16, height: 16, img: cfg.infoImage, cursor: 'pointer', isInfo: 1, parent: mainId } }); } ... onClick(e) { // 点击节点区域是否为信息icon const isInfo = e.target.get('attrs').isInfo }在画布初始化节点的时候给 shape 设置属性 isInfo 用于识别,绑定点击事件的时候就可以通过 get('attrs') 方法来区分
谢谢各位已经解决,贴一下自己的解决方法
在画布初始化节点的时候给 shape 设置属性 isInfo 用于识别,绑定点击事件的时候就可以通过 get('attrs') 方法来区分