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
daeee270
Commit
daeee270
authored
Apr 14, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:默认参数
parent
1710e03d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
21 deletions
+20
-21
src/components/ChatEditor/index.tsx
+13
-16
src/pages/Home/HomeNew.tsx
+7
-5
No files found.
src/components/ChatEditor/index.tsx
View file @
daeee270
...
...
@@ -371,27 +371,24 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 获取默认工具信息
const
defaultTool
=
toolList
.
length
>
0
?
toolList
[
0
]
:
{
toolId
:
''
,
toolName
:
'默认工具'
}
// 通知上层开始 loading
onToolClick
?.(
true
,
String
(
defaultTool
.
toolId
||
''
)
,
defaultTool
.
toolName
,
false
,
undefined
,
true
)
onToolClick
?.(
true
,
undefined
,
defaultTool
.
toolName
,
false
,
undefined
,
true
)
try
{
// 重置提交按钮状态
dispatch
(
setIsAsking
(
false
))
//
你的期望:默认高亮第0个且写入缓存,因此这里不清空 toolId,而是把第0个当作“已选中”
//
制度活化模式:不应携带具体 toolId
const
defaultToolId
=
String
(
defaultTool
.
toolId
||
''
)
dispatch
(
setCurrentToolId
(
defaultToolId
))
dispatch
(
clearCurrentToolId
(
))
// 立即更新本地状态,让 UI 立即响应
setIsToolBtnActive
(
false
)
setSelectedToolId
(
defaultToolId
)
safeSessionStorageRemoveItem
(
'showToolQuestion'
)
// 存入默认高亮按钮信息到缓存
if
(
toolList
.
length
>
0
)
{
safeSessionStorageSetItem
(
'currentToolId'
,
defaultToolId
)
safeSessionStorageSetItem
(
'currentToolName'
,
defaultTool
.
toolName
)
setSessionToolId
(
defaultToolId
)
console
.
log
(
'[chat-toolid-log] ChatEditor defaultTool setSessionToolId:'
,
defaultToolId
,
'| line:364'
)
}
// 清空 toolId 缓存,避免后续接口误带第0个工具的 toolId
safeSessionStorageRemoveItem
(
'currentToolId'
)
setSessionToolId
(
null
)
console
.
log
(
'[chat-toolid-log] ChatEditor clear currentToolId in general mode'
,
'| line:364'
)
setShowToolQuestion
(
false
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
true
,
defaultToolI
d
,
defaultTool
.
toolName
,
false
)
onToolClick
?.(
true
,
undefine
d
,
defaultTool
.
toolName
,
false
)
// 清空路由中的 toolId 参数
if
(
toolIdFromUrl
)
{
const
newSearchParams
=
new
URLSearchParams
(
searchParams
)
...
...
@@ -406,26 +403,26 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
if
(
res
?.
data
?.
conversationId
)
{
const
conversationId
=
res
.
data
.
conversationId
// 获取到会话ID后,通知上层更新欢迎语并传递 conversationId
onToolClick
?.(
true
,
defaultToolI
d
,
defaultTool
.
toolName
,
false
,
conversationId
)
onToolClick
?.(
true
,
undefine
d
,
defaultTool
.
toolName
,
false
,
conversationId
)
// 在 navigate 之前设置标记,避免 Chat 组件的 useEffect 重复调用接口
sessionStorage
.
setItem
(
'toolHistoryLoading'
,
conversationId
)
// 更新路由到新的会话ID
navigate
(
`/chat/
${
conversationId
}
`
,
{
replace
:
true
,
state
:
{
toolId
:
defaultToolI
d
,
toolId
:
undefine
d
,
skipHistoryLoad
:
true
,
// 标记跳过历史记录加载,因为 ChatEditor 会处理
},
})
// 使用获取到的会话ID调用历史会话
await
waitForToken
()
const
qaRes
=
await
fetchUserQaRecordPage
(
conversationId
,
defaultTool
.
toolId
)
const
qaRes
=
await
fetchUserQaRecordPage
(
conversationId
,
''
)
console
.
log
(
'qaRes chatEditor11111'
,
qaRes
)
// 通过自定义事件将历史记录数据传递给父组件进行渲染
window
.
dispatchEvent
(
new
CustomEvent
(
'toolHistoryLoaded'
,
{
detail
:
{
conversationId
,
toolId
:
defaultToolI
d
,
toolId
:
undefine
d
,
toolName
:
defaultTool
.
toolName
,
qaRecords
:
qaRes
?.
data
||
[],
},
...
...
@@ -441,7 +438,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}
finally
{
// 通知上层结束 loading
onToolClick
?.(
true
,
String
(
defaultTool
.
toolId
||
''
)
,
defaultTool
.
toolName
,
false
,
undefined
,
false
)
onToolClick
?.(
true
,
undefined
,
defaultTool
.
toolName
,
false
,
undefined
,
false
)
}
}
...
...
src/pages/Home/HomeNew.tsx
View file @
daeee270
...
...
@@ -7,14 +7,14 @@ import styles from './Home.module.less'
import
{
QuestionList
}
from
'./components/QuestionList'
import
HomeIcon2
from
'@/assets/homeIcon2.png'
import
SmartIce
from
'@/assets/smart-ice.png'
import
{
fetchConversations
,
setCurrentConversation
,
setCurrentToolId
,
setNavigationFlag
}
from
'@/store/conversationSlice'
import
{
clearCurrentToolId
,
fetchConversations
,
setCurrentConversation
,
setCurrentToolId
,
setNavigationFlag
}
from
'@/store/conversationSlice'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
fetchEfficiencyQuestionList
,
fetchToolList
}
from
'@/api/home'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
fetchSessionConversationId
}
from
'@/api/conversation'
import
{
fetchCheckTokenApi
}
from
'@/api/chat'
import
{
getUserRolesForApi
,
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorageSetItem
,
waitForToken
}
from
'@/lib/utils'
import
{
getUserRolesForApi
,
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorage
RemoveItem
,
safeSessionStorage
SetItem
,
waitForToken
}
from
'@/lib/utils'
// 从 localStorage 获取 token 的辅助函数
function
getTokenFromStorage
():
string
|
null
{
...
...
@@ -279,9 +279,11 @@ export const Home: React.FC = () => {
console
.
log
(
'[chat-toolid-log] HomeNew setItem:'
,
toolId
,
'| line:253'
)
}
else
{
// 点击事件没有 toolId 时不覆盖缓存,避免“先清空再被默认第0个回填”
console
.
log
(
'[chat-toolid-log] HomeNew ignore empty toolId event'
,
'| line:260'
)
return
// 制度活化模式:点击事件没有 toolId 时应清空缓存并继续刷新左侧常见问题
dispatch
(
clearCurrentToolId
())
safeSessionStorageRemoveItem
(
'currentToolId'
)
safeSessionStorageRemoveItem
(
'currentToolName'
)
console
.
log
(
'[chat-toolid-log] HomeNew clear currentToolId for general mode'
,
'| line:260'
)
}
// 如果事件传递了 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