diff --git a/packages/devops-admin/src/components/FunctionEditor/index.vue b/packages/devops-admin/src/components/FunctionEditor/index.vue index a0ced5b706..ab81d2d52c 100644 --- a/packages/devops-admin/src/components/FunctionEditor/index.vue +++ b/packages/devops-admin/src/components/FunctionEditor/index.vue @@ -72,12 +72,6 @@ export default { // 加载必要的类型文件 autoImportTypings.loadDefaults() - - // listen Ctrl+S - document.addEventListener('keydown', this.save, false) - }, - beforeDestroy() { - document.removeEventListener('keydown', this.save, false) }, methods: { getValue() { @@ -86,13 +80,7 @@ export default { /** * 当代码变化时,尝试解析是否有新 import 的依赖,并加载其类型文件 */ - parseImports: _.debounce(autoImportTypings.parse, 2000, { leading: true }).bind(autoImportTypings), - save(e) { - if ((e.ctrlKey || e.metaKey) && e.key === 's') { - this.$emit('save', this.getValue()) - e.preventDefault() - } - } + parseImports: _.debounce(autoImportTypings.parse, 2000, { leading: true }).bind(autoImportTypings) } } diff --git a/packages/devops-admin/src/views/development/function.vue b/packages/devops-admin/src/views/development/function.vue index b3f478cbcf..b2f064f6f0 100644 --- a/packages/devops-admin/src/views/development/function.vue +++ b/packages/devops-admin/src/views/development/function.vue @@ -25,7 +25,7 @@
- +
@@ -172,10 +172,10 @@ export default { this.getLatestLogs() this.setTagViewTitle() }, - mounted() { + activated() { document.addEventListener('keydown', this.bindShortKey, false) }, - beforeDestroy() { + deactivated() { document.removeEventListener('keydown', this.bindShortKey, false) }, methods: { @@ -336,13 +336,20 @@ export default { return param }, // 快捷键绑定 - bindShortKey(e) { - // Ctrl + b 为调试运行,并弹出 + async bindShortKey(e) { + // Ctrl + s 为保存 + if ((e.ctrlKey || e.metaKey) && e.key === 's') { + this.updateFunc() + e.preventDefault() + } + + // Ctrl + j 弹出/隐藏调试框 if ((e.ctrlKey || e.metaKey) && e.key === 'j') { this.showDebugPanel = !this.showDebugPanel e.preventDefault() } + // Ctrol + 为调试运行,并弹出调试框 if ((e.ctrlKey || e.metaKey) && e.key === 'b') { this.showDebugPanel = true this.launch()