Commit cdd72345 by weiyudumei

fix: 修复 workflow 卡片输入框初始化时被禁用的问题

- 流式响应过程中忽略服务器返回的 endAnswerFlag,避免过早禁用
- 优化 isCompleted 判断逻辑,只有在当前回答且流式响应完成且没有正在进行的请求时才禁用
- 传递 isAsking 状态到 CardWorkflowForm 组件
parent 8204814b
......@@ -150,12 +150,14 @@ export const Chat: React.FC = () => {
// 只移除空格和制表符,保留换行符(避免移除末尾的 \n\n)
filteredAnswer = trimSpacesOnly(filteredAnswer)
// 在流式响应过程中,忽略服务器返回的 endAnswerFlag,避免过早禁用输入框
const { endAnswerFlag: _omitEndAnswerFlag, ...dataWithoutEndFlag } = msg.content.data || {}
newItems[lastIndex] = {
...newItems[lastIndex],
question,
answerList: [
{
...msg.content.data,
...dataWithoutEndFlag,
isShow: false,
answer: filteredAnswer,
},
......
......@@ -19,6 +19,7 @@ interface ChatAnswerAttachmentProps {
onSubmitQuestion?: (question: string, productCode?: string) => void
onWorkflowSubmit?: (paramMap: Record<string, string>, recordId?: string) => void
isWorkflowSubmitting?: boolean
isAsking?: boolean
}
export const ChatAnswerAttachment: React.FC<ChatAnswerAttachmentProps> = ({
......@@ -27,6 +28,7 @@ export const ChatAnswerAttachment: React.FC<ChatAnswerAttachmentProps> = ({
onSubmitQuestion,
onWorkflowSubmit,
isWorkflowSubmitting = false,
isAsking = false,
}) => {
const [previewModalOpen, setPreviewModalOpen] = useState(false)
const [currentDoc, setCurrentDoc] = useState<any>(null)
......@@ -175,7 +177,7 @@ export const ChatAnswerAttachment: React.FC<ChatAnswerAttachmentProps> = ({
answer={answer}
onSubmitWorkflow={onWorkflowSubmit || (() => {})}
isSubmitting={isWorkflowSubmitting}
isCompleted={answer.endAnswerFlag}
isCompleted={isLastAnswer && answer.endAnswerFlag === true && !isAsking}
/>
)}
{/* 其他 card-* 类型 */}
......
......@@ -7,8 +7,9 @@ import { ChatMaxCount } from './ChatMaxCount'
import type { Answer, ChatRecord } from '@/types/chat'
import AvatarBot from '@/assets/avatarBot.png'
import AIIcon from '@/assets/ai-icon.png'
import { useAppDispatch } from '@/store/hook'
import { useAppDispatch, useAppSelector } from '@/store/hook'
import { setIsAsking } from '@/store/chatSlice'
import type { RootState } from '@/store'
import SdreamLoading from '@/components/SdreamLoading'
interface ChatAnswerBoxProps {
......@@ -28,6 +29,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
const [innerRecord, setInnerRecord] = useState<ChatRecord>(record)
const [isTyping, setIsTyping] = useState(false)
const dispatch = useAppDispatch()
const isAsking = useAppSelector((state: RootState) => state.chat.isAsking)
const viteOutputObj = import.meta.env.VITE_OUTPUT_OBJ || 'open'
const handleTyping = () => {
......@@ -79,6 +81,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
hideOperate={shouldHideOperate}
onWorkflowSubmit={onWorkflowSubmit}
isWorkflowSubmitting={isWorkflowSubmitting}
isAsking={isAsking}
/>
)}
{!item.isShow && !item.isChatMaxCount && (
......@@ -92,6 +95,7 @@ export const ChatAnswerBox: React.FC<ChatAnswerBoxProps> = ({ record, showIndex,
hideOperate={shouldHideOperate}
onWorkflowSubmit={onWorkflowSubmit}
isWorkflowSubmitting={isWorkflowSubmitting}
isAsking={isAsking}
/>
)}
{!item.isShow && item.isChatMaxCount && <ChatMaxCount />}
......
......@@ -19,6 +19,7 @@ interface ChatAnswerParserProps {
hideOperate?: boolean
onWorkflowSubmit?: (paramMap: Record<string, string>, recordId?: string) => void
isWorkflowSubmitting?: boolean
isAsking?: boolean
}
function CheckIcon({ ...props }) {
......@@ -39,7 +40,7 @@ function CheckIcon({ ...props }) {
)
}
export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer, onTyping, onComplate, answer, isStopTyping, onSubmitQuestion, hideOperate, onWorkflowSubmit, isWorkflowSubmitting }) => {
export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer, onTyping, onComplate, answer, isStopTyping, onSubmitQuestion, hideOperate, onWorkflowSubmit, isWorkflowSubmitting, isAsking = false }) => {
const formatAnswer = formatMarkdown(answer.answer || '')
const [displayedText, setDisplayedText] = useState('')
const [currentIndex, setCurrentIndex] = useState(0)
......@@ -212,6 +213,7 @@ export const ChatAnswerParser: React.FC<ChatAnswerParserProps> = ({ isLastAnswer
answer={answer}
onWorkflowSubmit={onWorkflowSubmit}
isWorkflowSubmitting={isWorkflowSubmitting}
isAsking={isAsking}
/>
)}
......
......@@ -12,9 +12,10 @@ interface ChatAnswerShowerProps {
hideOperate?: boolean
onWorkflowSubmit?: (paramMap: Record<string, string>, recordId?: string) => void
isWorkflowSubmitting?: boolean
isAsking?: boolean
}
export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLastAnswer, onSubmitQuestion, hideOperate: hideOperateProp, onWorkflowSubmit, isWorkflowSubmitting }) => {
export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLastAnswer, onSubmitQuestion, hideOperate: hideOperateProp, onWorkflowSubmit, isWorkflowSubmitting, isAsking = false }) => {
const hideOperateByCard = (answer.cardList || []).some(attachment => attachment.type === 'box' || attachment?.type?.includes('card-'))
const hideOperate = hideOperateByCard || hideOperateProp
return (
......@@ -33,6 +34,7 @@ export const ChatAnswerShower: React.FC<ChatAnswerShowerProps> = ({ answer, isLa
answer={answer}
onWorkflowSubmit={onWorkflowSubmit}
isWorkflowSubmitting={isWorkflowSubmitting}
isAsking={isAsking}
/>
)}
{/* 操作区:仅根据卡片类型 / 上层显式 hideOperate 控制是否展示 */}
......
......@@ -252,12 +252,14 @@ export const TacticsChat: React.FC = () => {
// 只移除空格和制表符,保留换行符(避免移除末尾的 \n\n)
filteredAnswer = trimSpacesOnly(filteredAnswer)
// 在流式响应过程中,忽略服务器返回的 endAnswerFlag,避免过早禁用输入框
const { endAnswerFlag: _omitEndAnswerFlag, ...dataWithoutEndFlag } = msg.content.data || {}
newItems[lastAiIndex] = {
...newItems[lastAiIndex],
question,
answerList: [
{
...msg.content.data,
...dataWithoutEndFlag,
isShow: false,
answer: filteredAnswer,
},
......
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