diff --git a/packages/frontend/src/components/AddConnectionForm.vue b/packages/frontend/src/components/AddConnectionForm.vue index 0407fe1..8e23d8c 100644 --- a/packages/frontend/src/components/AddConnectionForm.vue +++ b/packages/frontend/src/components/AddConnectionForm.vue @@ -11,7 +11,7 @@ import TagInput from './TagInput.vue'; import SshKeySelector from './SshKeySelector.vue'; // +++ Import SSH Key Selector +++ // 定义组件发出的事件 -const emit = defineEmits(['close', 'connection-added', 'connection-updated']); +const emit = defineEmits(['close', 'connection-added', 'connection-updated', 'connection-deleted']); // 定义 Props const props = defineProps<{ @@ -315,6 +315,29 @@ notes: formData.notes, // 添加备注 } }; +// 处理删除连接 +const handleDeleteConnection = async () => { + if (!isEditMode.value || !props.connectionToEdit) return; + + // 添加一个确认对话框 + // 使用模板字符串和 t 函数的默认值功能 + const connectionName = props.connectionToEdit.name || `ID: ${props.connectionToEdit.id}`; + if (!confirm(t('connections.prompts.confirmDelete', { name: connectionName }))) { + return; + } + + formError.value = null; + connectionsStore.error = null; // 清除之前的错误 + + const success = await connectionsStore.deleteConnection(props.connectionToEdit.id); + if (success) { + emit('connection-deleted'); // 发出删除成功事件 + emit('close'); // 删除成功后关闭表单 + } else { + formError.value = t('connections.form.errorDelete', { error: connectionsStore.error || t('errors.unknown', '未知错误') }); + } +}; + // --- Tag Creation/Deletion Handling --- const handleCreateTag = async (tagName: string) => { console.log(`[ConnForm] Received create-tag event for: ${tagName}`); // +++ 添加日志 +++ @@ -655,6 +678,10 @@ const testButtonText = computed(() => {