'use client'; import React, { useRef, useEffect } from 'react'; import { Box, Typography, Paper, Grid, CircularProgress } from '@mui/material'; import { useTheme } from '@mui/material/styles'; import ChatMessage from './ChatMessage'; import { playgroundStyles } from '@/styles/playground'; import { useTranslation } from 'react-i18next'; const ChatArea = ({ selectedModels, conversations, loading, getModelName }) => { const theme = useTheme(); const styles = playgroundStyles(theme); const { t } = useTranslation(); // 为每个模型创建独立的引用 const chatContainerRefs = { model1: useRef(null), model2: useRef(null), model3: useRef(null) }; // 为每个模型的聊天容器自动滚动到底部 useEffect(() => { Object.values(chatContainerRefs).forEach(ref => { if (ref.current) { ref.current.scrollTop = ref.current.scrollHeight; } }); }, [conversations]); if (selectedModels.length === 0) { return ( {t('playground.selectModelFirst')} ); } return ( {selectedModels.map((modelId, index) => { const modelConversation = conversations[modelId] || []; const isLoading = loading[modelId]; const refKey = `model${index + 1}`; return ( 1 ? 12 / selectedModels.length : 12} key={modelId} style={{ maxHeight: 'calc(100vh - 300px)' }} > {getModelName(modelId)} {isLoading && } {modelConversation.length === 0 ? ( {t('playground.sendFirstMessage')} ) : ( modelConversation.map((message, msgIndex) => ( )) )} ); })} ); }; export default ChatArea;