import React, { useEffect } from 'react'; import { Dialog, DialogTitle, DialogContent, DialogActions, Button, TextField, Box, Typography, IconButton, InputAdornment, FormControl, InputLabel, Select, MenuItem, CircularProgress, } from '@mui/material'; import { Visibility, VisibilityOff } from '@mui/icons-material'; import { Controller, useForm } from 'react-hook-form'; // AWS Bedrock 支持的区域列表 export const BEDROCK_REGIONS = [ { value: 'us-east-1', label: 'US East (N. Virginia)' }, { value: 'us-west-2', label: 'US West (Oregon)' }, { value: 'ap-southeast-2', label: 'Asia Pacific (Sydney)' }, { value: 'ap-northeast-1', label: 'Asia Pacific (Tokyo)' }, { value: 'eu-central-1', label: 'Europe (Frankfurt)' }, { value: 'eu-west-3', label: 'Europe (Paris)' }, ]; // 表单数据接口 export interface BedrockFormData { access_key_id: string; secret_access_key: string; region: string; } // 对话框 Props 接口 export interface BedrockDialogProps { open: boolean; onClose: () => void; onSubmit: (data: BedrockFormData) => void; loading: boolean; initialData?: BedrockFormData; editMode?: boolean; } /** * AWS Bedrock 配置对话框 */ function BedrockDialog ({ open, onClose, onSubmit, loading, initialData, editMode = false, }: BedrockDialogProps) { const [showAccessKey, setShowAccessKey] = React.useState(false); const [showSecretKey, setShowSecretKey] = React.useState(false); const { control, handleSubmit, reset, formState: { errors }, } = useForm({ defaultValues: { access_key_id: '', secret_access_key: '', region: 'us-east-1', }, }); // 当对话框打开或初始数据变化时重置表单 useEffect(() => { if (open) { reset(initialData || { access_key_id: '', secret_access_key: '', region: 'us-east-1' }); } }, [open, initialData, reset]); const handleFormSubmit = (data: BedrockFormData) => { onSubmit(data); }; const toggleShowAccessKey = () => { setShowAccessKey(!showAccessKey); }; const toggleShowSecretKey = () => { setShowSecretKey(!showSecretKey); }; return ( {editMode ? '编辑' : '配置'} AWS Bedrock ( {showAccessKey ? : } ), }} /> )} /> ( {showSecretKey ? : } ), }} /> )} /> ( Region {errors.region && ( {errors.region.message} )} )} /> ); }; export default BedrockDialog;