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 { useRouter } from 'vue-router';
|
||||
|
||||
let isNotified = false;
|
||||
|
||||
export default {
|
||||
mounted: function () {
|
||||
created: function () {
|
||||
const router = useRouter();
|
||||
const keyBindingMap = routes
|
||||
.filter((route) => route.meta.keyBinding)
|
||||
|
@ -10,14 +12,27 @@ export default {
|
|||
map[route.meta.keyBinding.toLowerCase()] = route.path;
|
||||
return map;
|
||||
}, {});
|
||||
|
||||
const handleKeyDown = (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]);
|
||||
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('keyup', handleKeyUp);
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue