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
15ee66aa
Commit
15ee66aa
authored
Feb 02, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:提质增效欢迎语
parent
d8478402
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
7 deletions
+50
-7
src/pages/Chat/Chat.tsx
+34
-1
src/pages/Chat/components/ChatWelcome/index.tsx
+16
-6
No files found.
src/pages/Chat/Chat.tsx
View file @
15ee66aa
...
@@ -62,6 +62,9 @@ export const Chat: React.FC = () => {
...
@@ -62,6 +62,9 @@ export const Chat: React.FC = () => {
const
processingConversationIdRef
=
useRef
<
string
|
null
>
(
null
)
const
processingConversationIdRef
=
useRef
<
string
|
null
>
(
null
)
// 标记是否为提质增效模式的自动调用(用于提取欢迎语)
// 标记是否为提质增效模式的自动调用(用于提取欢迎语)
const
isAutoSubmitQualityImprovementRef
=
useRef
<
boolean
>
(
false
)
const
isAutoSubmitQualityImprovementRef
=
useRef
<
boolean
>
(
false
)
// 提质增效自动调用欢迎语候选(用于流结束后写入 sessionStorage)
const
autoWelcomeCandidateRef
=
useRef
<
string
>
(
''
)
const
hasAutoWelcomeCandidateRef
=
useRef
<
boolean
>
(
false
)
// 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时,
// 当外部系统直接以 /chat/:id 链接进入(没有 location.state,且 URL 中也没有 toolId)时,
// 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
// 视为一次新的会话入口:重置为制度活化,清除历史遗留的工具模式状态
...
@@ -145,7 +148,22 @@ export const Chat: React.FC = () => {
...
@@ -145,7 +148,22 @@ export const Chat: React.FC = () => {
const
lastIndex
=
newItems
.
length
-
1
const
lastIndex
=
newItems
.
length
-
1
const
isEmptyQuestion
=
!
question
.
trim
()
const
isEmptyQuestion
=
!
question
.
trim
()
// 提质增效模式下,自动调用时第一个数据块作为欢迎语
// 提质增效模式下,自动调用时收集首个有效 answer 作为欢迎语候选(按流式增量累积)
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
)
{
const
chunkAnswer
=
msg
?.
content
?.
data
?.
answer
if
(
typeof
chunkAnswer
===
'string'
)
{
// 仅对当前分片做基础清洗,避免重复累积整段答案导致内容重复
let
cleanedChunk
=
chunkAnswer
.
replace
(
/
\([^
)
]
*
\)
/g
,
''
)
cleanedChunk
=
cleanedChunk
.
replace
(
/
\[
参考文档
(?:
《
[^
》
]
*》
\s
*
)
+
\]
/g
,
''
)
cleanedChunk
=
trimSpacesOnly
(
cleanedChunk
)
if
(
cleanedChunk
.
trim
())
{
autoWelcomeCandidateRef
.
current
=
(
autoWelcomeCandidateRef
.
current
||
''
)
+
cleanedChunk
hasAutoWelcomeCandidateRef
.
current
=
true
}
}
}
// 提质增效模式下,自动调用时第一个数据块作为欢迎语(兼容旧逻辑,仍保留对 system.welcomeText 的写入)
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
&&
msg
.
content
.
data
.
answer
)
{
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
isEmptyQuestion
&&
msg
.
content
.
data
.
answer
)
{
// 判断是否为第一个数据块(只有 system 记录或最后一个记录是 system)
// 判断是否为第一个数据块(只有 system 记录或最后一个记录是 system)
const
isFirstChunk
=
newItems
.
length
===
1
&&
newItems
[
0
].
role
===
'system'
const
isFirstChunk
=
newItems
.
length
===
1
&&
newItems
[
0
].
role
===
'system'
...
@@ -263,6 +281,9 @@ export const Chat: React.FC = () => {
...
@@ -263,6 +281,9 @@ export const Chat: React.FC = () => {
const
isQualityImprovement
=
resolvedToolId
===
'6712395743241'
const
isQualityImprovement
=
resolvedToolId
===
'6712395743241'
isAutoSubmitQualityImprovementRef
.
current
=
isEmptyQuestion
&&
isQualityImprovement
isAutoSubmitQualityImprovementRef
.
current
=
isEmptyQuestion
&&
isQualityImprovement
if
(
isAutoSubmitQualityImprovementRef
.
current
)
{
if
(
isAutoSubmitQualityImprovementRef
.
current
)
{
// 重置欢迎语候选
autoWelcomeCandidateRef
.
current
=
''
hasAutoWelcomeCandidateRef
.
current
=
false
console
.
log
(
'[Chat] 提质增效自动调用 - handleSubmitQuestion 被调用'
,
{
console
.
log
(
'[Chat] 提质增效自动调用 - handleSubmitQuestion 被调用'
,
{
question
,
question
,
resolvedToolId
,
resolvedToolId
,
...
@@ -447,8 +468,20 @@ export const Chat: React.FC = () => {
...
@@ -447,8 +468,20 @@ export const Chat: React.FC = () => {
)
)
.
then
(()
=>
{
.
then
(()
=>
{
// 流结束时执行(通过 Promise resolve 判断)
// 流结束时执行(通过 Promise resolve 判断)
// 如果是提质增效自动调用且本轮存在有效欢迎语候选,将其写入 sessionStorage 供欢迎语使用
if
(
isAutoSubmitQualityImprovementRef
.
current
&&
hasAutoWelcomeCandidateRef
.
current
)
{
try
{
const
key
=
'qualityWelcomeText'
sessionStorage
.
setItem
(
key
,
autoWelcomeCandidateRef
.
current
)
}
catch
(
error
)
{
console
.
error
(
'[Chat] 写入提质增效欢迎语到 sessionStorage 失败:'
,
error
)
}
}
// 清除自动调用标记
// 清除自动调用标记
isAutoSubmitQualityImprovementRef
.
current
=
false
isAutoSubmitQualityImprovementRef
.
current
=
false
autoWelcomeCandidateRef
.
current
=
''
hasAutoWelcomeCandidateRef
.
current
=
false
// 设置最后一条 AI 回答的 endAnswerFlag,用于控制打字效果结束
// 设置最后一条 AI 回答的 endAnswerFlag,用于控制打字效果结束
setAllItems
((
prevItems
)
=>
{
setAllItems
((
prevItems
)
=>
{
const
newItems
=
[...
prevItems
]
const
newItems
=
[...
prevItems
]
...
...
src/pages/Chat/components/ChatWelcome/index.tsx
View file @
15ee66aa
...
@@ -13,22 +13,32 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ toolName: _toolName, w
...
@@ -13,22 +13,32 @@ export const ChatWelcome: React.FC<ChatWelcomeProps> = ({ toolName: _toolName, w
// 根据不同的 toolName 显示不同的提示语
// 根据不同的 toolName 显示不同的提示语
const
getWelcomeText
=
()
=>
{
const
getWelcomeText
=
()
=>
{
// 优先使用从接口返回的欢迎语(
提质增效模式自动调用时
)
// 优先使用从接口返回的欢迎语(
历史逻辑
)
if
(
welcomeText
)
{
if
(
welcomeText
)
{
return
welcomeText
return
welcomeText
}
}
// 回退到
原有的 toolId 判断
逻辑
// 回退到
基于当前工具的欢迎语
逻辑
const
currentToolId
=
typeof
window
!==
'undefined'
?
sessionStorage
.
getItem
(
'currentToolId'
)
:
''
const
currentToolId
=
typeof
window
!==
'undefined'
?
sessionStorage
.
getItem
(
'currentToolId'
)
:
''
if
(
currentToolId
===
'6712395743240'
)
{
// 提质增效:若 sessionStorage 中已有自动调用写入的欢迎语,优先使用该文案
return
'Hi~我是您的数据助手,可以帮你查询业务数据哦'
}
if
(
currentToolId
===
'6712395743241'
)
{
if
(
currentToolId
===
'6712395743241'
)
{
try
{
const
stored
=
typeof
window
!==
'undefined'
?
sessionStorage
.
getItem
(
'qualityWelcomeText'
)
:
null
if
(
stored
&&
stored
.
trim
())
{
return
stored
}
}
catch
{
// 读取失败时回退到默认文案
}
return
'Hi,我是AI提质增效助手,可以为您解答研发需求计划和业务功能流程等相关问题。请问有什么可以帮您?'
return
'Hi,我是AI提质增效助手,可以为您解答研发需求计划和业务功能流程等相关问题。请问有什么可以帮您?'
}
}
if
(
currentToolId
===
'6712395743240'
)
{
return
'Hi~我是您的数据助手,可以帮你查询业务数据哦'
}
return
'Hi,我是AI制度活化助手,可以为您提供公司规章制度、政策条款的查询与解读服务。请问您想了解什么呢?'
return
'Hi,我是AI制度活化助手,可以为您提供公司规章制度、政策条款的查询与解读服务。请问您想了解什么呢?'
}
}
...
...
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