/** * Copyright 2025 Beijing Volcano Engine Technology Co., Ltd. All Rights Reserved. * SPDX-license-identifier: BSD-3-Clause */ import React, { useRef, useEffect } from 'react'; import { useSelector } from 'react-redux'; import { Tag, Spin } from '@arco-design/web-react'; import { RootState } from '@/store'; import Loading from '@/components/Loading/HorizonLoading'; import Config from '@/config'; import styles from './index.module.less'; const lines: (string | React.ReactNode)[] = []; function Conversation(props: React.HTMLAttributes) { const { className, ...rest } = props; const msgHistory = useSelector((state: RootState) => state.room.msgHistory); const { userId } = useSelector((state: RootState) => state.room.localUser); const { isAITalking, isUserTalking } = useSelector((state: RootState) => state.room); const isAIReady = msgHistory.length > 0; const containerRef = useRef(null); useEffect(() => { const container = containerRef.current; if (container) { container.scrollTop = container.scrollHeight - container.clientHeight; } }, [msgHistory.length]); return (
{lines.map((line) => line)} {!isAIReady ? (
AI 准备中, 请稍侯
) : ( '' )} {msgHistory?.map(({ value, user, isInterrupted }, index) => { const isUserMsg = user === userId; const isRobotMsg = user === Config.BotName; if (!isUserMsg && !isRobotMsg) { return ''; } return (
{value}
{isAIReady && (isUserTalking || isAITalking) && index === msgHistory.length - 1 ? ( ) : ( '' )}
{!isUserMsg && isInterrupted ? 已打断 : ''}
); })}
); } export default Conversation;