feat: 添加退出登录按钮(桌面Header + 移动端"我"页面)
- Header: 桌面端右上角退出图标,带确认弹窗 - Me页面: 底部退出登录按钮,带确认弹窗 Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -1,20 +1,33 @@
|
||||
/** 顶部 Header(h-14 sticky)
|
||||
* 桌面:显示当前页面标题 + 用户信息
|
||||
* 桌面:显示当前页面标题 + 用户信息 + 退出按钮
|
||||
* 移动:显示 Logo + 通知铃铛
|
||||
*/
|
||||
import { useLocation } from 'react-router-dom'
|
||||
import { Bell } from 'lucide-react'
|
||||
import { useState } from 'react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { Bell, LogOut } from 'lucide-react'
|
||||
import { HEADER_TITLES } from '@/lib/nav-config'
|
||||
import { getName } from '@/lib/auth'
|
||||
import { getName, clearAuth } from '@/lib/auth'
|
||||
import {
|
||||
Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, DialogFooter,
|
||||
} from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
|
||||
export function Header() {
|
||||
const { pathname } = useLocation()
|
||||
const navigate = useNavigate()
|
||||
const name = getName()
|
||||
const [confirmLogout, setConfirmLogout] = useState(false)
|
||||
|
||||
// 匹配标题(支持子路由,取最长匹配)
|
||||
const title = Object.entries(HEADER_TITLES)
|
||||
.filter(([p]) => pathname === p || (p !== '/' && pathname.startsWith(p)))
|
||||
.sort((a, b) => b[0].length - a[0].length)[0]?.[1] || '左右 BossAi'
|
||||
|
||||
const handleLogout = () => {
|
||||
clearAuth()
|
||||
navigate('/login')
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-20 flex h-14 items-center gap-3 border-b border-border bg-white/95 px-4 backdrop-blur md:px-6">
|
||||
{/* 移动端 Logo */}
|
||||
@@ -36,6 +49,28 @@ export function Header() {
|
||||
{name && (
|
||||
<span className="hidden text-sm text-muted-foreground md:inline">{name}</span>
|
||||
)}
|
||||
{/* 退出按钮(桌面) */}
|
||||
<button
|
||||
onClick={() => setConfirmLogout(true)}
|
||||
className="hidden h-9 w-9 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-red-50 hover:text-red-600 md:flex"
|
||||
aria-label="退出登录"
|
||||
>
|
||||
<LogOut className="h-5 w-5" />
|
||||
</button>
|
||||
|
||||
{/* 退出确认弹窗 */}
|
||||
<Dialog open={confirmLogout} onOpenChange={setConfirmLogout}>
|
||||
<DialogContent className="max-w-sm">
|
||||
<DialogHeader>
|
||||
<DialogTitle>退出登录</DialogTitle>
|
||||
<DialogDescription>确定要退出当前账号吗?</DialogDescription>
|
||||
</DialogHeader>
|
||||
<DialogFooter>
|
||||
<Button variant="outline" onClick={() => setConfirmLogout(false)}>取消</Button>
|
||||
<Button variant="destructive" onClick={handleLogout}>退出</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</header>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user