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
1710e03d
Commit
1710e03d
authored
Apr 14, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:历史会话ID和常见问题传参逻辑
parent
8c98a5a1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
5 deletions
+67
-5
package-lock.json
+0
-0
src/components/ChatEditor/index.tsx
+16
-1
src/pages/Home/HomeNew.tsx
+51
-4
No files found.
package-lock.json
View file @
1710e03d
This diff is collapsed.
Click to expand it.
src/components/ChatEditor/index.tsx
View file @
1710e03d
...
@@ -132,10 +132,24 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -132,10 +132,24 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
search
:
location
.
search
,
search
:
location
.
search
,
hideTools
,
hideTools
,
})
})
const
userRoles
=
getUserRolesForApi
()
const
cacheKey
=
`toolList_
${
JSON
.
stringify
(
userRoles
)}
`
const
cached
=
safeSessionStorageGetItem
(
cacheKey
)
if
(
cached
)
{
try
{
const
{
toolList
:
cachedToolList
,
timestamp
}
=
JSON
.
parse
(
cached
)
if
(
Date
.
now
()
-
Number
(
timestamp
||
0
)
<
5
*
60
*
1000
&&
Array
.
isArray
(
cachedToolList
)
&&
cachedToolList
.
length
>
0
)
{
setToolList
(
cachedToolList
)
return
}
}
catch
{
// 缓存解析失败则继续走接口
}
}
// 等待 token 就绪后再调用接口
// 等待 token 就绪后再调用接口
await
waitForToken
()
await
waitForToken
()
// 从路由中获取 userRoles 参数
// 从路由中获取 userRoles 参数
const
userRoles
=
getUserRolesForApi
()
console
.
log
(
'[get_tool_list][ChatEditor] request'
,
{
userRoles
})
console
.
log
(
'[get_tool_list][ChatEditor] request'
,
{
userRoles
})
// 调用真实 API 获取工具列表
// 调用真实 API 获取工具列表
...
@@ -146,6 +160,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
...
@@ -146,6 +160,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
})
})
if
(
res
?.
data
&&
Array
.
isArray
(
res
.
data
)
&&
res
.
data
.
length
>
0
)
{
if
(
res
?.
data
&&
Array
.
isArray
(
res
.
data
)
&&
res
.
data
.
length
>
0
)
{
setToolList
(
res
.
data
)
setToolList
(
res
.
data
)
safeSessionStorageSetItem
(
cacheKey
,
JSON
.
stringify
({
toolList
:
res
.
data
,
timestamp
:
Date
.
now
()
}))
// 仅在“没有任何持久来源”时,才写入默认工具,避免覆盖已有的会话 toolId
// 仅在“没有任何持久来源”时,才写入默认工具,避免覆盖已有的会话 toolId
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
const
hasAnyToolSource
=
Boolean
(
storedToolId
||
currentToolId
||
toolIdFromUrl
)
const
hasAnyToolSource
=
Boolean
(
storedToolId
||
currentToolId
||
toolIdFromUrl
)
...
...
src/pages/Home/HomeNew.tsx
View file @
1710e03d
...
@@ -9,12 +9,12 @@ import HomeIcon2 from '@/assets/homeIcon2.png'
...
@@ -9,12 +9,12 @@ import HomeIcon2 from '@/assets/homeIcon2.png'
import
SmartIce
from
'@/assets/smart-ice.png'
import
SmartIce
from
'@/assets/smart-ice.png'
import
{
fetchConversations
,
setCurrentConversation
,
setCurrentToolId
,
setNavigationFlag
}
from
'@/store/conversationSlice'
import
{
fetchConversations
,
setCurrentConversation
,
setCurrentToolId
,
setNavigationFlag
}
from
'@/store/conversationSlice'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
fetchEfficiencyQuestionList
}
from
'@/api/home'
import
{
fetchEfficiencyQuestionList
,
fetchToolList
}
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
}
from
'@/api/conversation'
import
{
fetchSessionConversationId
}
from
'@/api/conversation'
import
{
fetchCheckTokenApi
}
from
'@/api/chat'
import
{
fetchCheckTokenApi
}
from
'@/api/chat'
import
{
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorageSetItem
,
waitForToken
}
from
'@/lib/utils'
import
{
getUserRolesF
orApi
,
getUserRolesF
romRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorageSetItem
,
waitForToken
}
from
'@/lib/utils'
// 从 localStorage 获取 token 的辅助函数
// 从 localStorage 获取 token 的辅助函数
function
getTokenFromStorage
():
string
|
null
{
function
getTokenFromStorage
():
string
|
null
{
...
@@ -86,6 +86,49 @@ export const Home: React.FC = () => {
...
@@ -86,6 +86,49 @@ export const Home: React.FC = () => {
defaultValue
:
''
,
defaultValue
:
''
,
})
})
const
ensureToolIdReady
=
useCallback
(
async
():
Promise
<
string
>
=>
{
const
storedToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
if
(
storedToolId
)
{
return
storedToolId
}
const
userRoles
=
getUserRolesForApi
()
const
cacheKey
=
`toolList_
${
JSON
.
stringify
(
userRoles
)}
`
let
toolList
:
any
[]
=
[]
const
cached
=
safeSessionStorageGetItem
(
cacheKey
)
if
(
cached
)
{
try
{
const
parsed
=
JSON
.
parse
(
cached
)
if
(
Date
.
now
()
-
Number
(
parsed
?.
timestamp
||
0
)
<
5
*
60
*
1000
&&
Array
.
isArray
(
parsed
?.
toolList
))
{
toolList
=
parsed
.
toolList
}
}
catch
{
toolList
=
[]
}
}
if
(
toolList
.
length
===
0
)
{
const
res
=
await
fetchToolList
({
userRoles
})
if
(
Array
.
isArray
(
res
?.
data
))
{
toolList
=
res
.
data
safeSessionStorageSetItem
(
cacheKey
,
JSON
.
stringify
({
toolList
,
timestamp
:
Date
.
now
()
}))
}
}
const
defaultTool
=
toolList
[
0
]
const
defaultToolId
=
String
(
defaultTool
?.
toolId
||
''
)
if
(
defaultToolId
)
{
safeSessionStorageSetItem
(
'currentToolId'
,
defaultToolId
)
if
(
defaultTool
?.
toolName
)
{
safeSessionStorageSetItem
(
'currentToolName'
,
defaultTool
.
toolName
)
}
dispatch
(
setCurrentToolId
(
defaultToolId
))
}
return
defaultToolId
},
[
dispatch
])
// 根据 toolId 获取对应的 recordType
// 根据 toolId 获取对应的 recordType
const
getRecordTypeByToolId
=
(
toolId
:
string
|
null
|
undefined
):
string
=>
{
const
getRecordTypeByToolId
=
(
toolId
:
string
|
null
|
undefined
):
string
=>
{
if
(
!
toolId
)
{
if
(
!
toolId
)
{
...
@@ -109,8 +152,12 @@ export const Home: React.FC = () => {
...
@@ -109,8 +152,12 @@ export const Home: React.FC = () => {
try
{
try
{
// 等待 token 就绪后再调用接口
// 等待 token 就绪后再调用接口
await
waitForToken
()
await
waitForToken
()
// 仅透传业务方附加参数,busiId/toolId 统一在接口层按 sessionStorage 实时解析
// 首次进入时先确保有默认 toolId,再调用依赖 toolId 的业务接口
const
res
=
await
fetchSessionConversationId
(
data
||
{})
const
toolId
=
await
ensureToolIdReady
()
const
res
=
await
fetchSessionConversationId
({
...(
data
||
{}),
...(
toolId
?
{
toolId
,
busiId
:
toolId
}
:
{}),
})
if
(
res
?.
data
?.
conversationId
)
{
if
(
res
?.
data
?.
conversationId
)
{
const
conversationId
=
res
.
data
.
conversationId
const
conversationId
=
res
.
data
.
conversationId
dispatch
(
setCurrentConversation
(
conversationId
))
dispatch
(
setCurrentConversation
(
conversationId
))
...
...
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