exports.install = function (Vue) {

  Vue.prototype.handleClick = function (title,type) {
    const component = findComponentDownward(this, 'myCustomSvg')
    component.handleClick(title,type)
  }
  Vue.prototype.handleClick2 = function (title) {
    const component = findComponentDownward(this, 'flowPath')
    component.openEventDrawer(title)
  }
  Vue.prototype.svgOnMouseenter = function (e, val) {
    const component = findComponentDownward(this, 'myPopover')
    component.svgOnMouseenter(e, val)
  }
  Vue.prototype.svgOnMouseleave = function (e, val) {
    const component = findComponentDownward(this, 'myPopover')
    component.svgOnMouseleave(e, val)
  }
  Vue.prototype.svgOnClick = function (e, val) {
    const component = findComponentDownward(this, 'myPopover')
    component.svgOnClick(e, val)
  }
  Vue.prototype.checkImg = function (val) {
    const component = findComponentDownward(this, 'myCommonUse')
    component.checkImg(val)
  }
  Vue.prototype.selectMark = function (val,type) {
    const component = findComponentDownward(this, 'myCommonUse')
    component.selectMark(val,type)
  }
}

function findComponentDownward(context, componentName) {
  const childrens = context.$children
  let children = null

  if (childrens.length) {
    for (const child of childrens) {
      const name = child.$options.name
      if (name === componentName) {
        children = child
        break
      } else {
        children = findComponentDownward(child, componentName)
        if (children) break
      }
    }
  }
  return children
}
