);
});
},
immediate: true,
},
},
methods: {
handleFocus() {
if (!this.list.length) this.focus = true;
},
handleDeleteKey(index) {
this.list.splice(index, 1);
},
handleKeydown(e) {
const { altKey, ctrlKey, shiftKey, key, code } = e;
if (!CODE_CONTROL.includes(key)) {
if (!this.keyRange.includes(code)) return;
let controlKey = “”;
[
{ key: altKey, text: “Alt” },
{ key: ctrlKey, text: “Ctrl” },
{ key: shiftKey, text: “Shift” },
].forEach((curKey) => {
if (curKey.key) {
if (controlKey) controlKey += “+”;
controlKey += curKey.text;
}
});
if (key) {
if (controlKey) controlKey += “+”;
controlKey += key.toUpperCase();
}
this.addHotkey({
text: controlKey,
controlKey: { altKey, ctrlKey, shiftKey, key, code },
});
}
e.preventDefault();
},
addHotkey(data) {
if (this.list.length && this.list.some((item) => data.text === item.text))
return;
if (
this.list.length &&
this.list.length.toString() === this.max.toString()
)
return;
this.list.push(data);
},
},
};