perf(button): delete the button component useless code

This commit is contained in:
vben
2020-10-30 00:56:11 +08:00
parent fb0c7763ed
commit bdce84537a
6 changed files with 97 additions and 54 deletions

View File

@@ -0,0 +1,24 @@
import { on, once } from '/@/utils/domUtils';
export default {
beforeMount(el: Element, binding: any) {
let interval: ReturnType<typeof setInterval> | null = null;
let startTime = 0;
const handler = () => binding.value && binding.value();
const clear = () => {
if (Date.now() - startTime < 100) {
handler();
}
interval && clearInterval(interval);
interval = null;
};
on(el, 'mousedown', (e) => {
if ((e as any).button !== 0) return;
startTime = Date.now();
once(document as any, 'mouseup', clear);
interval && clearInterval(interval);
interval = setInterval(handler, 100);
});
},
};