feat: allow multiple terminal tabs per connection

This commit is contained in:
liumangmang
2026-03-26 18:04:39 +08:00
parent 93cc13ddd0
commit 78e6fc3e47
5 changed files with 219 additions and 19 deletions

View File

@@ -19,19 +19,21 @@ export const useTerminalTabsStore = defineStore('terminalTabs', () => {
return `tab-${Date.now()}-${Math.random().toString(16).slice(2)}`
}
function openOrFocus(connection: Connection) {
// 检查是否已存在该连接的标签页
const existing = tabs.value.find(t => t.connectionId === connection.id)
if (existing) {
activate(existing.id)
return existing.id
function getTabTitle(connection: Connection) {
const sameConnectionCount = tabs.value.filter(t => t.connectionId === connection.id).length
if (sameConnectionCount === 0) {
return connection.name
}
// 创建新标签页
return `${connection.name} (${sameConnectionCount + 1})`
}
function openTab(connection: Connection) {
const newTab: TerminalTab = {
id: generateTabId(),
connectionId: connection.id,
title: connection.name,
title: getTabTitle(connection),
active: true,
}
@@ -67,7 +69,7 @@ export const useTerminalTabsStore = defineStore('terminalTabs', () => {
tabs,
activeTabId,
activeTab,
openOrFocus,
openTab,
activate,
close,
}

View File

@@ -91,9 +91,9 @@ async function handleDelete(conn: Connection) {
await store.deleteConnection(conn.id)
}
function openTerminal(conn: Connection) {
tabsStore.openOrFocus(conn)
router.push('/terminal')
function openTerminal(conn: Connection) {
tabsStore.openTab(conn)
router.push('/terminal')
}
function openSftp(conn: Connection) {

View File

@@ -17,13 +17,13 @@ onMounted(async () => {
await connectionsStore.fetchConnections()
}
const conn = connectionsStore.getConnection(connectionId.value)
if (conn) {
// 打开或聚焦该连接的标签页
tabsStore.openOrFocus(conn)
// 跳转到工作区
router.replace('/terminal')
} else {
const conn = connectionsStore.getConnection(connectionId.value)
if (conn) {
// 打开新的终端标签页
tabsStore.openTab(conn)
// 跳转到工作区
router.replace('/terminal')
} else {
// 连接不存在,返回连接列表
router.replace('/connections')
}