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
a41a24e8
Commit
a41a24e8
authored
Jan 07, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 点击常见问题提问逻辑
parent
aefb636d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
2 deletions
+13
-2
src/pages/Chat/Chat.tsx
+12
-1
src/pages/Chat/components/ChatWelcome/index.tsx
+1
-1
No files found.
src/pages/Chat/Chat.tsx
View file @
a41a24e8
...
@@ -39,6 +39,8 @@ export const Chat: React.FC = () => {
...
@@ -39,6 +39,8 @@ export const Chat: React.FC = () => {
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
[
allItems
,
setAllItems
]
=
useState
<
ChatRecord
[]
>
([])
const
dispatch
=
useAppDispatch
()
const
dispatch
=
useAppDispatch
()
const
{
shouldSendQuestion
,
currentToolId
,
conversations
}
=
useAppSelector
((
state
:
RootState
)
=>
state
.
conversation
)
const
{
shouldSendQuestion
,
currentToolId
,
conversations
}
=
useAppSelector
((
state
:
RootState
)
=>
state
.
conversation
)
// 标记历史记录是否已加载完成,用于确保自动发送问题在历史记录加载后执行
const
historyLoadedRef
=
useRef
<
{
conversationId
:
string
|
null
}
>
({
conversationId
:
null
})
const
scrollableRef
=
useRef
<
HTMLDivElement
|
any
>
(
null
)
const
scrollableRef
=
useRef
<
HTMLDivElement
|
any
>
(
null
)
const
position
=
useScroll
(
scrollableRef
)
const
position
=
useScroll
(
scrollableRef
)
const
currentIdRef
=
useRef
<
string
|
undefined
>
(
id
)
const
currentIdRef
=
useRef
<
string
|
undefined
>
(
id
)
...
@@ -458,6 +460,8 @@ export const Chat: React.FC = () => {
...
@@ -458,6 +460,8 @@ export const Chat: React.FC = () => {
}
}
finally
{
finally
{
setIsLoading
(
false
)
setIsLoading
(
false
)
// 标记该会话的历史记录已加载完成
historyLoadedRef
.
current
.
conversationId
=
finalConversationId
// 清除处理标记(支持新会话ID的情况)
// 清除处理标记(支持新会话ID的情况)
// finalConversationId 可能是新会话ID(从收藏返回时)或原来的 conversationId
// finalConversationId 可能是新会话ID(从收藏返回时)或原来的 conversationId
if
(
processingConversationIdRef
.
current
===
finalConversationId
)
{
if
(
processingConversationIdRef
.
current
===
finalConversationId
)
{
...
@@ -491,6 +495,8 @@ export const Chat: React.FC = () => {
...
@@ -491,6 +495,8 @@ export const Chat: React.FC = () => {
currentIdRef
.
current
=
id
currentIdRef
.
current
=
id
lastSentQuestionRef
.
current
=
''
// 重置标记
lastSentQuestionRef
.
current
=
''
// 重置标记
// 重置历史记录加载标记,确保新会话时能正确触发自动发送
historyLoadedRef
.
current
.
conversationId
=
null
// 保存 fromCollect 标记到 ref,避免 location.state 被清除后丢失
// 保存 fromCollect 标记到 ref,避免 location.state 被清除后丢失
// 优先使用 location.state,其次使用 sessionStorage(用于 navigate(-1) 的情况)
// 优先使用 location.state,其次使用 sessionStorage(用于 navigate(-1) 的情况)
fromCollectRef
.
current
=
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
fromCollectRef
.
current
=
Boolean
(
location
.
state
?.
fromCollect
)
||
Boolean
(
sessionStorage
.
getItem
(
'fromCollect'
))
...
@@ -513,6 +519,9 @@ export const Chat: React.FC = () => {
...
@@ -513,6 +519,9 @@ export const Chat: React.FC = () => {
&&
currentIdRef
.
current
&&
currentIdRef
.
current
&&
!
isLoading
&&
!
isLoading
&&
shouldSendQuestion
!==
lastSentQuestionRef
.
current
&&
shouldSendQuestion
!==
lastSentQuestionRef
.
current
// 确保历史记录已加载完成(如果是从常见问题点击进入,需要等待历史记录加载完成)
// 新会话(allItems.length <= 1)或历史记录已加载完成时,才自动发送
&&
(
historyLoadedRef
.
current
.
conversationId
===
currentIdRef
.
current
||
allItems
.
length
<=
1
)
)
{
)
{
lastSentQuestionRef
.
current
=
shouldSendQuestion
lastSentQuestionRef
.
current
=
shouldSendQuestion
// 立即清除shouldSendQuestion,防止重复发送
// 立即清除shouldSendQuestion,防止重复发送
...
@@ -522,7 +531,7 @@ export const Chat: React.FC = () => {
...
@@ -522,7 +531,7 @@ export const Chat: React.FC = () => {
handleSubmitQuestion
(
shouldSendQuestion
,
undefined
,
currentToolId
)
handleSubmitQuestion
(
shouldSendQuestion
,
undefined
,
currentToolId
)
},
100
)
},
100
)
}
}
},
[
shouldSendQuestion
,
isLoading
,
currentToolI
d
])
},
[
shouldSendQuestion
,
isLoading
,
allItems
.
length
,
currentToolId
,
i
d
])
// 根据 currentToolId 获取对应的 toolName
// 根据 currentToolId 获取对应的 toolName
useEffect
(()
=>
{
useEffect
(()
=>
{
...
@@ -618,6 +627,8 @@ export const Chat: React.FC = () => {
...
@@ -618,6 +627,8 @@ export const Chat: React.FC = () => {
}
}
finally
{
finally
{
setIsLoading
(
false
)
setIsLoading
(
false
)
// 标记该会话的历史记录已加载完成(通过工具切换事件加载)
historyLoadedRef
.
current
.
conversationId
=
conversationId
}
}
}
}
window
.
addEventListener
(
'toolHistoryLoaded'
,
handleToolHistoryLoaded
as
EventListener
)
window
.
addEventListener
(
'toolHistoryLoaded'
,
handleToolHistoryLoaded
as
EventListener
)
...
...
src/pages/Chat/components/ChatWelcome/index.tsx
View file @
a41a24e8
...
@@ -15,7 +15,7 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ toolName: _toolName })
...
@@ -15,7 +15,7 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ toolName: _toolName })
const
currentToolId
=
typeof
window
!==
'undefined'
?
sessionStorage
.
getItem
(
'currentToolId'
)
:
''
const
currentToolId
=
typeof
window
!==
'undefined'
?
sessionStorage
.
getItem
(
'currentToolId'
)
:
''
if
(
currentToolId
===
'6712395743240'
)
{
if
(
currentToolId
===
'6712395743240'
)
{
return
'H
I
~我是您的数据助手,可以帮你查询业务数据哦'
return
'H
i
~我是您的数据助手,可以帮你查询业务数据哦'
}
}
if
(
currentToolId
===
'6712395743241'
)
{
if
(
currentToolId
===
'6712395743241'
)
{
...
...
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