feat: CSV/云平台导入添加SSH端口(默认22) + 凭证关联下拉
- CSV模板新增port列, 连接方式改为SSH端口输入(默认22) - 云平台导入新增SSH端口配置 + 凭证下拉选择 - 移除冗余的连接方式(密码/密钥)选择 → 凭证下拉统一管理 - ExcelServerImport: template含port列, resetState包含新字段
This commit is contained in:
1 parent
cbf4334f7f
commit
11e8c24f37
2 files changed
+75
-35
No files matched your search
@@ -57,6 +57,9 @@ export function CloudServerImport({ open, onClose }: CloudServerImportProps) {
|
||||
const [discoverErrors, setDiscoverErrors] = useState<string[]>([]);
|
||||
const [isImporting, setIsImporting] = useState(false);
|
||||
const [importResult, setImportResult] = useState<{ imported: number; skipped: number } | null>(null);
|
||||
const [defaultSshPort, setDefaultSshPort] = useState('22');
|
||||
const [credentials, setCredentials] = useState<any[]>([]);
|
||||
const [selectedCredentialId, setSelectedCredentialId] = useState<string>('');
|
||||
|
||||
const loadAccounts = async () => {
|
||||
try {
|
||||
@@ -68,7 +71,13 @@ export function CloudServerImport({ open, onClose }: CloudServerImportProps) {
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (open) loadAccounts();
|
||||
if (open) {
|
||||
loadAccounts();
|
||||
import('@/services/api').then(({ credentialApi }) => {
|
||||
credentialApi.list().then((res: any) => setCredentials(res?.list || []))
|
||||
.catch(() => setCredentials([]));
|
||||
});
|
||||
}
|
||||
}, [open]);
|
||||
|
||||
const filteredAccounts = cloudAccounts.filter(
|
||||
@@ -140,7 +149,10 @@ export function CloudServerImport({ open, onClose }: CloudServerImportProps) {
|
||||
setIsImporting(true);
|
||||
try {
|
||||
const instancesToImport = cloudServers.filter(s => selectedServers.includes(s.instance_id));
|
||||
const res: any = await cloudApi.importInstances(selectedAccount.id, instancesToImport);
|
||||
const res: any = await cloudApi.importInstances(selectedAccount.id, instancesToImport, {
|
||||
default_port: Number(defaultSshPort) || 22,
|
||||
credential_id: selectedCredentialId ? Number(selectedCredentialId) : undefined,
|
||||
});
|
||||
setImportResult(res || { imported: 0, skipped: 0 });
|
||||
} catch (e: any) {
|
||||
console.error('导入失败:', e);
|
||||
@@ -199,6 +211,8 @@ export function CloudServerImport({ open, onClose }: CloudServerImportProps) {
|
||||
setRegionSearch('');
|
||||
setDiscoverErrors([]);
|
||||
setImportResult(null);
|
||||
setDefaultSshPort('22');
|
||||
setSelectedCredentialId('');
|
||||
};
|
||||
|
||||
const filteredRegions = regions.filter(r =>
|
||||
@@ -545,6 +559,43 @@ export function CloudServerImport({ open, onClose }: CloudServerImportProps) {
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* SSH 端口 + 凭证关联 */}
|
||||
{cloudServers.length > 0 && selectedServers.length > 0 && (
|
||||
<div className="grid grid-cols-2 gap-4 p-4 rounded-lg bg-[var(--dg-bg-secondary)] border border-[var(--dg-border)]">
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-[var(--dg-text-secondary)] mb-1">
|
||||
SSH 端口
|
||||
<span className="text-[var(--dg-text-muted)] ml-1">(导入时统一设置)</span>
|
||||
</label>
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="22"
|
||||
value={defaultSshPort}
|
||||
onChange={(e) => setDefaultSshPort(e.target.value)}
|
||||
className="w-32 bg-[var(--dg-bg-tertiary)] border-[var(--dg-border)] text-[var(--dg-text-primary)]"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label className="block text-xs font-medium text-[var(--dg-text-secondary)] mb-1">
|
||||
关联凭证
|
||||
<span className="text-[var(--dg-text-muted)] ml-1">(可选,用于SSH远程管理)</span>
|
||||
</label>
|
||||
<select
|
||||
value={selectedCredentialId}
|
||||
onChange={(e) => setSelectedCredentialId(e.target.value)}
|
||||
className="w-full px-3 py-1.5 bg-[var(--dg-bg-tertiary)] border border-[var(--dg-border)] rounded-md text-[var(--dg-text-primary)] text-xs"
|
||||
>
|
||||
<option value="">不使用凭据</option>
|
||||
{credentials.map((c: any) => (
|
||||
<option key={c.id} value={String(c.id)}>
|
||||
{c.type === 'ssh_key' ? '🔑' : '🔒'} {c.name}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
Reference in new issue
Block a user