From d8e3f9dfd996be92289f0fa22aeade744bf7676b Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Wed, 28 Aug 2024 16:11:25 +0200 Subject: [PATCH 1/3] feat: apply mixin --- src/boot/mainShortcutMixin.js | 29 +++++++++++++++++++++++++++++ src/boot/quasar.js | 2 ++ src/router/modules/route.js | 3 ++- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/boot/mainShortcutMixin.js diff --git a/src/boot/mainShortcutMixin.js b/src/boot/mainShortcutMixin.js new file mode 100644 index 000000000..4f60050c4 --- /dev/null +++ b/src/boot/mainShortcutMixin.js @@ -0,0 +1,29 @@ +import routes from 'src/router/modules'; + +import { useRouter } from 'vue-router'; +export default { + mounted: function () { + const router = useRouter(); + const keyBindingMap = routes + .filter((route) => route.meta.keyBinding) + .reduce((map, route) => { + map[route.meta.keyBinding.toLowerCase()] = route.path; + return map; + }, {}); + const handleKeyDown = (event) => { + const { ctrlKey, altKey, key } = event; + event.preventDefault(); + + const combination = `${ctrlKey ? 'Ctrl+' : ''}${ + altKey ? 'Alt+' : '' + }${key.toLowerCase()}`; + console.log(ctrlKey, altKey, key, combination); + + if (ctrlKey && altKey && keyBindingMap[key]) { + router.push(keyBindingMap[key]); + } + }; + + window.addEventListener('keydown', handleKeyDown); + }, +}; diff --git a/src/boot/quasar.js b/src/boot/quasar.js index a8d9b7ad9..caf573ac7 100644 --- a/src/boot/quasar.js +++ b/src/boot/quasar.js @@ -1,6 +1,8 @@ import { boot } from 'quasar/wrappers'; import qFormMixin from './qformMixin'; +import mainShortcutMixin from './mainShortcutMixin'; export default boot(({ app }) => { app.mixin(qFormMixin); + app.mixin(mainShortcutMixin); }); diff --git a/src/router/modules/route.js b/src/router/modules/route.js index 3c5c860cf..148975761 100644 --- a/src/router/modules/route.js +++ b/src/router/modules/route.js @@ -5,8 +5,9 @@ export default { name: 'Route', meta: { title: 'routes', - icon: 'vn:delivery', + icon: 'vn:delivesry', moduleName: 'Route', + keyBinding: 'r', }, component: RouterView, redirect: { name: 'RouteMain' }, -- 2.40.1 From d3ab56184be889e4cae187bd1a60f0a65f199ce5 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 2 Sep 2024 09:34:33 +0200 Subject: [PATCH 2/3] perf: remove console.log --- src/boot/mainShortcutMixin.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/boot/mainShortcutMixin.js b/src/boot/mainShortcutMixin.js index 4f60050c4..c4d37fd73 100644 --- a/src/boot/mainShortcutMixin.js +++ b/src/boot/mainShortcutMixin.js @@ -13,12 +13,6 @@ export default { const handleKeyDown = (event) => { const { ctrlKey, altKey, key } = event; event.preventDefault(); - - const combination = `${ctrlKey ? 'Ctrl+' : ''}${ - altKey ? 'Alt+' : '' - }${key.toLowerCase()}`; - console.log(ctrlKey, altKey, key, combination); - if (ctrlKey && altKey && keyBindingMap[key]) { router.push(keyBindingMap[key]); } -- 2.40.1 From c51af96ca7dd84aea3bf5c767deb45d0ebe21843 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Mon, 2 Sep 2024 12:56:44 +0000 Subject: [PATCH 3/3] fix: module icon --- src/router/modules/route.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/router/modules/route.js b/src/router/modules/route.js index 148975761..955fc9098 100644 --- a/src/router/modules/route.js +++ b/src/router/modules/route.js @@ -5,7 +5,7 @@ export default { name: 'Route', meta: { title: 'routes', - icon: 'vn:delivesry', + icon: 'vn:delivery', moduleName: 'Route', keyBinding: 'r', }, -- 2.40.1