const doubleTap = {
  install(Vue) {
    Vue.directive('double-tap', {
      bind(el, binding) {
        let lastTap = 0;
        let timeout = null;
        
        const handleClick = (event) => {
          const now = Date.now();
          const timeDiff = now - lastTap;
          
          if (timeout) clearTimeout(timeout);
          
          if (timeDiff < 300 && timeDiff > 0) {
            // 双击事件
            if (typeof binding.value === 'function') {
              binding.value(event);
            }
            lastTap = 0;
          } else {
            // 设置单击定时器
            timeout = setTimeout(() => {
              lastTap = 0;
            }, 300);
            lastTap = now;
          }
        };
        
        el.addEventListener('click', handleClick);
        el._doubleTapHandler = handleClick;
      },
      
      unbind(el) {
        if (el._doubleTapHandler) {
          el.removeEventListener('click', el._doubleTapHandler);
          delete el._doubleTapHandler;
        }
      }
    });
  }
}
export default doubleTap;