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
ca0d7aea
Commit
ca0d7aea
authored
Jan 05, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:历史记录展示
parent
a12ce805
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
15 deletions
+47
-15
src/components/ChatEditor/index.tsx
+26
-0
src/pages/Chat/Chat.tsx
+3
-7
src/pages/ChatTactics/TacticsChat.tsx
+5
-3
src/pages/ChatTactics/components/TacticsWelcome/index.tsx
+10
-0
src/pages/Home/HomeNew.tsx
+3
-5
No files found.
src/components/ChatEditor/index.tsx
View file @
ca0d7aea
...
@@ -236,6 +236,32 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -236,6 +236,32 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
newSearchParams
.
delete
(
'toolId'
)
newSearchParams
.
delete
(
'toolId'
)
setSearchParams
(
newSearchParams
,
{
replace
:
true
})
setSearchParams
(
newSearchParams
,
{
replace
:
true
})
}
}
// 先调用 fetchSessionConversationId 获取会话ID
try
{
const
requestData
=
{
busiId
:
''
,
}
const
res
=
await
fetchSessionConversationId
(
requestData
)
if
(
res
?.
data
?.
conversationId
)
{
const
conversationId
=
res
.
data
.
conversationId
// 使用获取到的会话ID调用历史会话
const
qaRes
=
await
fetchUserQaRecordPage
(
conversationId
,
''
)
console
.
log
(
'qaRes chatEditor11111'
,
qaRes
)
// 通过自定义事件将历史记录数据传递给父组件进行渲染
window
.
dispatchEvent
(
new
CustomEvent
(
'toolHistoryLoaded'
,
{
detail
:
{
conversationId
,
toolId
:
''
,
toolName
:
'制度活化'
,
qaRecords
:
qaRes
?.
data
||
[],
},
}))
}
}
catch
(
error
)
{
console
.
error
(
'获取会话ID或历史记录失败:'
,
error
)
}
}
}
// 处理工具按钮点击:先创建新会话,再切换工具
// 处理工具按钮点击:先创建新会话,再切换工具
...
...
src/pages/Chat/Chat.tsx
View file @
ca0d7aea
...
@@ -15,7 +15,7 @@ import { fetchUserQaRecordPage } from '@/api/conversation'
...
@@ -15,7 +15,7 @@ import { fetchUserQaRecordPage } from '@/api/conversation'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
fetchToolList
}
from
'@/api/home'
import
{
fetchToolList
}
from
'@/api/home'
import
{
clearCurrentToolId
,
clearShouldSendQuestion
,
fetchConversations
,
setCurrentToolId
}
from
'@/store/conversationSlice'
import
{
clearCurrentToolId
,
clearShouldSendQuestion
,
fetchConversations
,
setCurrentToolId
}
from
'@/store/conversationSlice'
import
{
getUserRolesForApi
,
safeSessionStorageGetItem
}
from
'@/lib/utils'
import
{
getUserRolesForApi
}
from
'@/lib/utils'
import
type
{
RootState
}
from
'@/store'
import
type
{
RootState
}
from
'@/store'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
ScrollBtoIcon
from
'@/assets/svg/scrollBto.svg?react'
import
ScrollBtoIcon
from
'@/assets/svg/scrollBto.svg?react'
...
@@ -477,17 +477,13 @@ export const Chat: React.FC = () => {
...
@@ -477,17 +477,13 @@ export const Chat: React.FC = () => {
// 制度活化,清除 toolId
// 制度活化,清除 toolId
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
}
}
// 刷新对话内容
// 历史记录加载已由 ChatEditor 通过 toolHistoryLoaded 事件处理,此处不再重复调用
if
(
currentIdRef
.
current
)
{
const
toolIdForApi
=
toolId
||
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
getUserQaRecordPage
(
currentIdRef
.
current
,
toolIdForApi
)
}
}
}
window
.
addEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
window
.
addEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
return
()
=>
{
return
()
=>
{
window
.
removeEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
window
.
removeEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
}
}
},
[
dispatch
,
getUserQaRecordPage
])
},
[
dispatch
])
// 监听工具历史记录加载事件,渲染历史会话
// 监听工具历史记录加载事件,渲染历史会话
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
src/pages/ChatTactics/TacticsChat.tsx
View file @
ca0d7aea
...
@@ -107,10 +107,11 @@ export const TacticsChat: React.FC = () => {
...
@@ -107,10 +107,11 @@ export const TacticsChat: React.FC = () => {
}
}
},
[
searchParams
])
},
[
searchParams
])
// 读取 from=order 时的 orderMeta 参数(直接从 query 读取,不再使用 sessionStorage)
// 读取 from=
tactics&place=
order 时的 orderMeta 参数(直接从 query 读取,不再使用 sessionStorage)
const
orderMeta
=
useMemo
(()
=>
{
const
orderMeta
=
useMemo
(()
=>
{
const
fromValues
=
searchParams
.
getAll
(
'from'
)
const
from
=
searchParams
.
get
(
'from'
)
if
(
!
fromValues
.
includes
(
'order'
))
{
const
place
=
searchParams
.
get
(
'place'
)
if
(
from
!==
'tactics'
||
place
!==
'order'
)
{
return
undefined
return
undefined
}
}
return
{
return
{
...
@@ -121,6 +122,7 @@ export const TacticsChat: React.FC = () => {
...
@@ -121,6 +122,7 @@ export const TacticsChat: React.FC = () => {
// 仅用于创建会话的额外参数(create_conversation)
// 仅用于创建会话的额外参数(create_conversation)
const
getConversationExtra
=
useCallback
(()
=>
{
const
getConversationExtra
=
useCallback
(()
=>
{
if
(
orderMeta
)
{
if
(
orderMeta
)
{
console
.
log
(
'orderMeta'
,
orderMeta
)
// 从 localStorage 读取 userName
// 从 localStorage 读取 userName
const
userNameFromStorage
=
safeLocalStorageGetItem
(
'__USER_NAME__'
)
const
userNameFromStorage
=
safeLocalStorageGetItem
(
'__USER_NAME__'
)
let
userName
=
''
let
userName
=
''
...
...
src/pages/ChatTactics/components/TacticsWelcome/index.tsx
View file @
ca0d7aea
...
@@ -18,6 +18,16 @@ export const TacticsWelcome: React.FC<TacticsWelcomeProps> = ({ cleared }) => {
...
@@ -18,6 +18,16 @@ export const TacticsWelcome: React.FC<TacticsWelcomeProps> = ({ cleared }) => {
const
placeFromCache
=
safeSessionStorageGetItem
(
'__TACTICS_PLACE__'
)
const
placeFromCache
=
safeSessionStorageGetItem
(
'__TACTICS_PLACE__'
)
const
isOrderPlace
=
from
===
'tactics'
&&
placeFromCache
===
'order'
const
isOrderPlace
=
from
===
'tactics'
&&
placeFromCache
===
'order'
// 打印路由参数
console
.
log
(
'TacticsWelcome 路由参数:'
,
{
searchParams
:
Object
.
fromEntries
(
searchParams
.
entries
()),
from
,
placeFromCache
,
isOrderPlace
,
cleared
,
url
:
window
.
location
.
href
,
})
const
welcomeText
=
cleared
const
welcomeText
=
cleared
?
'暂无分析记录,点击右上方按钮开始新的分析吧!'
?
'暂无分析记录,点击右上方按钮开始新的分析吧!'
:
isOrderPlace
:
isOrderPlace
...
...
src/pages/Home/HomeNew.tsx
View file @
ca0d7aea
...
@@ -12,7 +12,7 @@ import { useAppDispatch } from '@/store/hook'
...
@@ -12,7 +12,7 @@ import { useAppDispatch } from '@/store/hook'
import
{
fetchEfficiencyQuestionList
}
from
'@/api/home'
import
{
fetchEfficiencyQuestionList
}
from
'@/api/home'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
fetchSessionConversationId
,
fetchUserQaRecordPage
}
from
'@/api/conversation'
import
{
fetchSessionConversationId
}
from
'@/api/conversation'
import
{
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeSessionStorageGetItem
,
safeSessionStorageRemoveItem
,
safeSessionStorageSetItem
}
from
'@/lib/utils'
import
{
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeSessionStorageGetItem
,
safeSessionStorageRemoveItem
,
safeSessionStorageSetItem
}
from
'@/lib/utils'
import
type
{
Conversation
}
from
'@/types/conversation'
import
type
{
Conversation
}
from
'@/types/conversation'
...
@@ -130,10 +130,8 @@ export const Home: React.FC = () => {
...
@@ -130,10 +130,8 @@ export const Home: React.FC = () => {
dispatch
(
setCurrentConversation
(
conversationId
))
dispatch
(
setCurrentConversation
(
conversationId
))
dispatch
(
setNavigationFlag
(
true
))
dispatch
(
setNavigationFlag
(
true
))
// 获取历史记录
// 历史记录会在 Chat 页面自动渲染,不需要在这里获取
await
fetchUserQaRecordPage
(
conversationId
,
toolId
||
undefined
)
// 移除重复调用,避免接口被调用两次
console
.
log
(
'qaRes homeNew333333'
,
res
)
// 历史记录会在 Chat 页面自动渲染,这里只负责获取
}
}
}
}
catch
(
error
)
{
catch
(
error
)
{
...
...
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