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
ceee81e4
Commit
ceee81e4
authored
Aug 13, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 处理未登录的情况下不允许进入chat页
parent
79f1f5ac
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
2 deletions
+25
-2
src/layouts/HistoryBar/HistoryBar.tsx
+15
-1
src/layouts/Navbar/Navbar.tsx
+1
-0
src/routes/RouteChangeHandler.tsx
+9
-1
No files found.
src/layouts/HistoryBar/HistoryBar.tsx
View file @
ceee81e4
...
...
@@ -6,13 +6,27 @@ import { HistoryBarList } from './components/HistoryBarList'
import
SearchIcon
from
'@/assets/svg/search.svg?react'
import
HistoryMenuIcon
from
'@/assets/svg/historyMenu.svg?react'
import
{
ConversationModal
}
from
'@/components/ConversationModal'
import
{
useAppSelector
}
from
'@/store/hook'
import
useToast
from
'@/hooks/useToast'
interface
HistoryBarProps
{
isVisible
:
boolean
}
export
const
HistoryBar
:
React
.
FC
<
HistoryBarProps
>
=
({
isVisible
})
=>
{
const
showToast
=
useToast
()
const
[
isOpenConversationModal
,
setIsOpenConversationModal
]
=
useState
(
false
)
const
{
conversations
}
=
useAppSelector
(
state
=>
state
.
conversation
)
const
handleOpen
=
()
=>
{
if
(
conversations
.
length
===
0
)
{
showToast
(
'暂无记录,快去提问吧!'
,
'default'
,
{
icon
:
'🕑'
,
})
return
}
setIsOpenConversationModal
(
true
)
}
return
(
<
AnimatePresence
>
{
isVisible
&&
(
...
...
@@ -31,7 +45,7 @@ export const HistoryBar: React.FC<HistoryBarProps> = ({ isVisible }) => {
<
HistoryBarList
/>
</
div
>
<
div
className=
"text-[12px] border-t-solid border-t-[1px] border-t-[#82969C12] w-full h-[48px] flex items-center justify-center"
>
<
Button
onClick=
{
()
=>
setIsOpenConversationModal
(
true
)
}
className=
"w-full"
color=
"primary"
variant=
"light"
startContent=
{
<
HistoryMenuIcon
/>
}
>
<
Button
onClick=
{
handleOpen
}
className=
"w-full"
color=
"primary"
variant=
"light"
startContent=
{
<
HistoryMenuIcon
/>
}
>
<
span
className=
"text-[#82969C]"
>
管理对话记录
</
span
>
</
Button
>
</
div
>
...
...
src/layouts/Navbar/Navbar.tsx
View file @
ceee81e4
...
...
@@ -44,6 +44,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ isHistoryVisible, c
}
const
handleLogout
=
()
=>
{
onSetHistoryVisible
(
false
)
navigate
(
'/'
)
}
useEffect
(()
=>
{
...
...
src/routes/RouteChangeHandler.tsx
View file @
ceee81e4
import
React
,
{
useEffect
}
from
'react'
import
{
useLocation
}
from
'react-router-dom'
import
{
useLocation
,
useNavigate
}
from
'react-router-dom'
import
{
clearCurrentConversation
,
setCurrentConversation
}
from
'@/store/conversationSlice'
import
{
useAppDispatch
}
from
'@/store/hook'
...
...
@@ -7,6 +7,7 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
return
(
props
:
any
)
=>
{
const
location
=
useLocation
()
const
dispatch
=
useAppDispatch
()
const
navigate
=
useNavigate
()
useEffect
(()
=>
{
if
(
location
.
pathname
===
'/'
)
{
...
...
@@ -14,6 +15,13 @@ export function withRouteChangeHandler(WrappedComponent: React.ComponentType) {
}
else
if
(
location
.
pathname
.
startsWith
(
'/chat/'
))
{
const
conversationId
=
location
.
pathname
.
split
(
'/'
)[
2
]
if
(
!
JSON
.
parse
(
window
.
localStorage
.
getItem
(
'__TOKEN__'
)
||
''
))
{
// 如果没有有效的 token,重定向到首页
navigate
(
'/'
)
return
// 提前返回,不执行后续的 dispatch
}
dispatch
(
setCurrentConversation
(
conversationId
))
}
// 这里可以添加其他路由相关的逻辑
...
...
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