2020-09-16 14:49:21 +08:00
|
|
|
import { on, once } from '@element-plus/utils/dom'
|
|
|
|
|
2021-09-09 19:41:10 +08:00
|
|
|
import type { ObjectDirective, DirectiveBinding } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2020-09-16 14:49:21 +08:00
|
|
|
export default {
|
2021-09-09 19:41:10 +08:00
|
|
|
beforeMount(el: HTMLElement, binding: DirectiveBinding) {
|
2020-09-16 14:49:21 +08:00
|
|
|
let interval = null
|
2020-12-06 23:52:47 +08:00
|
|
|
let startTime: number
|
2020-09-16 14:49:21 +08:00
|
|
|
const handler = () => binding.value && binding.value()
|
|
|
|
const clear = () => {
|
|
|
|
if (Date.now() - startTime < 100) {
|
|
|
|
handler()
|
|
|
|
}
|
|
|
|
clearInterval(interval)
|
|
|
|
interval = null
|
|
|
|
}
|
|
|
|
|
2021-09-09 19:41:10 +08:00
|
|
|
on(el, 'mousedown', (e: MouseEvent) => {
|
2020-09-16 14:49:21 +08:00
|
|
|
if ((e as any).button !== 0) return
|
|
|
|
startTime = Date.now()
|
|
|
|
once(document as any, 'mouseup', clear)
|
|
|
|
clearInterval(interval)
|
|
|
|
interval = setInterval(handler, 100)
|
|
|
|
})
|
|
|
|
},
|
2020-12-06 23:52:47 +08:00
|
|
|
} as ObjectDirective
|