2020-09-16 14:49:21 +08:00
|
|
|
import { on, once } from '@element-plus/utils/dom'
|
|
|
|
|
2020-12-06 23:52:47 +08:00
|
|
|
import type { ObjectDirective } from 'vue'
|
2021-08-24 13:36:48 +08:00
|
|
|
|
2020-09-16 14:49:21 +08:00
|
|
|
export default {
|
|
|
|
beforeMount(el, binding) {
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
on(el, 'mousedown', e => {
|
|
|
|
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
|