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
6a029a0e
Commit
6a029a0e
authored
Nov 24, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:点击工具时新建会话
parent
187e8a25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
18 deletions
+50
-18
src/components/ChatEditor/index.tsx
+49
-17
src/pages/Chat/components/ChatWelcome/index.tsx
+1
-1
No files found.
src/components/ChatEditor/index.tsx
View file @
6a029a0e
...
...
@@ -6,8 +6,9 @@ import { LoginModal } from '../LoginModal'
import
type
{
RootState
}
from
'@/store'
import
SendIcon
from
'@/assets/svg/send.svg?react'
import
{
type
WithAuthProps
,
withAuth
}
from
'@/auth/withAuth'
import
{
useAppSelector
}
from
'@/store/hook'
import
{
useApp
Dispatch
,
useApp
Selector
}
from
'@/store/hook'
import
{
fetchToolList
}
from
'@/api/home'
import
{
createConversation
}
from
'@/store/conversationSlice'
interface
ChatEditorProps
{
onChange
?:
(
value
:
string
)
=>
void
...
...
@@ -22,6 +23,7 @@ interface ChatEditorProps {
const
ChatEditorBase
:
React
.
FC
<
ChatEditorProps
&
WithAuthProps
>
=
({
checkAuth
,
onChange
,
onFocus
,
onSubmit
,
onToolClick
,
placeholders
,
showContentTips
=
false
,
initialValue
=
''
})
=>
{
// const dispatch = useAppDispatch()
const
[
content
,
setContent
]
=
useState
(
initialValue
)
const
dispatch
=
useAppDispatch
()
const
editorRef
=
useRef
<
HTMLDivElement
>
(
null
)
const
[
currentPlaceholder
,
setCurrentPlaceholder
]
=
useState
(
0
)
const
intervalRef
=
useRef
<
NodeJS
.
Timeout
|
null
>
(
null
)
...
...
@@ -118,21 +120,42 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
document
.
execCommand
(
'insertText'
,
false
,
text
)
}
// 处理通用模式按钮点击
const
handleGeneralClick
=
()
=>
{
// 切换到通用模式(true 表示通用模式,恢复默认不切换左侧)
setIsToolBtnActive
(
true
)
// 清除选中的工具ID
setSelectedToolId
(
null
)
// 调用父组件的回调函数,传递通用模式状态和工具ID,以及是否需要改变样式
onToolClick
?.(
true
,
undefined
,
false
)
// 处理通用模式按钮点击:先创建新会话
const
handleGeneralClick
=
async
()
=>
{
if
(
!
checkAuth
())
return
try
{
await
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
})).
unwrap
()
setIsToolBtnActive
(
true
)
setSelectedToolId
(
null
)
onToolClick
?.(
true
,
undefined
,
false
)
}
catch
(
error
)
{
console
.
error
(
'创建会话失败:'
,
error
)
}
}
// 处理工具按钮点击
const
handleToolClick
=
(
tool
:
any
)
=>
{
setSelectedToolId
(
tool
.
toolId
)
setIsToolBtnActive
(
false
)
onToolClick
?.(
false
,
tool
.
toolId
,
true
)
// 处理工具按钮点击:先创建新会话,再切换工具
const
handleToolClick
=
async
(
tool
:
any
)
=>
{
if
(
!
checkAuth
())
return
try
{
await
dispatch
(
createConversation
({
conversationData
:
{},
shouldNavigate
:
true
,
shouldSendQuestion
:
''
,
})).
unwrap
()
setSelectedToolId
(
tool
.
toolId
)
setIsToolBtnActive
(
false
)
onToolClick
?.(
false
,
tool
.
toolId
,
true
)
}
catch
(
error
)
{
console
.
error
(
'创建会话失败:'
,
error
)
}
}
useEffect
(()
=>
{
...
...
@@ -240,8 +263,17 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
{
toolList
&&
toolList
.
length
>
0
&&
(
<
div
className=
"absolute left-4 bottom-2 flex items-center gap-3 pointer-events-auto pl-[16px]"
>
{
toolList
.
map
((
tool
:
any
,
index
:
number
)
=>
{
// index === 2 的按钮(通用模式)在默认状态下高亮
const
isSelected
=
(
selectedToolId
===
tool
.
toolId
&&
!
isToolBtnActive
)
||
(
index
===
2
&&
isToolBtnActive
)
// index === 1 的按钮(通用模式)在默认状态下高亮
const
isSelected
=
(
selectedToolId
===
tool
.
toolId
&&
!
isToolBtnActive
)
||
(
index
===
1
&&
isToolBtnActive
)
const
handleButtonPress
=
async
()
=>
{
// 高亮状态直接返回,避免重复触发
if
(
isSelected
)
return
if
(
index
===
1
)
await
handleGeneralClick
()
else
await
handleToolClick
(
tool
)
}
return
(
<
Button
key=
{
tool
.
toolId
||
`tool-${index}`
}
...
...
@@ -252,7 +284,7 @@ const ChatEditorBase: React.FC<ChatEditorProps & WithAuthProps> = ({ checkAuth,
}`
}
radius=
"full"
variant=
"bordered"
onPress=
{
()
=>
index
===
2
?
handleGeneralClick
()
:
handleToolClick
(
tool
)
}
onPress=
{
handleButtonPress
}
>
{
tool
.
toolIcon
&&
(
<
img
...
...
src/pages/Chat/components/ChatWelcome/index.tsx
View file @
6a029a0e
...
...
@@ -13,7 +13,7 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ isEfficiencyMode = fal
// 根据模式显示不同的提示语
const
getWelcomeText
=
()
=>
{
if
(
isEfficiencyMode
)
{
return
'HI~
我是您的提质增效助手,有什么可以帮您?
'
return
'HI~
我是您的数据助手,可以帮你查询业务数据哦
'
}
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