import { useState } from 'react' import { X, Zap, Globe, User, Lock, ArrowRight, AlertCircle } from 'lucide-react' import { useTabStore } from '../stores/tabStore' interface QuickConnectDialogProps { isOpen: boolean onClose: () => void } export default function QuickConnectDialog({ isOpen, onClose }: QuickConnectDialogProps) { const { addTab } = useTabStore() const [formData, setFormData] = useState({ host: '', port: 22, username: '', password: '', }) const [isConnecting, setIsConnecting] = useState(false) const [error, setError] = useState(null) if (!isOpen) return null const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() setIsConnecting(true) setError(null) try { // 快速连接只需添加标签,真正的连接由 TerminalView 处理 // 这样可以确保每个标签独立管理自己的连接生命周期 // 1. 打开新标签页,传递连接配置 // TerminalView 会负责创建实际的 SSH 连接 addTab({ title: `${formData.username}@${formData.host}`, type: 'terminal', connectionConfig: { host: formData.host, port: formData.port, username: formData.username, password: formData.password || undefined, }, }) // 2. 关闭对话框 onClose() // 3. 重置表单 setFormData({ host: '', port: 22, username: '', password: '', }) } catch (err: unknown) { setError((err instanceof Error ? err.message : String(err)) || '连接失败') } finally { setIsConnecting(false) } } return (
{/* Header */}

快速连接

临时连接到服务器

{/* Form */}
{/* Host and Port */}
setFormData({ ...formData, host: e.target.value })} placeholder="192.168.1.1" className="w-full px-3 py-2 bg-dark-900 border border-dark-700 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-accent-blue" />
setFormData({ ...formData, port: parseInt(e.target.value) })} placeholder="22" className="w-full px-3 py-2 bg-dark-900 border border-dark-700 rounded-lg text-gray-200 focus:outline-none focus:border-accent-blue" />
{/* Username */}
setFormData({ ...formData, username: e.target.value })} placeholder="root" className="w-full px-3 py-2 bg-dark-900 border border-dark-700 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-accent-blue" />
{/* Password */}
setFormData({ ...formData, password: e.target.value })} placeholder="••••••••" className="w-full px-3 py-2 bg-dark-900 border border-dark-700 rounded-lg text-gray-200 placeholder-gray-600 focus:outline-none focus:border-accent-blue" />
{/* Error message */} {error && (
{error}
)} {/* Hint */}

快速连接不会保存会话信息。如需保存,请使用"新建会话"。

{/* Actions */}
) }