Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sdream-ai-fe
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
侯明涛
sdream-ai-fe
Commits
eace2005
Commit
eace2005
authored
Jan 29, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:提质增效时自动调用提问接口,用户画像&&工单接入工作流
parent
cddd8c5b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
86 additions
and
28 deletions
+86
-28
src/components/ChatEditor/index.tsx
+12
-0
src/pages/Chat/Chat.tsx
+70
-27
src/pages/ChatTactics/TacticsChat.tsx
+4
-1
No files found.
src/components/ChatEditor/index.tsx
View file @
eace2005
...
...
@@ -449,6 +449,18 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
qaRecords
:
qaRes
?.
data
||
[],
},
}))
// 提质增效模式下,获取会话ID后立即调用提问接口
if
(
tool
.
toolId
===
'6712395743241'
)
{
window
.
dispatchEvent
(
new
CustomEvent
(
'autoSubmitQuestion'
,
{
detail
:
{
conversationId
,
question
:
''
,
toolId
:
tool
.
toolId
,
recordType
:
'B03'
,
busiType
:
'01'
,
},
}))
}
// 清除标记,避免影响后续路由切换
sessionStorage
.
removeItem
(
'toolHistoryLoading'
)
}
...
...
src/pages/Chat/Chat.tsx
View file @
eace2005
...
...
@@ -141,9 +141,21 @@ export const Chat: React.FC = () => {
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
const
isEmptyQuestion
=
!
question
.
trim
()
// 如果是空问题且最后一项不是AI回答,需要添加AI回答
if
(
isEmptyQuestion
&&
(
lastIndex
<
0
||
newItems
[
lastIndex
].
role
!==
'ai'
))
{
newItems
.
push
({
role
:
'ai'
,
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
)
}
const
currentIndex
=
newItems
.
length
-
1
if
(
currentIndex
>=
0
&&
newItems
[
currentIndex
].
role
===
'ai'
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
const
originalAnswer
=
(
newItems
[
lastIndex
].
answerList
?.[
0
]?.
answer
||
''
)
+
(
msg
.
content
.
data
.
answer
??
'
\
n'
)
const
existingAnswer
=
newItems
[
currentIndex
].
answerList
?.[
0
]
||
{}
const
originalAnswer
=
(
existingAnswer
.
answer
||
''
)
+
(
msg
.
content
.
data
.
answer
??
'
\
n'
)
// 移除所有括号及其内容
let
filteredAnswer
=
originalAnswer
.
replace
(
/
\([^
)
]
*
\)
/g
,
''
)
// 去除 [参考文档《任意内容》 《任意内容》...] 格式的内容
...
...
@@ -154,10 +166,9 @@ export const Chat: React.FC = () => {
// 在流式响应过程中,忽略服务器返回的 endAnswerFlag,避免过早禁用输入框
const
{
endAnswerFlag
:
_omitEndAnswerFlag
,
...
dataWithoutEndFlag
}
=
msg
.
content
.
data
||
{}
// 保留之前保存的 workFlowSessionId 和 recordId,避免被覆盖
const
existingAnswer
=
newItems
[
lastIndex
].
answerList
?.[
0
]
||
{}
newItems
[
lastIndex
]
=
{
...
newItems
[
lastIndex
],
question
,
newItems
[
currentIndex
]
=
{
...
newItems
[
currentIndex
],
question
:
isEmptyQuestion
?
undefined
:
question
,
answerList
:
[
{
...
existingAnswer
,
...
...
@@ -181,11 +192,22 @@ export const Chat: React.FC = () => {
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
// 创建数组的浅拷贝
const
lastIndex
=
newItems
.
length
-
1
if
(
lastIndex
>=
0
)
{
const
isEmptyQuestion
=
!
question
.
trim
()
// 如果是空问题且最后一项不是AI回答,需要添加AI回答
if
(
isEmptyQuestion
&&
(
lastIndex
<
0
||
newItems
[
lastIndex
].
role
!==
'ai'
))
{
newItems
.
push
({
role
:
'ai'
,
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
)
}
const
currentIndex
=
newItems
.
length
-
1
if
(
currentIndex
>=
0
&&
newItems
[
currentIndex
].
role
===
'ai'
)
{
// 创建最后一项的新对象,合并现有数据和新的 answer
newItems
[
las
tIndex
]
=
{
...
newItems
[
las
tIndex
],
question
,
newItems
[
curren
tIndex
]
=
{
...
newItems
[
curren
tIndex
],
question
:
isEmptyQuestion
?
undefined
:
question
,
answerList
:
[
{
...
msg
.
content
.
data
,
...
...
@@ -206,7 +228,7 @@ export const Chat: React.FC = () => {
question
:
string
,
productCode
?:
string
,
toolId
?:
string
,
extraParams
?:
{
paramMap
?:
Record
<
string
,
string
>
,
recordId
?:
string
,
recordType
?:
string
,
workFlowSessionId
?:
string
,
isReask
?:
boolean
},
extraParams
?:
{
paramMap
?:
Record
<
string
,
string
>
,
recordId
?:
string
,
recordType
?:
string
,
workFlowSessionId
?:
string
,
isReask
?:
boolean
,
busiType
?:
string
},
workFlowSessionId
?:
string
,
recordId
?:
string
,
)
=>
{
...
...
@@ -224,18 +246,20 @@ export const Chat: React.FC = () => {
// 检查token
await
fetchCheckTokenApi
()
// 一次性添加用户问题和空的AI回答
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'user'
,
question
,
}
as
ChatRecord
,
{
role
:
'ai'
,
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
,
])
// 如果 question 不为空,才添加用户问题和空的AI回答(自动提问时 question 为空,不显示)
if
(
question
.
trim
())
{
setAllItems
(
prevItems
=>
[
...
prevItems
,
{
role
:
'user'
,
question
,
}
as
ChatRecord
,
{
role
:
'ai'
,
answerList
:
[{
answer
:
''
}],
}
as
ChatRecord
,
])
}
// 创建新的 AbortController
abortControllerRef
.
current
=
new
AbortController
()
...
...
@@ -274,7 +298,7 @@ export const Chat: React.FC = () => {
else
if
(
recordId
)
{
requestBody
.
recordId
=
recordId
}
// workFlowSessionId 的传递逻辑:
// 1. 如果是重新问答(isReask === true),不传递 workFlowSessionId
// 2. 优先使用 extraParams 中的值
...
...
@@ -304,6 +328,10 @@ export const Chat: React.FC = () => {
// 如果传入了 recordType,优先使用传入的值(workflow 提交场景)
if
(
extraParams
?.
recordType
)
{
requestBody
.
recordType
=
extraParams
.
recordType
// 如果同时传入了 busiType,也使用传入的值
if
(
extraParams
?.
busiType
)
{
requestBody
.
busiType
=
extraParams
.
busiType
}
}
// 制度活化:toolId 为空字符串或 undefined
else
if
(
!
resolvedToolId
||
resolvedToolId
===
''
)
{
...
...
@@ -314,7 +342,7 @@ export const Chat: React.FC = () => {
// 提质增效:toolId 为 6712395743241
else
if
(
resolvedToolId
===
'6712395743241'
)
{
requestBody
.
busiType
=
'01'
requestBody
.
recordType
=
'B0
0
'
requestBody
.
recordType
=
'B0
3
'
}
// 数据助手:toolId 为 6712395743240
else
if
(
resolvedToolId
===
'6712395743240'
)
{
...
...
@@ -927,6 +955,21 @@ export const Chat: React.FC = () => {
}
},
[
dispatch
])
// 监听自动提问事件(提质增效模式下使用)
useEffect
(()
=>
{
const
handleAutoSubmitQuestion
=
(
event
:
CustomEvent
)
=>
{
const
{
conversationId
,
question
,
toolId
,
recordType
,
busiType
}
=
event
.
detail
// 确保当前会话ID匹配
if
(
conversationId
===
currentIdRef
.
current
)
{
handleSubmitQuestion
(
question
,
undefined
,
toolId
,
{
recordType
,
busiType
})
}
}
window
.
addEventListener
(
'autoSubmitQuestion'
,
handleAutoSubmitQuestion
as
EventListener
)
return
()
=>
{
window
.
removeEventListener
(
'autoSubmitQuestion'
,
handleAutoSubmitQuestion
as
EventListener
)
}
},
[
handleSubmitQuestion
])
return
(
<
div
className=
{
styles
.
scrollView
}
>
<
div
className=
{
`${styles.chatPage} relative`
}
>
...
...
@@ -953,10 +996,10 @@ export const Chat: React.FC = () => {
const
uniqueKey
=
recordId
?
`${record.role}-${recordId}`
:
`${record.role}-${record.question || record.answerList?.[0]?.answer || ''}-${index}`
// 如果历史记录中 firstQaFlag 为 true,隐藏 UI 但保留组件渲染(确保自动提交逻辑能执行)
const
shouldHideHistoryItem
=
record
.
role
===
'ai'
&&
record
.
answerList
?.[
0
]?.
firstQaFlag
===
true
return
(
<
div
className=
"w-full chatItem mx-auto"
...
...
src/pages/ChatTactics/TacticsChat.tsx
View file @
eace2005
...
...
@@ -434,7 +434,8 @@ export const TacticsChat: React.FC = () => {
productCode
,
toolId
:
resolvedToolId
,
...(
extra
?.
busiType
?
{
busiType
:
extra
.
busiType
}
:
{}),
...(
extra
?.
recordType
?
{
recordType
:
extra
.
recordType
}
:
{}),
// from=tactics&place=order 场景下,recordType 固定为 A11,不根据 extra.recordType 改变
...(
orderMeta
&&
shouldIncludeOrderMeta
?
{
recordType
:
'A11'
}
:
(
extra
?.
recordType
?
{
recordType
:
extra
.
recordType
}
:
{})),
...(
extra
?.
numberType
?
{
numberType
:
extra
.
numberType
}
:
{}),
}
// 优先级:orderMeta > userMeta > tacticsMeta
...
...
@@ -475,6 +476,8 @@ export const TacticsChat: React.FC = () => {
}
}
requestBody
.
busiId
=
userId
// from=tactics&place=order 场景下,recordType 固定为 A11
requestBody
.
recordType
=
'A11'
}
else
if
(
userMeta
?.
place
===
'user'
)
{
requestBody
.
busiType
??
=
'02'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment