From ec0d68377eb33ef8ef9fdc9ac85f75c3cd5c651c Mon Sep 17 00:00:00 2001 From: chaoszhu Date: Mon, 21 Jul 2025 21:18:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BB=9F=E4=B8=80=E6=89=A7=E8=A1=8C?= =?UTF-8?q?=E5=A4=96=E9=83=A8=E8=84=9A=E6=9C=AC=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/terminal/components/footer-bar.vue | 4 ++-- web/src/views/terminal/components/sftp-v2.vue | 4 ++-- .../terminal/components/terminal-wrapper.vue | 20 ++++++++++++------- .../views/terminal/components/terminal.vue | 6 +++++- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/web/src/views/terminal/components/footer-bar.vue b/web/src/views/terminal/components/footer-bar.vue index 9787ddb..649c349 100644 --- a/web/src/views/terminal/components/footer-bar.vue +++ b/web/src/views/terminal/components/footer-bar.vue @@ -33,7 +33,7 @@ const props = defineProps({ } }) -const emit = defineEmits(['resize', 'exec-command', 'height-change',]) +const emit = defineEmits(['resize', 'exec-script', 'height-change',]) // 拖拽相关状态 const isResizing = ref(false) @@ -73,7 +73,7 @@ const stopResize = () => { } const execCommand = (command) => { - emit('exec-command', command, 'script') + emit('exec-script', command) } // 清理事件监听 diff --git a/web/src/views/terminal/components/sftp-v2.vue b/web/src/views/terminal/components/sftp-v2.vue index 1691029..a97cee3 100644 --- a/web/src/views/terminal/components/sftp-v2.vue +++ b/web/src/views/terminal/components/sftp-v2.vue @@ -542,7 +542,7 @@ import { useContextMenu } from '@/composables/useContextMenu' import TextEditor from '@/components/text-editor/index.vue' import ImagePreview from '@/components/image-preview/index.vue' -const emit = defineEmits(['exec-command', ]) +const emit = defineEmits(['exec-script', ]) const props = defineProps({ hostId: { @@ -1594,7 +1594,7 @@ const onRowContextMenu = (row, _column, event) => { items.push({ label: '发送cd指令到终端', onClick: () => { - emit('exec-command', cdCommand, 'script') + emit('exec-script', cdCommand) } }) } diff --git a/web/src/views/terminal/components/terminal-wrapper.vue b/web/src/views/terminal/components/terminal-wrapper.vue index 7c15ed1..26aa5b3 100644 --- a/web/src/views/terminal/components/terminal-wrapper.vue +++ b/web/src/views/terminal/components/terminal-wrapper.vue @@ -333,13 +333,13 @@ >
@@ -352,7 +352,7 @@ :show="showFooterBar" :height="footerBarHeight" @resize="resizeTerminal" - @exec-command="handleInputCommand" + @exec-script="handleExecScript" @height-change="handleFooterBarHeightChange" /> @@ -698,13 +698,19 @@ const handleLinkHost = (hostDescObj) => { }, 100) } +// scriptDescObj: 脚本库对象或脚本命令 const handleExecScript = async (scriptDescObj) => { if (!scriptDescObj) return // clearCheckedNodes二次触发change事件 - const id = Array.isArray(scriptDescObj) ? scriptDescObj.slice(-1)[0] : scriptDescObj.id - const script = scriptList.value.find((item) => item.id === id) - if (!script) return $message.warning('未找到对应的脚本') + let command = '' + const id = Array.isArray(scriptDescObj) ? scriptDescObj.slice(-1)[0] : scriptDescObj?.id + if (id) { + const script = scriptList.value.find((item) => item.id === id) + command = script?.command + } else { + command = scriptDescObj + } + if (!command) return $message.warning('未找到对应的脚本') - const command = script.command if (!isSyncAllSession.value) { // 不同步时,使用 handleInputCommand(会处理分屏同步) await handleInputCommand(command, 'script') diff --git a/web/src/views/terminal/components/terminal.vue b/web/src/views/terminal/components/terminal.vue index 27aa77f..39bb644 100644 --- a/web/src/views/terminal/components/terminal.vue +++ b/web/src/views/terminal/components/terminal.vue @@ -300,7 +300,10 @@ const createLocalTerminal = () => { !isMobileScreen.value && terminalInstance.loadAddon(canvasAddon) terminalInstance.writeln('\x1b[1;32mWelcome to EasyNode terminal\x1b[0m.') terminalInstance.writeln('\x1b[1;32mAn experimental Web-SSH Terminal\x1b[0m.') - if (props.autoFocus) terminalInstance.focus() + if (props.autoFocus) { + terminalInstance.focus() + emit('tab-focus', uid) + } onFindText() onWebLinks() onResize() @@ -668,6 +671,7 @@ const focusTab = () => { term.value.blur() setTimeout(() => { term.value.focus() + emit('tab-focus', uid) }, 200) }