From 164cc343d73e7e1325832b5a75e4ce40532d3b32 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Thu, 1 May 2025 17:54:08 +0800 Subject: [PATCH] update --- .../src/repositories/connection.repository.ts | 7 ++-- .../src/components/AddConnectionForm.vue | 33 ++++++++++++------- .../src/components/SshKeyManagementModal.vue | 6 ++-- .../src/components/SshKeySelector.vue | 15 +++++++++ .../frontend/src/stores/connections.store.ts | 1 + 5 files changed, 45 insertions(+), 17 deletions(-) diff --git a/packages/backend/src/repositories/connection.repository.ts b/packages/backend/src/repositories/connection.repository.ts index 017893a..e5e5159 100644 --- a/packages/backend/src/repositories/connection.repository.ts +++ b/packages/backend/src/repositories/connection.repository.ts @@ -16,14 +16,15 @@ interface ConnectionBase { created_at: number; updated_at: number; last_connected_at: number | null; + ssh_key_id?: number | null; // +++ Add ssh_key_id here as well +++ } -// ConnectionWithTagsRow implicitly includes 'type' via ConnectionBase +// ConnectionWithTagsRow implicitly includes 'type' and 'ssh_key_id' via ConnectionBase interface ConnectionWithTagsRow extends ConnectionBase { tag_ids_str: string | null; } -// ConnectionWithTags implicitly includes 'type' via ConnectionBase +// ConnectionWithTags implicitly includes 'type' and 'ssh_key_id' via ConnectionBase export interface ConnectionWithTags extends ConnectionBase { tag_ids: number[]; } @@ -60,7 +61,7 @@ interface FullConnectionDbRow extends FullConnectionData { export const findAllConnectionsWithTags = async (): Promise => { const sql = ` SELECT - c.id, c.name, c.type, c.host, c.port, c.username, c.auth_method, c.proxy_id, + c.id, c.name, c.type, c.host, c.port, c.username, c.auth_method, c.proxy_id, c.ssh_key_id, -- +++ Select ssh_key_id +++ c.created_at, c.updated_at, c.last_connected_at, GROUP_CONCAT(ct.tag_id) as tag_ids_str FROM connections c diff --git a/packages/frontend/src/components/AddConnectionForm.vue b/packages/frontend/src/components/AddConnectionForm.vue index 73c6c22..bd37baa 100644 --- a/packages/frontend/src/components/AddConnectionForm.vue +++ b/packages/frontend/src/components/AddConnectionForm.vue @@ -85,18 +85,29 @@ watch(() => props.connectionToEdit, (newVal) => { formData.username = newVal.username; formData.auth_method = newVal.auth_method; formData.proxy_id = newVal.proxy_id ?? null; - formData.tag_ids = newVal.tag_ids ? [...newVal.tag_ids] : []; // 填充 tag_ids (深拷贝) - // 清空敏感字段 - formData.password = ''; - formData.private_key = ''; - formData.passphrase = ''; - } else { - // 添加模式:重置表单 - Object.assign(formData, initialFormData); + formData.tag_ids = newVal.tag_ids ? [...newVal.tag_ids] : []; // 填充 tag_ids (深拷贝) + + // +++ 填充 selected_ssh_key_id (如果认证方式是 key) +++ + if (newVal.auth_method === 'key') { + formData.selected_ssh_key_id = newVal.ssh_key_id ?? null; + } else { + formData.selected_ssh_key_id = null; // 清空,以防之前是 key + } + + // 清空敏感字段 (密码和直接输入的密钥) + formData.password = ''; + formData.private_key = ''; // 即使是 key 认证,编辑时也不显示旧的直接输入密钥 + formData.passphrase = ''; // 同上 + + } else { + // 添加模式:重置表单 + Object.assign(formData, initialFormData); + formData.tag_ids = []; // 确保 tag_ids 也被重置为空数组 + formData.selected_ssh_key_id = null; // 确保添加模式下也重置 } }, { immediate: true }); -// 组件挂载时获取代理和标签列表 +// 组件挂载时获取代理、标签和 SSH 密钥列表 onMounted(() => { proxiesStore.fetchProxies(); tagsStore.fetchTags(); // 获取标签列表 @@ -434,9 +445,9 @@ const testButtonText = computed(() => { -
+
diff --git a/packages/frontend/src/components/SshKeyManagementModal.vue b/packages/frontend/src/components/SshKeyManagementModal.vue index 45d6a56..154212b 100644 --- a/packages/frontend/src/components/SshKeyManagementModal.vue +++ b/packages/frontend/src/components/SshKeyManagementModal.vue @@ -129,7 +129,7 @@ const cancelForm = () => { @@ -193,13 +193,13 @@ const cancelForm = () => { - {{ t('sshKeys.modal.keyUpdateNote') }} +
- {{ t('sshKeys.modal.passphraseUpdateNote') }} +
diff --git a/packages/frontend/src/components/SshKeySelector.vue b/packages/frontend/src/components/SshKeySelector.vue index 9fd4afc..4b8f344 100644 --- a/packages/frontend/src/components/SshKeySelector.vue +++ b/packages/frontend/src/components/SshKeySelector.vue @@ -35,6 +35,21 @@ watch(selectedKeyId, (newVal) => { } }); +// Watch for changes in the keys list itself +watch(keys, (newKeys) => { + // If a key ID is selected (from props/v-model) + if (selectedKeyId.value !== null) { + // Check if that ID still exists in the newly loaded/updated list + const keyExists = newKeys.some(key => key.id === selectedKeyId.value); + if (!keyExists) { + // If the selected key ID is no longer valid (e.g., deleted), reset the selection + console.warn(`[SshKeySelector] Selected key ID ${selectedKeyId.value} not found in updated list. Resetting.`); + selectedKeyId.value = null; // This will trigger the watcher above to emit update:modelValue + } + // If the key *does* exist, the v-model binding on