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
749ccdec
Commit
749ccdec
authored
Dec 08, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:欢迎语
parent
276e093c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
11 deletions
+13
-11
src/components/ChatEditor/index.tsx
+13
-11
No files found.
src/components/ChatEditor/index.tsx
View file @
749ccdec
...
...
@@ -40,14 +40,13 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
const
[
searchParams
,
setSearchParams
]
=
useSearchParams
()
const
location
=
useLocation
()
const
toolIdFromUrl
=
searchParams
.
get
(
'toolId'
)
const
fromCollect
=
location
.
state
?.
fromCollect
// 获取工具列表
const
getToolList
=
async
()
=>
{
try
{
// 从路由中获取 userRoles 参数
const
userRoles
=
getUserRolesForApi
()
// eslint-disable-next-line no-console
console
.
log
(
'[ChatEditor] 获取到的 userRoles 参数:'
,
userRoles
,
'类型:'
,
Array
.
isArray
(
userRoles
)
?
'array'
:
typeof
userRoles
)
// 调用真实 API 获取工具列表
const
res
=
await
fetchToolList
({
userRoles
})
if
(
res
?.
data
&&
Array
.
isArray
(
res
.
data
)
&&
res
.
data
.
length
>
0
)
{
...
...
@@ -61,7 +60,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 根据 currentToolId 以及 sessionStorage 中的记录决定高亮逻辑
useEffect
(()
=>
{
if
(
currentToolId
&&
!
sessionToolId
)
{
if
(
currentToolId
&&
!
sessionToolId
&&
!
fromCollect
)
{
// 清除过期的 Redux 值
dispatch
(
clearCurrentToolId
())
// 如果 URL 中还有 toolId,也清除它
...
...
@@ -108,7 +107,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setSelectedToolId
(
null
)
setIsToolBtnActive
(
true
)
}
},
[
currentToolId
,
sessionToolId
,
toolIdFromUrl
,
searchParams
,
setSearchParams
])
},
[
currentToolId
,
sessionToolId
,
toolIdFromUrl
,
searchParams
,
setSearchParams
,
fromCollect
])
// 监听 sessionStorage 中的 currentToolId(历史点击时写入)来辅助高亮逻辑
useEffect
(()
=>
{
...
...
@@ -226,6 +225,8 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
safeSessionStorageRemoveItem
(
'currentToolId'
)
setSessionToolId
(
null
)
setShowToolQuestion
(
false
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
true
,
undefined
,
'通用模式'
,
false
)
// 清空路由中的 toolId 参数
if
(
toolIdFromUrl
)
{
const
newSearchParams
=
new
URLSearchParams
(
searchParams
)
...
...
@@ -238,7 +239,6 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
})).
unwrap
()
onToolClick
?.(
true
,
undefined
,
'通用模式'
,
false
)
}
catch
(
error
)
{
console
.
error
(
'创建会话失败:'
,
error
)
...
...
@@ -260,13 +260,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
setIsToolBtnActive
(
false
)
safeSessionStorageSetItem
(
'currentToolId'
,
tool
.
toolId
)
setSessionToolId
(
tool
.
toolId
)
// 先通知上层更新欢迎语(即便后续接口异常也能生效)
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
)
try
{
await
dispatch
(
createConversation
({
conversationData
:
{
toolId
:
tool
.
toolId
},
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
})).
unwrap
()
onToolClick
?.(
false
,
tool
.
toolId
,
tool
.
toolName
,
true
)
}
catch
(
error
)
{
console
.
error
(
'创建会话失败:'
,
error
)
...
...
@@ -422,13 +423,14 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
// 处理后端返回的 base64 图标
const
getToolIconSrc
=
()
=>
{
if
(
!
tool
.
toolIcon
)
const
icon
=
tool
.
toolIcon
if
(
!
icon
)
return
''
//
如果已经是完整的 data URL,
直接返回
if
(
tool
.
toolIcon
.
startsWith
(
'data:
'
))
return
tool
.
toolI
con
//
已经是完整的 data URL 或 http 链接时
直接返回
if
(
icon
.
startsWith
(
'data:'
)
||
icon
.
startsWith
(
'http
'
))
return
i
con
// 否则拼接为 base64 图片格式
return
`data:image/png;base64,${
tool.toolI
con}`
return
`data:image/png;base64,${
i
con}`
}
return
(
...
...
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