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
1219c383
Commit
1219c383
authored
Dec 31, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:获取历史会话id接口&&新建会话时机
parent
6eea50cc
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
5 deletions
+44
-5
src/api/conversation.ts
+14
-1
src/pages/Home/HomeNew.tsx
+30
-4
No files found.
src/api/conversation.ts
View file @
1219c383
...
@@ -13,7 +13,7 @@ export function fetchQueryUserConversationPage<T>(data: T) {
...
@@ -13,7 +13,7 @@ export function fetchQueryUserConversationPage<T>(data: T) {
* @params { * }
* @params { * }
*/
*/
export
function
fetchCreateConversation
<
T
>
(
data
:
T
)
{
export
function
fetchCreateConversation
<
T
>
(
data
:
T
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/create_conversation'
,
data
)
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/create_conversation'
,
data
as
Record
<
string
,
any
>
)
}
}
/**
/**
...
@@ -33,3 +33,16 @@ export function fetchDeleteUserConversation(conversationIdList: string[]) {
...
@@ -33,3 +33,16 @@ export function fetchDeleteUserConversation(conversationIdList: string[]) {
conversationIdList
,
conversationIdList
,
})
})
}
}
/**
* 获取历史会话ID
* @params
*/
export
function
fetchSessionConversationId
<
T
>
(
data
:
T
)
{
const
requestData
=
{
...(
data
as
Record
<
string
,
any
>
),
busiType
:
'01'
,
busiId
:
(
data
as
Record
<
string
,
any
>
)?.
busiId
||
''
,
}
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/get_user_conversation_session'
,
requestData
)
}
src/pages/Home/HomeNew.tsx
View file @
1219c383
...
@@ -12,6 +12,7 @@ import { useAppDispatch } from '@/store/hook'
...
@@ -12,6 +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
{
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'
...
@@ -59,7 +60,7 @@ export const Home: React.FC = () => {
...
@@ -59,7 +60,7 @@ export const Home: React.FC = () => {
defaultValue
:
''
,
defaultValue
:
''
,
})
})
const
initConversation
=
async
()
=>
{
const
_
initConversation
=
async
()
=>
{
const
fromCollect
=
location
.
state
?.
fromCollect
const
fromCollect
=
location
.
state
?.
fromCollect
// 只有在访问首页时才处理会话,如果已经在聊天页面则不处理
// 只有在访问首页时才处理会话,如果已经在聊天页面则不处理
if
(
!
fromCollect
&&
(
location
.
pathname
===
'/'
||
location
.
pathname
===
'/home'
))
{
if
(
!
fromCollect
&&
(
location
.
pathname
===
'/'
||
location
.
pathname
===
'/home'
))
{
...
@@ -107,6 +108,31 @@ export const Home: React.FC = () => {
...
@@ -107,6 +108,31 @@ export const Home: React.FC = () => {
}
}
}
}
// 获取会话ID并加载历史记录
const
getSessionConversationId
=
async
(
data
?:
any
)
=>
{
try
{
// 从 sessionStorage 获取 toolId 作为 busiId
const
toolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
requestData
=
{
...(
data
||
{}),
busiId
:
toolId
,
}
const
res
=
await
fetchSessionConversationId
(
requestData
)
if
(
res
?.
data
?.
conversationId
)
{
const
conversationId
=
res
.
data
.
conversationId
dispatch
(
setCurrentConversation
(
conversationId
))
dispatch
(
setNavigationFlag
(
true
))
// 获取历史记录
await
fetchUserQaRecordPage
(
conversationId
,
toolId
||
undefined
)
// 历史记录会在 Chat 页面自动渲染,这里只负责获取
}
}
catch
(
error
)
{
console
.
error
(
'获取会话ID失败:'
,
error
)
}
}
// 刷新问题列表
// 刷新问题列表
const
handleRefreshQuestions
=
useCallback
(
async
()
=>
{
const
handleRefreshQuestions
=
useCallback
(
async
()
=>
{
// 先清空旧数据
// 先清空旧数据
...
@@ -260,14 +286,14 @@ export const Home: React.FC = () => {
...
@@ -260,14 +286,14 @@ export const Home: React.FC = () => {
)
)
// 触发自定义事件,通知 ChatEditor 强制重置为制度活化
// 触发自定义事件,通知 ChatEditor 强制重置为制度活化
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
getSessionConversationId
()
dispatch
(
fetchConversations
())
dispatch
(
fetchConversations
())
// 2. 拉取常见问题等业务数据
// 2. 拉取常见问题等业务数据
_handleToolClick
(
false
,
''
,
true
)
_handleToolClick
(
false
,
''
,
true
)
}
}
}
}
else
{
else
{
initConversation
()
getSessionConversationId
()
dispatch
(
fetchConversations
())
dispatch
(
fetchConversations
())
}
}
}
}
...
@@ -296,7 +322,7 @@ export const Home: React.FC = () => {
...
@@ -296,7 +322,7 @@ export const Home: React.FC = () => {
)
)
// 触发自定义事件,通知 ChatEditor 强制重置为制度活化
// 触发自定义事件,通知 ChatEditor 强制重置为制度活化
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
window
.
dispatchEvent
(
new
CustomEvent
(
'forceResetToGeneralMode'
))
initConversation
()
getSessionConversationId
()
dispatch
(
fetchConversations
())
dispatch
(
fetchConversations
())
// 2. 拉取常见问题等业务数据
// 2. 拉取常见问题等业务数据
_handleToolClick
(
false
,
''
,
true
)
_handleToolClick
(
false
,
''
,
true
)
...
...
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