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
32c6981d
Commit
32c6981d
authored
Sep 29, 2025
by
weiyudumei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复收藏按钮重复调用接口问题
- 移除React.StrictMode避免开发环境副作用重复执行 - 在ChatAnswerOperate中添加防重复调用机制 - 增加错误处理和状态回滚逻辑
parent
f3d9b624
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
14 deletions
+33
-14
src/index.tsx
+3
-5
src/pages/Chat/components/ChatItem/ChatAnswerOperate.tsx
+30
-9
No files found.
src/index.tsx
View file @
32c6981d
...
...
@@ -29,10 +29,8 @@ if (!Object.hasOwn) {
if
(
rootEl
)
{
const
root
=
ReactDOM
.
createRoot
(
rootEl
)
root
.
render
(
<
React
.
StrictMode
>
<
HeroUIProvider
className=
"h-full"
>
<
App
/>
</
HeroUIProvider
>
</
React
.
StrictMode
>,
<
HeroUIProvider
className=
"h-full"
>
<
App
/>
</
HeroUIProvider
>,
)
}
src/pages/Chat/components/ChatItem/ChatAnswerOperate.tsx
View file @
32c6981d
import
{
Button
,
Tooltip
}
from
'@heroui/react'
import
{
useState
}
from
'react'
import
{
use
Ref
,
use
State
}
from
'react'
import
{
useDebounceFn
}
from
'ahooks'
import
type
{
Answer
}
from
'@/types/chat'
import
CollectIcon
from
'@/assets/svg/shouc.svg?react'
...
...
@@ -17,18 +17,39 @@ export const ChatAnswerOperate: React.FC<ChatAnswerOperateProps> = ({ answer })
// const [isLike, setIsLike] = useState(answer.feedbackStatus === '01')
// const [isUnLike, setIsUnLike] = useState(answer.feedbackStatus === '02')
const
[
isOpenUnLikeModal
,
setIsOpenUnLikeOpen
]
=
useState
(
false
)
const
isProcessingRef
=
useRef
(
false
)
const
handleCollect
=
useDebounceFn
(
async
()
=>
{
if
(
!
isCollect
)
{
setIsCollect
(
true
)
const
res
=
await
fetchSubmitCollection
(
answer
.
recordId
||
''
)
if
(
res
.
ok
)
{
showToast
(
'收藏成功!'
,
'success'
)
// 防止重复调用
if
(
isProcessingRef
.
current
)
{
return
}
isProcessingRef
.
current
=
true
try
{
if
(
!
isCollect
)
{
setIsCollect
(
true
)
const
res
=
await
fetchSubmitCollection
(
answer
.
recordId
||
''
)
if
(
res
.
ok
)
{
showToast
(
'收藏成功!'
,
'success'
)
}
else
{
// 如果请求失败,回滚状态
setIsCollect
(
false
)
}
}
else
{
setIsCollect
(
false
)
const
res
=
await
fetchCancelCollection
(
answer
.
recordId
||
''
)
if
(
!
res
.
ok
)
{
// 如果请求失败,回滚状态
setIsCollect
(
true
)
}
}
}
else
{
setIsCollect
(
false
)
await
fetchCancelCollection
(
answer
.
recordId
||
''
)
finally
{
isProcessingRef
.
current
=
false
}
},
{
wait
:
200
})
...
...
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