export default function (el: HTMLElement, content: anyObj) {
  const { value, duration } = content
  // 定义长按所需的时长（毫秒）
  const delay = duration || 1000
  let pressTimer: any = null

  // 开始计时
  const start = (e: any) => {
    if (e.type === 'click' && e.button !== 0) {
      return
    }
    // 设置定时器
    if (pressTimer === null) {
      pressTimer = setTimeout(() => {
        // 长按后执行绑定的函数
        value()
      }, delay)
    }
  }

  // 取消计时器
  const cancel = (_: Event) => {
    if (pressTimer !== null) {
      clearTimeout(pressTimer)
      pressTimer = null
    }
  }

  // 添加事件监听
  el.addEventListener('touchstart', start)
  el.addEventListener('touchend', cancel)
  el.addEventListener('touchmove', cancel) // 避免拖动时触发
  el.addEventListener('mousedown', start) // 支持鼠标点击
  el.addEventListener('mouseup', cancel)
  el.addEventListener('mouseleave', cancel)
}
