|
@@ -0,0 +1,31 @@
|
|
|
+let registerShortcuts = null
|
|
|
+let shortcutFunction = null
|
|
|
+
|
|
|
+export const xcHotKey = (keyList) => {
|
|
|
+ registerShortcuts = keyList
|
|
|
+ shortcutFunction = document.onkeydown = function (event) {
|
|
|
+ shortcutTrigger(event)
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+export const logoutShortcut = () => {
|
|
|
+ shortcutFunction = null
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 快捷键触发事件
|
|
|
+ * @param event
|
|
|
+ */
|
|
|
+const shortcutTrigger = (event) => {
|
|
|
+ for (let listKey in registerShortcuts) {
|
|
|
+ let data = registerShortcuts[listKey]
|
|
|
+ for (let key in data) {
|
|
|
+ // 同时按下
|
|
|
+ let pressSimultaneously = listKey + 'Key'
|
|
|
+ if (event[pressSimultaneously] && event.key === key) {
|
|
|
+ event.returnValue = false
|
|
|
+ data[key]()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|