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
dab9f5f8
Commit
dab9f5f8
authored
Aug 08, 2024
by
HoMeTown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 处理退出登录
parent
0f46e9c8
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
85 additions
and
14 deletions
+85
-14
src/auth/AuthContext.tsx
+2
-0
src/layouts/MainLayout/MainLayout.tsx
+3
-3
src/layouts/Navbar/Navbar.tsx
+9
-11
src/layouts/Navbar/components/User/index.tsx
+71
-0
No files found.
src/auth/AuthContext.tsx
View file @
dab9f5f8
...
@@ -46,6 +46,8 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
...
@@ -46,6 +46,8 @@ export const AuthProvider: React.FC<AuthProviderProps> = ({ children }) => {
const
logout
=
()
=>
{
const
logout
=
()
=>
{
setIsLoggedIn
(
false
)
setIsLoggedIn
(
false
)
setToken
(
''
)
showToast
(
'已退出'
,
'success'
)
}
}
const
toggleLoginModal
=
()
=>
{
const
toggleLoginModal
=
()
=>
{
...
...
src/layouts/MainLayout/MainLayout.tsx
View file @
dab9f5f8
import
type
React
from
'react'
import
type
React
from
'react'
import
{
motion
}
from
'framer-motion'
import
{
motion
}
from
'framer-motion'
import
{
use
Toggle
}
from
'ahooks
'
import
{
use
State
}
from
'react
'
import
{
Navbar
}
from
'../Navbar'
import
{
Navbar
}
from
'../Navbar'
import
{
HistoryBar
}
from
'../HistoryBar/HistoryBar'
import
{
HistoryBar
}
from
'../HistoryBar/HistoryBar'
import
styles
from
'./MainLayout.module.less'
import
styles
from
'./MainLayout.module.less'
...
@@ -24,7 +24,7 @@ const contentVariants = {
...
@@ -24,7 +24,7 @@ const contentVariants = {
export
const
MainLayout
:
React
.
FC
<
MainLayoutProps
>
=
({
children
})
=>
{
export
const
MainLayout
:
React
.
FC
<
MainLayoutProps
>
=
({
children
})
=>
{
const
{
showLoginModal
,
toggleLoginModal
}
=
useAuth
()
const
{
showLoginModal
,
toggleLoginModal
}
=
useAuth
()
const
[
isHistoryVisible
,
{
toggle
}]
=
useToggle
(
)
const
[
isHistoryVisible
,
setHistoryVisible
]
=
useState
(
false
)
return
(
return
(
<
motion
.
main
className=
{
styles
.
layoutMain
}
>
<
motion
.
main
className=
{
styles
.
layoutMain
}
>
<
motion
.
div
<
motion
.
div
...
@@ -32,7 +32,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
...
@@ -32,7 +32,7 @@ export const MainLayout: React.FC<MainLayoutProps> = ({ children }) => {
variants=
{
contentVariants
}
variants=
{
contentVariants
}
className=
{
`h-full pl-[12px] flex items-center ${isHistoryVisible ? 'w-[340px]' : 'w-[90px]'}`
}
className=
{
`h-full pl-[12px] flex items-center ${isHistoryVisible ? 'w-[340px]' : 'w-[90px]'}`
}
>
>
<
Navbar
is
Collapsed=
{
isHistoryVisible
}
onToggle=
{
togg
le
}
/>
<
Navbar
is
HistoryVisible=
{
isHistoryVisible
}
onSetHistoryVisible=
{
setHistoryVisib
le
}
/>
<
HistoryBar
isVisible=
{
isHistoryVisible
}
/>
<
HistoryBar
isVisible=
{
isHistoryVisible
}
/>
</
motion
.
div
>
</
motion
.
div
>
<
motion
.
div
<
motion
.
div
...
...
src/layouts/Navbar/Navbar.tsx
View file @
dab9f5f8
import
type
React
from
'react'
import
type
React
from
'react'
import
{
motion
}
from
'framer-motion'
import
{
motion
}
from
'framer-motion'
import
{
Button
,
Tooltip
}
from
'@nextui-org/react'
import
styles
from
'./Navbar.module.less'
import
styles
from
'./Navbar.module.less'
import
{
NavBarItem
}
from
'./components/NavBarItem'
import
{
NavBarItem
}
from
'./components/NavBarItem'
import
UserIcon
from
'@/assets/svg/user.svg?react
'
import
{
User
}
from
'./components/User
'
import
type
{
WithAuthProps
}
from
'@/auth/withAuth'
import
type
{
WithAuthProps
}
from
'@/auth/withAuth'
import
{
withAuth
}
from
'@/auth/withAuth'
import
{
withAuth
}
from
'@/auth/withAuth'
import
{
NAV_BAR_ITEMS
}
from
'@/config/nav'
import
{
NAV_BAR_ITEMS
}
from
'@/config/nav'
interface
NavbarProps
{
interface
NavbarProps
{
is
Collapsed
:
boolean
is
HistoryVisible
:
boolean
on
Toggle
:
(
)
=>
void
on
SetHistoryVisible
:
(
visible
:
boolean
)
=>
void
}
}
const
NavbarBase
:
React
.
FC
<
NavbarProps
&
WithAuthProps
>
=
({
showLoginTip
,
checkAuth
,
onTogg
le
})
=>
{
const
NavbarBase
:
React
.
FC
<
NavbarProps
&
WithAuthProps
>
=
({
isHistoryVisible
,
checkAuth
,
onSetHistoryVisib
le
})
=>
{
const
handleClick
=
(
type
:
string
|
undefined
)
=>
{
const
handleClick
=
(
type
:
string
|
undefined
)
=>
{
if
(
!
checkAuth
())
if
(
!
checkAuth
())
return
return
if
(
type
===
'history'
)
{
if
(
type
===
'history'
)
{
on
Toggle
(
)
on
SetHistoryVisible
(
!
isHistoryVisible
)
}
}
}
}
const
handleLogout
=
()
=>
{
onSetHistoryVisible
(
false
)
}
return
(
return
(
<
motion
.
nav
className=
"h-full flex-shrink-0 flex flex-col items-center justify-center"
>
<
motion
.
nav
className=
"h-full flex-shrink-0 flex flex-col items-center justify-center"
>
...
@@ -31,11 +33,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ showLoginTip, check
...
@@ -31,11 +33,7 @@ const NavbarBase: React.FC<NavbarProps & WithAuthProps> = ({ showLoginTip, check
<
NavBarItem
onClick=
{
handleClick
}
icon=
{
item
.
icon
}
label=
{
item
.
label
}
key=
{
item
.
key
}
type=
{
item
.
key
}
/>
<
NavBarItem
onClick=
{
handleClick
}
icon=
{
item
.
icon
}
label=
{
item
.
label
}
key=
{
item
.
key
}
type=
{
item
.
key
}
/>
)
)
})
}
})
}
<
Tooltip
isOpen=
{
showLoginTip
}
color=
"foreground"
content=
"登录体验更多功能"
placement=
"right"
>
<
User
onLogout=
{
handleLogout
}
/>
<
Button
onClick=
{
checkAuth
}
variant=
"light"
isIconOnly
aria
-
label=
"Like"
>
<
UserIcon
/>
</
Button
>
</
Tooltip
>
</
motion
.
div
>
</
motion
.
div
>
</
motion
.
nav
>
</
motion
.
nav
>
)
)
...
...
src/layouts/Navbar/components/User/index.tsx
0 → 100644
View file @
dab9f5f8
import
{
Button
,
Dropdown
,
DropdownItem
,
DropdownMenu
,
DropdownTrigger
,
Tooltip
}
from
'@nextui-org/react'
import
{
withAuth
}
from
'@/auth/withAuth'
import
type
{
WithAuthProps
}
from
'@/auth/withAuth'
import
UserIcon
from
'@/assets/svg/user.svg?react'
import
{
useAuth
}
from
'@/auth/AuthContext'
interface
UserProps
{
onLogout
:
()
=>
void
}
export
const
UserLogin
:
React
.
FC
<
UserProps
>
=
({
onLogout
})
=>
{
const
{
logout
}
=
useAuth
()
const
items
=
[
{
key
:
'conact'
,
label
:
'联系我们'
,
},
{
key
:
'file'
,
label
:
'相关协议'
,
},
{
key
:
'logout'
,
label
:
'退出登录'
,
},
]
const
handleClick
=
(
key
:
string
)
=>
{
if
(
key
===
'logout'
)
{
logout
()
onLogout
()
}
}
return
(
<
Dropdown
>
<
DropdownTrigger
>
<
Button
variant=
"light"
isIconOnly
aria
-
label=
"Like"
>
<
UserIcon
/>
</
Button
>
</
DropdownTrigger
>
<
DropdownMenu
variant=
"flat"
aria
-
label=
"Dynamic Actions"
items=
{
items
}
>
{
item
=>
(
<
DropdownItem
onClick=
{
()
=>
handleClick
(
item
.
key
)
}
key=
{
item
.
key
}
color=
{
item
.
key
===
'logout'
?
'danger'
:
'primary'
}
className=
{
item
.
key
===
'logout'
?
'text-danger'
:
''
}
>
{
item
.
label
}
</
DropdownItem
>
)
}
</
DropdownMenu
>
</
Dropdown
>
)
}
const
UserNotLoginBase
:
React
.
FC
<
WithAuthProps
>
=
({
showLoginTip
,
checkAuth
})
=>
{
return
(
<
Tooltip
isOpen=
{
showLoginTip
}
color=
"foreground"
content=
"登录体验更多功能"
placement=
"right"
>
<
Button
onClick=
{
checkAuth
}
variant=
"light"
isIconOnly
aria
-
label=
"Like"
>
<
UserIcon
/>
</
Button
>
</
Tooltip
>
)
}
export
const
UserNotLogin
=
withAuth
(
UserNotLoginBase
)
export
const
User
:
React
.
FC
<
UserProps
>
=
({
onLogout
})
=>
{
const
{
isLoggedIn
}
=
useAuth
()
return
isLoggedIn
?
<
UserLogin
onLogout=
{
onLogout
}
/>
:
<
UserNotLogin
/>
}
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