/*
 *@description:表格hover性能优化
 *@author: hudw
 *@date: 2022-09-20 11:09:41
 */
//import debounce from 'lodash/debounce'
//  this.onWindowResized = debounce(this.onWindowResized, 500, {
//   leading: false
// });
export default {
  data() {
    return {
      elementTableContent: null,
    }
  },
  mounted() {
    this.elementTableContent = this.$el.querySelector('.ant-table-content')
    if (this.elementTableContent) {
      this.elementTableContent.addEventListener('mouseover', this.handleMouseover)
      this.elementTableContent.addEventListener('mouseout', this.handleMouseout)
    }
  },
  destroyed() {
    this.elementTableContent.removeEventListener('mouseover', this.handleMouseover)
    this.elementTableContent.removeEventListener('mouseout', this.handleMouseout)
    this.elementTableContent=null
  },
  methods: {
    handleMouseover(event) {
      this.resultsTRList(event, 'add')
    },
    handleMouseout(event) {
      this.resultsTRList(event, 'remove')
    },
    resultsTRList(event, fn) {
      event.stopPropagation()
      let path= event.path|| event.composedPath?.();
      let tr=null
      if (path) {
        tr = Array.from(path).find((item) => item.nodeName === 'TR')
      }
      if (!tr) return
      let rowKey = tr.dataset.rowKey
      let trList = this.elementTableContent.querySelectorAll(`tr[data-row-key="${rowKey}"]`)
      Array.from(trList).forEach((item) => {
        item.classList[fn]('ant-table-row-hover')
      })
    },
  },
}
