新增 listenKeydown

This commit is contained in:
fofolee 2022-04-23 00:34:26 +08:00
parent f99123518a
commit e260d14a36
2 changed files with 31 additions and 6 deletions

View File

@ -55,7 +55,8 @@ export default {
runResult: "",
runResultStatus: true,
subInputValue: "",
listener: null,
subInputListener: null,
quickcommandListener: null,
history: [],
historyIdx: null,
enableHtml: false,
@ -171,7 +172,7 @@ export default {
setTimeout(() => {
if (this.subInputValue) querySubInput();
}, 100);
this.listener = (event) => {
this.subInputListener = (event) => {
event.preventDefault();
switch (event.keyCode) {
case 13:
@ -193,7 +194,7 @@ export default {
break;
}
};
document.addEventListener("keydown", this.listener, true);
document.addEventListener("keydown", this.subInputListener, true);
},
// payload
async getTempPayload(currentCommand) {
@ -243,15 +244,24 @@ export default {
}
quickcommand.closeWaitBtn?.();
quickcommand.closeWaitBtn = () => {};
if (!!this.listener) {
if (!!this.subInputListener) {
this.subInputValue = "";
utools.removeSubInput();
document.removeEventListener("keydown", this.listener, true);
document.removeEventListener("keydown", this.subInputListener, true);
}
if (!!this.quickcommandListener) {
document.removeEventListener("keydown", this.quickcommandListener);
}
},
},
unmounted() {
this.stopRun();
},
mounted() {
quickcommand.listenKeydown = (callback) => {
this.quickcommandListener = callback;
document.addEventListener("keydown", callback);
};
},
};
</script>

View File

@ -170,13 +170,28 @@ interface quickcommandApi {
* @param callback
* @param label
*/
showWaitButton(callback, label?: string): void;
showWaitButton(callback: () => void, label?: string): void;
/**
*
*/
closeWaitBtn(): void;
/**
*
*
* ```js
* quickcommand.listenKeydown(e=>{
* if(e.key === 'c' && e.ctrlKey){
* console.log("取消")
* }
* })
* ```
*
* @param callback
*/
listenKeydown(callback: (event) => void): void;
/**
*
* @param ms