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
af45edef
Commit
af45edef
authored
Aug 12, 2025
by
weiw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:收藏页面增加返回功能
parent
9807cfe4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
40 deletions
+89
-40
src/layouts/Navbar/Navbar.tsx
+12
-0
src/pages/Collect/Collect.tsx
+63
-37
src/pages/Home/HomeNew.tsx
+14
-3
No files found.
src/layouts/Navbar/Navbar.tsx
View file @
af45edef
...
...
@@ -59,6 +59,18 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}
if
(
type
===
'collect'
)
{
// 从URL中提取会话ID并存储到 sessionStorage
const
pathParts
=
location
.
pathname
.
split
(
'/'
)
// 从路径中提取会话ID,获取 chat/ 后面的值
// 查找 'chat' 在路径中的位置,然后获取其后一项作为会话ID
const
chatIndex
=
pathParts
.
indexOf
(
'chat'
)
const
conversationId
=
chatIndex
!==
-
1
&&
pathParts
.
length
>
chatIndex
+
1
?
pathParts
[
chatIndex
+
1
]
:
null
if
(
conversationId
)
{
sessionStorage
.
setItem
(
'currentConversationId'
,
conversationId
)
}
navigate
(
'/collect'
)
}
...
...
src/pages/Collect/Collect.tsx
View file @
af45edef
import
{
useEffect
,
useState
}
from
'react'
import
{
Button
,
Modal
,
ModalBody
,
ModalContent
,
ModalFooter
,
ModalHeader
,
Tooltip
}
from
'@heroui/react'
import
{
motion
}
from
'framer-motion'
import
{
useNavigate
}
from
'react-router-dom'
import
{
formatMarkdown
}
from
'../Chat/components/ChatItem/markdownFormatter'
import
{
ChatAnswerAttachment
}
from
'../Chat/components/ChatItem/ChatAnswerAttchment'
import
styles
from
'./Collect.module.less'
...
...
@@ -18,6 +19,8 @@ import ShineBorder from '@/components/ShineBorder'
import
SdreamLoading
from
'@/components/SdreamLoading'
export
const
Collect
:
React
.
FC
=
()
=>
{
const
navigate
=
useNavigate
()
const
[
isLoading
,
setIsLoading
]
=
useState
(
false
)
const
[
isOpen
,
setIsOpen
]
=
useState
(
false
)
const
[
collectList
,
setCollectList
]
=
useState
<
any
>
([])
...
...
@@ -84,6 +87,12 @@ export const Collect: React.FC = () => {
setPageNum
(
pageNum
+
1
)
}
// 添加返回上一页的函数
const
handleGoBack
=
()
=>
{
const
conversationId
=
sessionStorage
.
getItem
(
'currentConversationId'
)
||
''
navigate
(
`/chat/
${
conversationId
}
`
,
{
state
:
{
fromCollect
:
true
}
})
}
useEffect
(()
=>
{
getCollectList
()
},
[
pageNum
])
...
...
@@ -93,13 +102,26 @@ export const Collect: React.FC = () => {
{
/* <ChatSlogan />
<ChatMaskBar /> */
}
<
div
className=
"content h-full overflow-y-auto pt-[24px]"
>
<
motion
.
div
className=
{
`${styles.collectScrollable} scrollbar-hide`
}
<
div
onClick=
{
handleGoBack
}
className=
"flex items-center cursor-pointer text-blue-500 hover:text-blue-700 transition-colors duration-200"
>
<
svg
className=
"w-5 h-5 mr-1"
viewBox=
"0 0 24 24"
fill=
"none"
xmlns=
"http://www.w3.org/2000/svg"
>
<
path
d=
"M19 12H5M12 19L5 12L12 5"
stroke=
"currentColor"
strokeWidth=
"2"
strokeLinecap=
"round"
strokeLinejoin=
"round"
/>
</
svg
>
<
span
className=
"font-medium"
>
返回
</
span
>
</
div
>
<
motion
.
div
className=
{
`${styles.collectScrollable} scrollbar-hide`
}
>
<
div
className=
{
`${styles.inter}`
}
>
{
collectList
.
length
!==
0
&&
(
{
collectList
.
length
!==
0
&&
(
<
motion
.
div
initial=
{
{
opacity
:
0
,
y
:
-
10
}
}
animate=
{
{
opacity
:
1
,
y
:
0
}
}
...
...
@@ -109,16 +131,16 @@ export const Collect: React.FC = () => {
}
}
className=
"flex flex-col gap-[24px]"
>
{
collectList
.
map
((
item
:
any
,
index
:
number
)
=>
(
{
collectList
.
map
((
item
:
any
,
index
:
number
)
=>
(
<
ShineBorder
borderRadius=
{
20
}
className=
"text-[#27353C] w-full max-w-[912px] mx-auto bg-white rounded-[20px] box-border px-[24px] py-[20px]"
key=
{
`${item.collectionId}_${index}`
}
>
<
div
className=
"flex mb-[20px]"
>
<
div
className=
"mr-[20px]"
><
QIcon
/></
div
>
<
div
className=
"mr-[20px]"
>
<
QIcon
/>
</
div
>
<
div
className=
"font-bold text-[16px]"
>
{
item
.
question
}
</
div
>
</
div
>
<
div
className=
"flex"
>
...
...
@@ -126,54 +148,60 @@ export const Collect: React.FC = () => {
<
AIcon
/>
</
div
>
<
div
className=
"flex-1"
>
<
MarkdownDetail
>
{
formatMarkdown
(
item
.
answer
||
''
)
}
</
MarkdownDetail
>
<
MarkdownDetail
>
{
formatMarkdown
(
item
.
answer
||
''
)
}
</
MarkdownDetail
>
{
item
.
cardList
&&
item
.
cardList
?.
length
!==
0
&&
<
ChatAnswerAttachment
answer=
{
item
}
/>
}
<
div
className=
"mt-[12px] flex gap-[4px] justify-between items-center"
>
<
div
className=
"text-12px text-[#B2B8C1]"
>
{
item
.
collectionTime
}
</
div
>
<
div
className=
"text-12px text-[#B2B8C1]"
>
{
item
.
collectionTime
}
</
div
>
<
div
>
<
Tooltip
color=
"foreground"
content=
"复制"
className=
"capitalize"
>
<
Button
variant=
"light"
isIconOnly
aria
-
label=
"CopyIcon"
onPress=
{
()
=>
handleCopy
(
item
)
}
><
CopyIcon
/></
Button
>
<
Button
variant=
"light"
isIconOnly
aria
-
label=
"CopyIcon"
onPress=
{
()
=>
handleCopy
(
item
)
}
>
<
CopyIcon
/>
</
Button
>
</
Tooltip
>
<
Tooltip
color=
"foreground"
content=
"删除"
className=
"capitalize"
>
<
Button
variant=
"light"
isIconOnly
aria
-
label=
"DeleteIcon"
onPress=
{
()
=>
handleDelete
(
item
)
}
><
DeleteIcon
/></
Button
>
<
Button
variant=
"light"
isIconOnly
aria
-
label=
"DeleteIcon"
onPress=
{
()
=>
handleDelete
(
item
)
}
>
<
DeleteIcon
/>
</
Button
>
</
Tooltip
>
</
div
>
</
div
>
</
div
>
</
div
>
</
ShineBorder
>
))
}
))
}
</
motion
.
div
>
)
}
{
collectList
.
length
===
0
&&
!
isLoading
&&
(
)
}
{
collectList
.
length
===
0
&&
!
isLoading
&&
(
<
div
className=
"flex w-full h-full items-center justify-center flex-col"
>
<
EmptyIcon
/>
<
p
className=
"text-[13px] text-[#27353C] mt-[16px]"
>
暂无收藏记录
</
p
>
</
div
>
)
}
{
isLoading
&&
<
div
className=
"w-full flex justify-center items-center"
><
SdreamLoading
/></
div
>
}
{
!
isLoading
&&
collectList
.
length
<
total
&&
(
)
}
{
isLoading
&&
(
<
div
className=
"w-full flex justify-center items-center"
>
<
SdreamLoading
/>
</
div
>
)
}
{
!
isLoading
&&
collectList
.
length
<
total
&&
(
<
div
className=
"w-full max-w-[912px] mx-auto flex justify-center mt-[24px]"
>
<
Button
onPress=
{
handleLoadMore
}
color=
"primary"
variant=
"light"
>
加载更多
</
Button
>
</
div
>
)
}
{
collectList
.
length
===
total
&&
collectList
.
length
!==
0
&&
(
)
}
{
collectList
.
length
===
total
&&
collectList
.
length
!==
0
&&
(
<
div
className=
"w-full mt-[24px] max-w-[912px] mx-auto flex justify-center text-[#8D9795]"
>
到底啦~
</
div
>
)
}
)
}
</
div
>
</
motion
.
div
>
</
div
>
...
...
@@ -188,9 +216,7 @@ export const Collect: React.FC = () => {
确认删除当前收藏内容吗?删除后,此条收藏的内容将不可恢复。
</
ModalBody
>
<
ModalFooter
>
<
Button
onPress=
{
onClose
}
>
再想想
</
Button
>
<
Button
onPress=
{
onClose
}
>
再想想
</
Button
>
<
Button
color=
"primary"
onPress=
{
handleSureDel
}
>
确认
</
Button
>
...
...
src/pages/Home/HomeNew.tsx
View file @
af45edef
import
type
React
from
'react'
import
{
motion
}
from
'framer-motion'
import
{
Outlet
}
from
'react-router-dom'
import
{
Outlet
,
useLocation
}
from
'react-router-dom'
import
{
useEffect
}
from
'react'
import
styles
from
'./Home.module.less'
import
{
QuestionList
}
from
'./components/QuestionList'
...
...
@@ -38,8 +38,12 @@ function getAnimationProps(delay: number) {
export
const
Home
:
React
.
FC
=
()
=>
{
const
dispatch
=
useAppDispatch
()
const
location
=
useLocation
()
useEffect
(()
=>
{
// 在组件挂载时执行dispatch
const
fromCollect
=
location
.
state
?.
fromCollect
// 在组件挂载时执行dispatch,但只执行一次
if
(
!
fromCollect
)
{
dispatch
(
createConversation
({
conversationData
:
{},
...
...
@@ -47,7 +51,14 @@ export const Home: React.FC = () => {
shouldSendQuestion
:
''
,
}),
)
},
[])
// 空依赖数组确保只在组件挂载时执行一次
}
// 清除状态以避免下次影响
if
(
location
.
state
?.
fromCollect
)
{
// 使用 replace 替换当前历史记录,清除 state
window
.
history
.
replaceState
({},
document
.
title
,
window
.
location
.
pathname
)
}
},
[])
// const location = useLocation()
// 检查当前路径是否包含 "/chat/"
...
...
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