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
107247b0
Commit
107247b0
authored
Nov 30, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:不同工具展示不同欢迎语
parent
0db97af0
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
66 additions
and
12 deletions
+66
-12
src/pages/Chat/Chat.tsx
+56
-7
src/pages/Chat/components/ChatWelcome/index.tsx
+10
-5
No files found.
src/pages/Chat/Chat.tsx
View file @
107247b0
...
...
@@ -12,6 +12,7 @@ import { ChatEditor } from '@/components/ChatEditor'
import
type
{
ChatRecord
}
from
'@/types/chat'
import
{
fetchUserQaRecordPage
}
from
'@/api/conversation'
import
{
fetchCheckTokenApi
,
fetchStreamResponse
}
from
'@/api/chat'
import
{
fetchToolList
}
from
'@/api/home'
import
{
clearCurrentToolId
,
clearShouldSendQuestion
,
fetchConversations
,
setCurrentToolId
}
from
'@/store/conversationSlice'
import
type
{
RootState
}
from
'@/store'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
...
...
@@ -30,7 +31,7 @@ export const Chat: React.FC = () => {
const
currentIdRef
=
useRef
<
string
|
undefined
>
(
id
)
const
lastSentQuestionRef
=
useRef
<
string
>
(
''
)
const
abortControllerRef
=
useRef
<
AbortController
|
null
>
(
null
)
const
[
isEfficiencyMode
,
setIsEfficiencyMode
]
=
useState
(
false
)
const
[
currentToolName
,
setCurrentToolName
]
=
useState
<
string
|
undefined
>
(
undefined
)
/** 处理正常stream的数据 */
const
handleStreamMesageData
=
(
msg
:
any
,
question
:
string
)
=>
{
...
...
@@ -281,12 +282,60 @@ export const Chat: React.FC = () => {
}
},
[
shouldSendQuestion
,
isLoading
,
currentToolId
])
// 根据 currentToolId 获取对应的 toolName
useEffect
(()
=>
{
const
getToolNameFromToolId
=
async
()
=>
{
if
(
currentToolId
)
{
try
{
const
userRoles
:
string
[]
=
[]
try
{
const
searchParams
=
new
URLSearchParams
(
window
.
location
.
search
)
const
rolesFromRepeatedKeys
=
searchParams
.
getAll
(
'userRoles'
).
filter
(
Boolean
)
if
(
rolesFromRepeatedKeys
.
length
)
{
userRoles
.
push
(...
Array
.
from
(
new
Set
(
rolesFromRepeatedKeys
)))
}
else
{
const
commaSeparated
=
searchParams
.
get
(
'userRoles'
)
if
(
commaSeparated
)
{
const
roles
=
commaSeparated
.
split
(
','
)
.
map
(
role
=>
role
.
trim
())
.
filter
(
Boolean
)
if
(
roles
.
length
)
{
userRoles
.
push
(...
Array
.
from
(
new
Set
(
roles
)))
}
}
}
}
catch
{
// 忽略错误
}
const
res
=
await
fetchToolList
({
userRoles
})
if
(
res
?.
data
)
{
const
tool
=
res
.
data
.
find
((
t
:
any
)
=>
t
.
toolId
===
currentToolId
)
if
(
tool
?.
toolName
)
{
setCurrentToolName
(
tool
.
toolName
)
}
}
}
catch
(
error
)
{
console
.
error
(
'获取工具列表失败:'
,
error
)
}
}
else
{
// 通用模式
setCurrentToolName
(
'通用模式'
)
}
}
getToolNameFromToolId
()
},
[
currentToolId
])
// 监听工具按钮点击事件,更新 ChatWelcome 提示语和 toolId
useEffect
(()
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
const
{
isToolBtn
,
toolId
}
=
event
.
detail
//
isToolBtn = true 表示通用模式,false 表示提质增效模式
set
IsEfficiencyMode
(
!
isToolBtn
)
const
{
isToolBtn
,
toolId
,
toolName
}
=
event
.
detail
//
保存当前选择的 toolName
set
CurrentToolName
(
toolName
)
// 保存当前选择的 toolId 到 Redux
if
(
!
isToolBtn
&&
toolId
)
{
// 提质增效模式,保存 toolId
...
...
@@ -333,7 +382,7 @@ export const Chat: React.FC = () => {
record.question || record.answerList?.[0]?.answer || ''
}`
}
>
{
record
.
role
===
'system'
&&
<
ChatWelcome
isEfficiencyMode=
{
isEfficiencyMod
e
}
/>
}
{
record
.
role
===
'system'
&&
<
ChatWelcome
toolName=
{
currentToolNam
e
}
/>
}
{
record
.
role
===
'user'
&&
<
ChatItemUser
record=
{
record
}
/>
}
{
record
.
role
===
'ai'
&&
(
<
ChatAnswerBox
...
...
@@ -368,10 +417,10 @@ export const Chat: React.FC = () => {
</
div
>
<
ChatEditor
onSubmit=
{
(
question
,
toolId
)
=>
handleSubmitQuestion
(
question
,
undefined
,
toolId
)
}
onToolClick=
{
(
isToolBtn
,
toolId
,
shouldChangeStyle
)
=>
{
onToolClick=
{
(
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
)
=>
{
// 发送自定义事件到父组件
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
detail
:
{
isToolBtn
,
toolId
,
shouldChangeStyle
},
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
},
}))
}
}
placeholders=
{
[]
}
...
...
src/pages/Chat/components/ChatWelcome/index.tsx
View file @
107247b0
...
...
@@ -4,19 +4,24 @@ import AvatarBot from '@/assets/avatarBot.png'
import
AIIcon
from
'@/assets/ai-icon.png'
interface
ChatWelcomeProps
{
isEfficiencyMode
?:
boolean
toolName
?:
string
}
export
const
ChatWelcome
:
React
.
FC
<
ChatWelcomeProps
>
=
({
isEfficiencyMode
=
fals
e
})
=>
{
export
const
ChatWelcome
:
React
.
FC
<
ChatWelcomeProps
>
=
({
toolNam
e
})
=>
{
const
viteOutputObj
=
import
.
meta
.
env
.
VITE_OUTPUT_OBJ
||
'open'
// 根据
模式
显示不同的提示语
// 根据
不同的 toolName
显示不同的提示语
const
getWelcomeText
=
()
=>
{
if
(
isEfficiencyMode
)
{
switch
(
toolName
)
{
case
'数据助手'
:
return
'HI~我是您的数据助手,可以帮你查询业务数据哦'
}
case
'提质增效'
:
return
'HI~我是您的提质增效助手,有什么可以帮您?'
case
'通用模式'
:
default
:
return
'您好,有什么我可以帮您的吗?'
}
}
return
(
<
div
className=
"chatWelcomeContainer w-full"
>
...
...
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