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
bde8ec13
Commit
bde8ec13
authored
Apr 15, 2026
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:业务洞察常见问题逻辑
parent
89aa960c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
76 additions
and
5 deletions
+76
-5
src/api/chat.ts
+10
-0
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
+1
-0
src/pages/Chat/Chat.tsx
+1
-1
src/pages/Home/HomeNew.tsx
+64
-4
No files found.
src/api/chat.ts
View file @
bde8ec13
...
@@ -235,3 +235,13 @@ export function fetchOrderQueryRecommendQuestion(
...
@@ -235,3 +235,13 @@ export function fetchOrderQueryRecommendQuestion(
export
function
fetchTerminateQuestion
(
params
:
any
)
{
export
function
fetchTerminateQuestion
(
params
:
any
)
{
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/terminate_question'
,
params
)
return
http
.
post
(
'/conversation/api/conversation/mobile/v1/terminate_question'
,
params
)
}
}
/**
* 获取业务洞察常见问题list
* @param params
* configTypeList: ['10']
* @returns Promise<any>
*/
export
function
fetchBusinessInsightList
(
params
:
any
)
{
return
http
.
post
(
'/conversation/api/commonconfig/mobile/v1/query_config_list'
,
params
)
}
src/layouts/HistoryBar/components/HistoryBarList/index.tsx
View file @
bde8ec13
...
@@ -76,6 +76,7 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
...
@@ -76,6 +76,7 @@ export const HistoryBarList: React.FC<HistoryBarListProps> = ({ searchValue, onS
toolName
:
''
,
toolName
:
''
,
shouldChangeStyle
:
true
,
shouldChangeStyle
:
true
,
conversationId
:
conversation
.
conversationId
,
conversationId
:
conversation
.
conversationId
,
source
:
'history'
,
},
},
}))
}))
}
}
...
...
src/pages/Chat/Chat.tsx
View file @
bde8ec13
...
@@ -1115,7 +1115,7 @@ export const Chat: React.FC = () => {
...
@@ -1115,7 +1115,7 @@ export const Chat: React.FC = () => {
// 只在真正的工具切换时触发事件(有 conversationId 时),避免 loading 状态更新时重复触发
// 只在真正的工具切换时触发事件(有 conversationId 时),避免 loading 状态更新时重复触发
if
(
conversationId
)
{
if
(
conversationId
)
{
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
window
.
dispatchEvent
(
new
CustomEvent
(
'toolButtonClick'
,
{
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
},
detail
:
{
isToolBtn
,
toolId
,
toolName
,
shouldChangeStyle
,
conversationId
,
source
:
'toolButton'
},
}))
}))
}
}
}
}
}
}
...
...
src/pages/Home/HomeNew.tsx
View file @
bde8ec13
...
@@ -13,7 +13,7 @@ import { fetchEfficiencyQuestionList } from '@/api/home'
...
@@ -13,7 +13,7 @@ import { fetchEfficiencyQuestionList } from '@/api/home'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
SdreamLoading
from
'@/components/SdreamLoading'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
fetchLoginByToken
,
fetchLoginByUid
}
from
'@/api/common'
import
{
fetchSessionConversationId
}
from
'@/api/conversation'
import
{
fetchSessionConversationId
}
from
'@/api/conversation'
import
{
fetchCheckTokenApi
}
from
'@/api/chat'
import
{
fetch
BusinessInsightList
,
fetch
CheckTokenApi
}
from
'@/api/chat'
import
{
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorageRemoveItem
,
safeSessionStorageSetItem
,
waitForToken
}
from
'@/lib/utils'
import
{
getUserRolesFromRoute
,
safeLocalStorageGetItem
,
safeLocalStorageSetItem
,
safeSessionStorageGetItem
,
safeSessionStorageRemoveItem
,
safeSessionStorageSetItem
,
waitForToken
}
from
'@/lib/utils'
// 从 localStorage 获取 token 的辅助函数
// 从 localStorage 获取 token 的辅助函数
...
@@ -75,6 +75,7 @@ export const Home: React.FC = () => {
...
@@ -75,6 +75,7 @@ export const Home: React.FC = () => {
const
[
otherQuestions
,
setOtherQuestions
]
=
useState
<
any
>
({
content
:
[]
})
const
[
otherQuestions
,
setOtherQuestions
]
=
useState
<
any
>
({
content
:
[]
})
const
[
isToolBtnActive
,
setIsToolBtnActive
]
=
useState
<
boolean
>
(
false
)
const
[
isToolBtnActive
,
setIsToolBtnActive
]
=
useState
<
boolean
>
(
false
)
const
[
shouldChangeStyle
,
setShouldChangeStyle
]
=
useState
<
boolean
>
(
true
)
const
[
shouldChangeStyle
,
setShouldChangeStyle
]
=
useState
<
boolean
>
(
true
)
const
[
isBusinessInsightMode
,
setIsBusinessInsightMode
]
=
useState
<
boolean
>
(
false
)
// 保存原始的configType为07的数据
// 保存原始的configType为07的数据
const
[
originalOtherQuestions
,
_setOriginalOtherQuestions
]
=
useState
<
any
>
({
content
:
[]
})
const
[
originalOtherQuestions
,
_setOriginalOtherQuestions
]
=
useState
<
any
>
({
content
:
[]
})
...
@@ -86,6 +87,35 @@ export const Home: React.FC = () => {
...
@@ -86,6 +87,35 @@ export const Home: React.FC = () => {
defaultValue
:
''
,
defaultValue
:
''
,
})
})
const
parseBusinessInsightQuestions
=
(
rawContent
:
unknown
):
string
[]
=>
{
if
(
Array
.
isArray
(
rawContent
))
{
return
rawContent
.
filter
((
item
):
item
is
string
=>
typeof
item
===
'string'
).
map
(
item
=>
item
.
trim
()).
filter
(
Boolean
)
}
if
(
typeof
rawContent
===
'string'
)
{
try
{
const
parsed
=
JSON
.
parse
(
rawContent
)
if
(
Array
.
isArray
(
parsed
))
{
return
parsed
.
filter
((
item
):
item
is
string
=>
typeof
item
===
'string'
).
map
(
item
=>
item
.
trim
()).
filter
(
Boolean
)
}
}
catch
{
return
[]
}
}
return
[]
}
const
fetchBusinessInsightQuestions
=
useCallback
(
async
()
=>
{
const
res
=
await
fetchBusinessInsightList
({
configTypeList
:
[
'10'
]
})
const
data
=
Array
.
isArray
(
res
?.
data
)
?
res
.
data
[
0
]
:
res
?.
data
const
normalized
=
parseBusinessInsightQuestions
(
data
?.
content
??
data
?.
questionList
)
setOtherQuestions
((
prev
:
any
)
=>
({
...
prev
,
configName
:
data
?.
configName
||
'业务洞察'
,
content
:
normalized
,
}))
},
[])
// 根据 toolId 获取对应的 recordType
// 根据 toolId 获取对应的 recordType
const
getRecordTypeByToolId
=
(
toolId
:
string
|
null
|
undefined
):
string
=>
{
const
getRecordTypeByToolId
=
(
toolId
:
string
|
null
|
undefined
):
string
=>
{
if
(
!
toolId
)
{
if
(
!
toolId
)
{
...
@@ -140,6 +170,11 @@ export const Home: React.FC = () => {
...
@@ -140,6 +170,11 @@ export const Home: React.FC = () => {
setIsDataLoaded
(
false
)
// 重置加载状态
setIsDataLoaded
(
false
)
// 重置加载状态
try
{
try
{
if
(
isBusinessInsightMode
)
{
await
fetchBusinessInsightQuestions
()
return
}
// 从路由中获取 conversationId
// 从路由中获取 conversationId
const
conversationId
=
location
.
pathname
.
startsWith
(
'/chat/'
)
const
conversationId
=
location
.
pathname
.
startsWith
(
'/chat/'
)
?
location
.
pathname
.
split
(
'/'
)[
2
]
?
location
.
pathname
.
split
(
'/'
)[
2
]
...
@@ -173,11 +208,12 @@ export const Home: React.FC = () => {
...
@@ -173,11 +208,12 @@ export const Home: React.FC = () => {
finally
{
finally
{
setIsDataLoaded
(
true
)
// 无论成功失败都标记为已加载
setIsDataLoaded
(
true
)
// 无论成功失败都标记为已加载
}
}
},
[
location
.
search
])
},
[
location
.
search
,
isBusinessInsightMode
,
fetchBusinessInsightQuestions
])
// 处理工具按钮点击
// 处理工具按钮点击
const
_handleToolClick
=
useCallback
(
async
(
isToolBtn
:
boolean
,
toolId
?:
string
,
ignoreUrlToolId
?:
boolean
,
conversationIdParam
?:
string
|
null
)
=>
{
const
_handleToolClick
=
useCallback
(
async
(
isToolBtn
:
boolean
,
toolId
?:
string
,
ignoreUrlToolId
?:
boolean
,
conversationIdParam
?:
string
|
null
)
=>
{
// 提质增效模式 / 数据助手 / 制度活化:都先清空数据,重新拉常见问题
// 提质增效模式 / 数据助手 / 制度活化:都先清空数据,重新拉常见问题
setIsBusinessInsightMode
(
false
)
setOtherQuestions
((
prev
:
any
)
=>
({
setOtherQuestions
((
prev
:
any
)
=>
({
...
prev
,
...
prev
,
content
:
[],
content
:
[],
...
@@ -241,7 +277,7 @@ export const Home: React.FC = () => {
...
@@ -241,7 +277,7 @@ export const Home: React.FC = () => {
// 监听工具按钮点击事件
// 监听工具按钮点击事件
useEffect
(()
=>
{
useEffect
(()
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
const
handleToolClickEvent
=
(
event
:
CustomEvent
)
=>
{
const
{
isToolBtn
,
toolId
,
conversationId
}
=
event
.
detail
const
{
isToolBtn
,
toolId
,
conversationId
,
toolName
,
source
}
=
event
.
detail
setIsToolBtnActive
(
isToolBtn
)
setIsToolBtnActive
(
isToolBtn
)
// 更新样式控制状态
// 更新样式控制状态
setShouldChangeStyle
(
true
)
setShouldChangeStyle
(
true
)
...
@@ -256,6 +292,30 @@ export const Home: React.FC = () => {
...
@@ -256,6 +292,30 @@ export const Home: React.FC = () => {
dispatch
(
clearCurrentToolId
())
dispatch
(
clearCurrentToolId
())
}
}
const
isBusinessInsightClick
=
source
===
'toolButton'
&&
toolName
===
'业务洞察'
// 仅在点击“业务洞察”工具按钮时调用业务洞察常见问题接口;其余情况保持原有逻辑
if
(
isBusinessInsightClick
)
{
setIsBusinessInsightMode
(
true
)
// 先清空旧数据
setOtherQuestions
((
prev
:
any
)
=>
({
...
prev
,
content
:
[],
}))
setIsDataLoaded
(
false
)
fetchBusinessInsightQuestions
()
.
catch
((
error
)
=>
{
console
.
error
(
'[HomeNew] 业务洞察常见问题获取失败:'
,
error
)
})
.
finally
(()
=>
{
setIsDataLoaded
(
true
)
})
return
}
setIsBusinessInsightMode
(
false
)
// 如果事件传递了 conversationId,延迟调用以确保路由更新完成
// 如果事件传递了 conversationId,延迟调用以确保路由更新完成
// 延迟一小段时间(100ms)确保 React Router 已完成路由更新和状态同步
// 延迟一小段时间(100ms)确保 React Router 已完成路由更新和状态同步
if
(
conversationId
)
{
if
(
conversationId
)
{
...
@@ -272,7 +332,7 @@ export const Home: React.FC = () => {
...
@@ -272,7 +332,7 @@ export const Home: React.FC = () => {
return
()
=>
{
return
()
=>
{
window
.
removeEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
window
.
removeEventListener
(
'toolButtonClick'
,
handleToolClickEvent
as
EventListener
)
}
}
},
[
_handleToolClick
,
isToolBtnActive
,
shouldChangeStyle
,
dispatch
])
},
[
_handleToolClick
,
isToolBtnActive
,
shouldChangeStyle
,
dispatch
,
fetchBusinessInsightQuestions
])
// 监听从收藏返回时刷新问题列表的事件
// 监听从收藏返回时刷新问题列表的事件
useEffect
(()
=>
{
useEffect
(()
=>
{
...
...
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