Spaces:
Sleeping
Sleeping
import React from 'react'; | |
import { useNavigate, useLocation } from 'react-router-dom'; | |
import { useAuth } from '../../contexts/AuthContext'; | |
const Sidebar: React.FC = () => { | |
const navigate = useNavigate(); | |
const location = useLocation(); | |
const { user, logout } = useAuth(); | |
const navItems = [ | |
{ | |
name: '首页', | |
path: '/', | |
icon: ( | |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6" /> | |
</svg> | |
) | |
}, | |
{ | |
name: '分类', | |
path: '/categories', | |
icon: ( | |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 11H5m14 0a2 2 0 012 2v6a2 2 0 01-2 2H5a2 2 0 01-2-2v-6a2 2 0 012-2m14 0V9a2 2 0 00-2-2M5 11V9a2 2 0 012-2m0 0V5a2 2 0 012-2h6a2 2 0 012 2v2M7 7h10" /> | |
</svg> | |
) | |
}, | |
{ | |
name: '新建', | |
path: '/create', | |
icon: ( | |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M12 4v16m8-8H4" /> | |
</svg> | |
) | |
}, | |
{ | |
name: '设置', | |
path: '/settings', | |
icon: ( | |
<svg xmlns="http://www.w3.org/2000/svg" className="h-6 w-6" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z" /> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M15 12a3 3 0 11-6 0 3 3 0 016 0z" /> | |
</svg> | |
) | |
} | |
]; | |
const isActive = (path: string) => { | |
return location.pathname === path; | |
}; | |
return ( | |
<div className="h-full flex flex-col"> | |
<div className="p-4 border-b border-gray-200"> | |
<h1 className="text-xl font-bold text-gray-800">提示词管理</h1> | |
</div> | |
<div className="flex-1 overflow-y-auto p-4"> | |
<nav className="space-y-2"> | |
{navItems.map((item) => ( | |
<button | |
key={item.path} | |
onClick={() => navigate(item.path)} | |
className={`w-full flex items-center space-x-3 p-3 rounded-lg transition-colors | |
${isActive(item.path) | |
? 'bg-blue-50 text-blue-600' | |
: 'text-gray-600 hover:bg-gray-100' | |
}`} | |
> | |
<span>{item.icon}</span> | |
<span>{item.name}</span> | |
</button> | |
))} | |
</nav> | |
</div> | |
{user && ( | |
<div className="p-4 border-t border-gray-200"> | |
<div className="flex items-center"> | |
<div className="flex-1"> | |
<p className="text-sm font-medium">{user}</p> | |
<p className="text-xs text-gray-500">已登录</p> | |
</div> | |
<button | |
onClick={logout} | |
className="text-gray-600 hover:text-red-600 p-2" | |
title="登出" | |
> | |
<svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor"> | |
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1" /> | |
</svg> | |
</button> | |
</div> | |
</div> | |
)} | |
</div> | |
); | |
}; | |
export default Sidebar; |