<template>
  <extend-base-el-tree v-bind="$attrs" @node-click="hdlClick" @node-contextmenu='rightClick'></extend-base-el-tree>
</template>

<script>
import {Tree} from 'element-ui'
import debounce from 'lodash.debounce'
export default {
  inheritAttrs: false,
  data () {
    return {
      clickCount: 0
    }
  },
  components: {
    'extend-base-el-tree': Tree
  },
  methods: {
    hdlClick () {
      const args = arguments;
      // 发送双击事件
      this.clickCount++;
      const fnEmitDblClick = debounce(() => {
        // 之前发现单击双击事件冲突，然后我在这里修改了一下，只不过单击会有300毫秒的延迟，因为浏览器得判断是双击还是单击事件
        if (this.clickCount === 1) {
          // 发送单击事件
          this.$emit('node-click', ...args);
        }
        if (this.clickCount > 1) {
          this.$emit('node-dblclick', ...args)
        }
        this.clickCount = 0
      }, 300);
      fnEmitDblClick()
    },
    rightClick () {
      const args = arguments;
      this.$emit('node-contextmenu', ...args)
    }
  }
}
</script>

<style scoped>

</style>
