forked from verdnatura/salix-front
perf: improve mainShrotcutMixin
This commit is contained in:
parent
ea8fde49ff
commit
eca68b76a0
|
@ -1,8 +1,10 @@
|
||||||
import routes from 'src/router/modules';
|
import routes from 'src/router/modules';
|
||||||
|
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
|
let isNotified = false;
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mounted: function () {
|
created: function () {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const keyBindingMap = routes
|
const keyBindingMap = routes
|
||||||
.filter((route) => route.meta.keyBinding)
|
.filter((route) => route.meta.keyBinding)
|
||||||
|
@ -10,14 +12,27 @@ export default {
|
||||||
map[route.meta.keyBinding.toLowerCase()] = route.path;
|
map[route.meta.keyBinding.toLowerCase()] = route.path;
|
||||||
return map;
|
return map;
|
||||||
}, {});
|
}, {});
|
||||||
|
|
||||||
const handleKeyDown = (event) => {
|
const handleKeyDown = (event) => {
|
||||||
const { ctrlKey, altKey, key } = event;
|
const { ctrlKey, altKey, key } = event;
|
||||||
event.preventDefault();
|
|
||||||
if (ctrlKey && altKey && keyBindingMap[key]) {
|
if (ctrlKey && altKey && keyBindingMap[key] && !isNotified) {
|
||||||
|
event.preventDefault();
|
||||||
router.push(keyBindingMap[key]);
|
router.push(keyBindingMap[key]);
|
||||||
|
isNotified = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleKeyUp = (event) => {
|
||||||
|
const { ctrlKey, altKey } = event;
|
||||||
|
|
||||||
|
// Resetea la bandera cuando se sueltan las teclas ctrl o alt
|
||||||
|
if (!ctrlKey || !altKey) {
|
||||||
|
isNotified = false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener('keydown', handleKeyDown);
|
window.addEventListener('keydown', handleKeyDown);
|
||||||
|
window.addEventListener('keyup', handleKeyUp);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue