Commit b14e994b by weiyudumei

refactor: 移除流式返回时的UI隐藏逻辑,只隐藏历史记录,正常问答显示UI

parent efae372f
...@@ -60,11 +60,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex, ...@@ -60,11 +60,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
// 当前默认始终展示点赞 / 点踩 / 复制等操作区(是否展示由下层基于卡片类型自行决定) // 当前默认始终展示点赞 / 点踩 / 复制等操作区(是否展示由下层基于卡片类型自行决定)
const shouldHideOperate = false const shouldHideOperate = false
// 如果 firstQaFlag 为 true 且存在 workflow 卡片,隐藏整个 chatItem(用户不需要看到这次的结果) // 不再隐藏流式返回的 chatItem,只隐藏历史记录(在 Chat.tsx 和 TacticsChat.tsx 中处理)
// 注意:历史记录(isShow === true)不会渲染 CardWorkflowForm,不会自动提交
// 只有流式返回的新记录(isShow === false)才会渲染 CardWorkflowForm 并执行自动提交
const hasWorkflowCard = (item.cardList || []).some(attachment => attachment.type === 'card-workflow')
const shouldHideChatItem = item.firstQaFlag === true && hasWorkflowCard
// 创建包装函数,从会话历史中找到最后一个有 workFlowSessionId 的答案,并在追问时传递 // 创建包装函数,从会话历史中找到最后一个有 workFlowSessionId 的答案,并在追问时传递
const handleSubmitQuestionWithWorkflow = (question: string, productCode?: string) => { const handleSubmitQuestionWithWorkflow = (question: string, productCode?: string) => {
...@@ -89,7 +85,6 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex, ...@@ -89,7 +85,6 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
<div <div
className="chatItemBotContainer w-full" className="chatItemBotContainer w-full"
key={`${item.recordId}-${index}`} key={`${item.recordId}-${index}`}
style={shouldHideChatItem ? { visibility: 'hidden', height: 0, overflow: 'hidden', margin: 0, padding: 0 } : undefined}
> >
<div className="flex"> <div className="flex">
<Avatar <Avatar
......
...@@ -202,9 +202,7 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer ...@@ -202,9 +202,7 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer
</MarkdownDetail> </MarkdownDetail>
</div> </div>
)} )}
{/* ChatAnswerParser 用于流式返回的新记录(isShow === false),即使 firstQaFlag === true 也要渲染 ChatAnswerAttachment,确保自动提交逻辑能执行 {!isTyping
如果 firstQaFlag 为 true 且存在 workflow 卡片,即使 isTyping 为 true 也要渲染 ChatAnswerAttachment */}
{((!isTyping) || (answer.firstQaFlag === true && (answer.cardList || []).some(attachment => attachment.type === 'card-workflow')))
&& answer.cardList && answer.cardList
&& answer.cardList?.length !== 0 && answer.cardList?.length !== 0
&& ( && (
......
...@@ -28,9 +28,7 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa ...@@ -28,9 +28,7 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa
</MarkdownDetail> </MarkdownDetail>
</div> </div>
)} )}
{/* 历史记录(isShow === true)且 firstQaFlag === true 时,不渲染 ChatAnswerAttachment(不需要自动提交) {answer.cardList && answer.cardList?.length !== 0 && (
流式返回的新记录(isShow === false)即使 firstQaFlag === true 也要渲染,确保自动提交逻辑能执行 */}
{answer.cardList && answer.cardList?.length !== 0 && !(answer.isShow === true && answer.firstQaFlag === true) && (
<ChatAnswerAttachment <ChatAnswerAttachment
onSubmitQuestion={onSubmitQuestion} onSubmitQuestion={onSubmitQuestion}
isLastAnswer={isLastAnswer} isLastAnswer={isLastAnswer}
......
...@@ -1195,10 +1195,8 @@ export const TacticsChat: React.FC = () => { ...@@ -1195,10 +1195,8 @@ export const TacticsChat: React.FC = () => {
if (record.role === 'user' && !record.question) { if (record.role === 'user' && !record.question) {
return null return null
} }
// 如果历史记录中 firstQaFlag 为 true,则不展示该条 chatItem // 如果历史记录中 firstQaFlag 为 true,隐藏 UI 但保留组件渲染
if (record.role === 'ai' && record.answerList?.[0]?.firstQaFlag === true) { const shouldHideHistoryItem = record.role === 'ai' && record.answerList?.[0]?.firstQaFlag === true
return null
}
const matchedDivider = historyDividers.find(divider => divider.index === index + 1) const matchedDivider = historyDividers.find(divider => divider.index === index + 1)
const recordId = record.answerList?.[0]?.recordId || record.groupId const recordId = record.answerList?.[0]?.recordId || record.groupId
const uniqueKey = recordId const uniqueKey = recordId
...@@ -1216,6 +1214,7 @@ export const TacticsChat: React.FC = () => { ...@@ -1216,6 +1214,7 @@ export const TacticsChat: React.FC = () => {
)} )}
<div <div
className="w-full chatItem mx-auto" className="w-full chatItem mx-auto"
style={shouldHideHistoryItem ? { visibility: 'hidden', height: 0, overflow: 'hidden', margin: 0, padding: 0 } : undefined}
> >
{record.role === 'system' && <TacticsWelcome cleared={hasCleared} />} {record.role === 'system' && <TacticsWelcome cleared={hasCleared} />}
{record.role === 'user' && <ChatItemUser record={record} />} {record.role === 'user' && <ChatItemUser record={record} />}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment