From 9b79ebb6e61ed0e9698c346d8280ac5c30bed687 Mon Sep 17 00:00:00 2001 From: lijiahangmax Date: Tue, 6 Feb 2024 11:52:02 +0800 Subject: [PATCH] =?UTF-8?q?:hammer:=20=E6=B7=BB=E5=8A=A0=20sftp=20?= =?UTF-8?q?=E4=BC=9A=E8=AF=9D=E7=B1=BB=E5=9E=8B.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/store/modules/terminal/index.ts | 17 ++-- .../command-snippet-list-drawer.vue | 4 +- .../components/command-snippet-list-item.vue | 4 +- .../components/layout/main-content.vue | 6 +- .../components/layout/right-sidebar.vue | 4 +- .../components/layout/terminal-panel.vue | 9 +- .../components/ssh/ssh-context-menu.vue | 4 +- .../host/terminal/components/ssh/ssh-view.vue | 6 +- .../host/terminal/handler/sftp-session.ts | 41 +++++++++ ...sion-handler.ts => ssh-session-handler.ts} | 14 +-- .../{terminal-session.ts => ssh-session.ts} | 20 ++--- .../handler/terminal-output-processor.ts | 88 +++++++++++++------ .../handler/terminal-session-manager.ts | 47 +++++++--- .../host/terminal/types/terminal.type.ts | 58 +++++++----- 14 files changed, 219 insertions(+), 103 deletions(-) create mode 100644 orion-ops-ui/src/views/host/terminal/handler/sftp-session.ts rename orion-ops-ui/src/views/host/terminal/handler/{terminal-session-handler.ts => ssh-session-handler.ts} (95%) rename orion-ops-ui/src/views/host/terminal/handler/{terminal-session.ts => ssh-session.ts} (91%) diff --git a/orion-ops-ui/src/store/modules/terminal/index.ts b/orion-ops-ui/src/store/modules/terminal/index.ts index f8d33044..89e1a6cc 100644 --- a/orion-ops-ui/src/store/modules/terminal/index.ts +++ b/orion-ops-ui/src/store/modules/terminal/index.ts @@ -8,7 +8,7 @@ import type { TerminalShortcutSetting, TerminalState } from './types'; -import type { PanelSessionTab, TerminalPanelTabItem } from '@/views/host/terminal/types/terminal.type'; +import type { ISshSession, PanelSessionTab, TerminalPanelTabItem } from '@/views/host/terminal/types/terminal.type'; import type { AuthorizedHostQueryResponse } from '@/api/asset/asset-authorized-data'; import { getCurrentAuthorizedHost } from '@/api/asset/asset-authorized-data'; import type { HostQueryResponse } from '@/api/asset/host'; @@ -64,7 +64,8 @@ export default defineStore('terminal', { } as TerminalShortcutSetting, }, hosts: {} as AuthorizedHostQueryResponse, - tabManager: new TerminalTabManager(TerminalTabs.NEW_CONNECTION), + // fixme + tabManager: new TerminalTabManager(TerminalTabs.TERMINAL_PANEL), panelManager: new TerminalPanelManager(), sessionManager: new TerminalSessionManager() }), @@ -173,8 +174,8 @@ export default defineStore('terminal', { } }, - // 检查当前是否为终端页面 并且获取当前终端会话 - getAndCheckCurrentTerminalSession(tips: boolean = true) { + // 检查当前是否为终端页面 并且获取当前 ssh 会话 + getAndCheckCurrentSshSession(tips: boolean = true) { // 获取当前 activeTab const activeTab = this.tabManager.active; if (activeTab !== TerminalTabs.TERMINAL_PANEL.key) { @@ -184,15 +185,15 @@ export default defineStore('terminal', { return; } // 获取当前会话 - const session = this.getCurrentTerminalSession(); + const session = this.getCurrentSshSession(); if (!session && tips) { Message.warning('请打开终端'); } return session; }, - // 获取当前终端会话 - getCurrentTerminalSession() { + // 获取当前 ssh 会话 + getCurrentSshSession() { // 获取面板会话 const sessionTab = this.panelManager .getCurrentPanel() @@ -201,7 +202,7 @@ export default defineStore('terminal', { return; } // 获取会话 - return this.sessionManager.getSession(sessionTab.key); + return this.sessionManager.getSession(sessionTab.key); }, }, diff --git a/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-drawer.vue b/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-drawer.vue index 11634f17..9c63fd91 100644 --- a/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-drawer.vue +++ b/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-drawer.vue @@ -83,7 +83,7 @@ const { loading, setLoading } = useLoading(); const { visible, setVisible } = useVisible(); - const { getCurrentTerminalSession } = useTerminalStore(); + const { getCurrentSshSession } = useTerminalStore(); const cacheStore = useCacheStore(); const formDrawer = ref(); @@ -267,7 +267,7 @@ // 关闭回调 const onClose = () => { // 聚焦终端 - getCurrentTerminalSession()?.focus(); + getCurrentSshSession()?.focus(); }; diff --git a/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-item.vue b/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-item.vue index 3fb5be3c..c9e71ccb 100644 --- a/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-item.vue +++ b/orion-ops-ui/src/views/host/command-snippet/components/command-snippet-list-item.vue @@ -125,7 +125,7 @@ }>(); const { copy } = useCopy(); - const { getAndCheckCurrentTerminalSession } = useTerminalStore(); + const { getAndCheckCurrentSshSession } = useTerminalStore(); let clickCount = 0; @@ -184,7 +184,7 @@ // 写入命令 const write = (command: string) => { - const handler = getAndCheckCurrentTerminalSession()?.handler; + const handler = getAndCheckCurrentSshSession()?.handler; if (handler && handler.enabledStatus('checkAppendMissing')) { handler.checkAppendMissing(command); } diff --git a/orion-ops-ui/src/views/host/terminal/components/layout/main-content.vue b/orion-ops-ui/src/views/host/terminal/components/layout/main-content.vue index e21ada5b..8855850d 100644 --- a/orion-ops-ui/src/views/host/terminal/components/layout/main-content.vue +++ b/orion-ops-ui/src/views/host/terminal/components/layout/main-content.vue @@ -45,17 +45,17 @@ import TerminalShortcutSetting from '../setting/shortcut/terminal-shortcut-setting.vue'; import TerminalPanelsView from '@/views/host/terminal/components/layout/terminal-panels-view.vue'; - const { preference, tabManager, getCurrentTerminalSession } = useTerminalStore(); + const { preference, tabManager, getCurrentSshSession } = useTerminalStore(); // 监听 tab 切换 watch(() => tabManager.active, (active, before) => { // 失焦 tab if (before === TerminalTabs.TERMINAL_PANEL.key) { - getCurrentTerminalSession()?.blur(); + getCurrentSshSession()?.blur(); } // 聚焦 tab if (active === TerminalTabs.TERMINAL_PANEL.key) { - getCurrentTerminalSession()?.focus(); + getCurrentSshSession()?.focus(); } // 修改标题 document.title = Object.values(TerminalTabs) diff --git a/orion-ops-ui/src/views/host/terminal/components/layout/right-sidebar.vue b/orion-ops-ui/src/views/host/terminal/components/layout/right-sidebar.vue index d8084384..4a8e942f 100644 --- a/orion-ops-ui/src/views/host/terminal/components/layout/right-sidebar.vue +++ b/orion-ops-ui/src/views/host/terminal/components/layout/right-sidebar.vue @@ -28,7 +28,7 @@ const emits = defineEmits(['openTransfer']); - const { getAndCheckCurrentTerminalSession } = useTerminalStore(); + const { getAndCheckCurrentSshSession } = useTerminalStore(); const snippetRef = ref(); @@ -59,7 +59,7 @@ // 终端截屏 const screenshot = () => { - const handler = getAndCheckCurrentTerminalSession()?.handler; + const handler = getAndCheckCurrentSshSession()?.handler; if (handler && handler.enabledStatus('screenshot')) { handler.screenshot(); } diff --git a/orion-ops-ui/src/views/host/terminal/components/layout/terminal-panel.vue b/orion-ops-ui/src/views/host/terminal/components/layout/terminal-panel.vue index 56534ca4..ee88e1d2 100644 --- a/orion-ops-ui/src/views/host/terminal/components/layout/terminal-panel.vue +++ b/orion-ops-ui/src/views/host/terminal/components/layout/terminal-panel.vue @@ -44,7 +44,7 @@