2022-06-22 08:04:42 +08:00
|
|
|
// @ts-nocheck
|
2022-02-11 11:03:15 +08:00
|
|
|
import { on, once } from '@element-plus/utils'
|
2020-09-16 14:49:21 +08:00
|
|
|
|
2022-03-25 15:35:56 +08:00
|
|
|
import type { DirectiveBinding, ObjectDirective } 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
|