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
af79aca0
Commit
af79aca0
authored
Dec 10, 2025
by
Liu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:常见问题换一换时更新
parent
35fc01e1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
27 deletions
+56
-27
src/pages/Home/HomeNew.tsx
+37
-0
src/pages/Home/components/QuestionList/QuestionList.tsx
+19
-27
No files found.
src/pages/Home/HomeNew.tsx
View file @
af79aca0
...
...
@@ -77,6 +77,42 @@ export const Home: React.FC = () => {
}
}
// 刷新问题列表
const
handleRefreshQuestions
=
useCallback
(
async
()
=>
{
// 先清空旧数据
setOtherQuestions
((
prev
:
any
)
=>
({
...
prev
,
content
:
[],
}))
setIsDataLoaded
(
false
)
// 重置加载状态
try
{
// 获取当前的 toolId,优先从 sessionStorage 获取,其次从 Redux 获取
const
sessionToolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
const
searchParams
=
new
URLSearchParams
(
location
.
search
)
const
urlToolId
=
searchParams
.
get
(
'toolId'
)
||
''
const
finalToolId
=
sessionToolId
||
urlToolId
// 调用接口重新获取问题列表
const
res
=
await
fetchEfficiencyQuestionList
({
toolId
:
finalToolId
,
})
if
(
res
&&
res
.
data
&&
res
.
data
.
questions
)
{
setOtherQuestions
((
prev
:
any
)
=>
({
...
prev
,
content
:
res
.
data
.
questions
||
[],
}))
}
}
catch
(
error
)
{
console
.
error
(
'刷新问题列表失败:'
,
error
)
throw
error
// 抛出错误,让 QuestionList 组件处理
}
finally
{
setIsDataLoaded
(
true
)
// 无论成功失败都标记为已加载
}
},
[
location
.
search
])
// 处理工具按钮点击
const
_handleToolClick
=
useCallback
(
async
(
isToolBtn
:
boolean
,
toolId
?:
string
,
ignoreUrlToolId
?:
boolean
)
=>
{
// 提质增效模式 / 数据助手 / 通用模式:都先清空数据,重新拉常见问题
...
...
@@ -286,6 +322,7 @@ export const Home: React.FC = () => {
iconImg=
{
HomeIcon2
}
isToolBtn=
{
shouldChangeStyle
}
isLoaded=
{
isDataLoaded
}
onRefresh=
{
handleRefreshQuestions
}
/>
</
motion
.
div
>
{
shouldChangeStyle
&&
(
...
...
src/pages/Home/components/QuestionList/QuestionList.tsx
View file @
af79aca0
...
...
@@ -6,7 +6,6 @@ import { useCallback, useEffect, useState } from 'react'
import
{
useNavigate
}
from
'react-router-dom'
import
Refresh
from
'@/assets/svg/refresh.svg?react'
import
{
type
WithAuthProps
,
withAuth
}
from
'@/auth/withAuth'
import
{
fetchEfficiencyQuestionList
}
from
'@/api/home'
import
{
useAppDispatch
,
useAppSelector
}
from
'@/store/hook'
import
{
createConversation
,
setCurrentConversation
,
setShouldSendQuestion
}
from
'@/store/conversationSlice'
import
{
safeSessionStorageGetItem
}
from
'@/lib/utils'
...
...
@@ -23,6 +22,7 @@ interface QuestionListProps {
height
?:
string
isToolBtn
?:
boolean
isLoaded
?:
boolean
onRefresh
?:
()
=>
Promise
<
void
>
}
const
containerVariants
=
{
hidden
:
{},
...
...
@@ -70,11 +70,11 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
displayCount
:
_displayCount
=
6
,
isToolBtn
=
false
,
isLoaded
=
false
,
onRefresh
,
})
=>
{
const
[
isRotating
,
setIsRotating
]
=
useState
(
false
)
const
[
displayedItems
,
setDisplayedItems
]
=
useState
<
string
[]
>
([])
const
[
isClicking
,
setIsClicking
]
=
useState
(
false
)
const
[
fetchedQuestions
,
setFetchedQuestions
]
=
useState
<
string
[]
|
null
>
(
null
)
const
dispatch
=
useAppDispatch
()
const
navigate
=
useNavigate
()
const
{
currentConversationId
,
conversations
,
currentToolId
}
=
useAppSelector
(
state
=>
state
.
conversation
)
...
...
@@ -82,36 +82,25 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
// 根据 isToolBtn 动态设置 displayCount
const
actualDisplayCount
=
isToolBtn
?
6
:
4
const
updateDisplayedItems
=
useCallback
(
(
customQuestions
?:
string
[])
=>
{
const
sourceQuestions
=
(
customQuestions
&&
customQuestions
.
length
>
0
)
?
customQuestions
:
(
fetchedQuestions
&&
fetchedQuestions
.
length
>
0
?
fetchedQuestions
:
questions
)
if
(
!
sourceQuestions
.
length
)
{
return
}
const
indices
=
getRandomIndices
(
sourceQuestions
.
length
,
Math
.
min
(
actualDisplayCount
,
sourceQuestions
.
length
))
setDisplayedItems
(
indices
.
map
(
index
=>
sourceQuestions
[
index
]))
},
[
questions
,
fetchedQuestions
,
actualDisplayCount
],
)
const
updateDisplayedItems
=
useCallback
(()
=>
{
const
indices
=
getRandomIndices
(
questions
.
length
,
Math
.
min
(
actualDisplayCount
,
questions
.
length
))
setDisplayedItems
(
indices
.
map
(
index
=>
questions
[
index
]))
},
[
questions
,
actualDisplayCount
])
const
handleRefresh
=
async
()
=>
{
// 如果没有提供 onRefresh 回调,则不执行任何操作
if
(
!
onRefresh
)
{
return
}
setIsRotating
(
true
)
const
toolId
=
safeSessionStorageGetItem
(
'currentToolId'
)
||
''
try
{
const
res
=
await
fetchEfficiencyQuestionList
({
toolId
})
const
newQuestions
=
res
?.
data
?.
questions
as
string
[]
|
undefined
if
(
newQuestions
?.
length
)
{
setFetchedQuestions
(
newQuestions
)
updateDisplayedItems
(
newQuestions
)
return
}
updateDisplayedItems
()
// 重新调用接口获取新问题
await
onRefresh
()
}
catch
(
error
)
{
console
.
error
(
'刷新
常见问题
失败:'
,
error
)
updateDisplayedItems
()
console
.
error
(
'刷新
问题列表
失败:'
,
error
)
// 接口调用失败时不回退到随机选择,保持当前状态
}
finally
{
setIsRotating
(
false
)
...
...
@@ -158,6 +147,9 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
updateDisplayedItems
()
},
[
updateDisplayedItems
])
// 当上游将 questions 清空时,立即清空展示项,避免短暂显示旧数据
const
itemsToRender
=
questions
.
length
===
0
?
[]
:
displayedItems
return
(
<
div
className=
"bg-white box-border px-[20px] py-[12px] w-full sm:w-[300px] md:w-[300px]"
...
...
@@ -207,7 +199,7 @@ const QuestionListBase: React.FC<QuestionListProps & WithAuthProps> = ({
animate=
"visible"
className=
"mt-[8px] flex flex-col gap-[8px] w-full"
>
{
displayedItems
.
map
((
item
,
index
)
=>
(
{
itemsToRender
.
map
((
item
,
index
)
=>
(
<
motion
.
li
key=
{
`question-${item}`
}
custom=
{
index
}
...
...
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