a
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
// 新粗野主义按钮组件
|
||||
export function Button({
|
||||
children,
|
||||
variant = 'primary',
|
||||
size = 'md',
|
||||
className = '',
|
||||
onClick,
|
||||
type = 'button',
|
||||
disabled = false
|
||||
}) {
|
||||
const baseClasses = 'inline-flex items-center justify-center font-bold transition-all duration-150 border-2 border-black'
|
||||
|
||||
const variants = {
|
||||
primary: 'bg-brutal-pink text-black shadow-brutal hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]',
|
||||
secondary: 'bg-brutal-cyan text-black shadow-brutal hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]',
|
||||
success: 'bg-brutal-green text-black shadow-brutal hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]',
|
||||
warning: 'bg-brutal-yellow text-black shadow-brutal hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]',
|
||||
danger: 'bg-red-500 text-white shadow-brutal hover:shadow-none hover:translate-x-[2px] hover:translate-y-[2px]',
|
||||
outline: 'bg-white text-black shadow-brutal-sm hover:shadow-none hover:translate-x-[1px] hover:translate-y-[1px]'
|
||||
}
|
||||
|
||||
const sizes = {
|
||||
sm: 'px-3 py-1.5 text-xs',
|
||||
md: 'px-4 py-2 text-sm',
|
||||
lg: 'px-6 py-3 text-base'
|
||||
}
|
||||
|
||||
const disabledClasses = disabled ? 'opacity-50 cursor-not-allowed' : ''
|
||||
|
||||
return (
|
||||
<button
|
||||
type={type}
|
||||
onClick={onClick}
|
||||
disabled={disabled}
|
||||
className={`${baseClasses} ${variants[variant]} ${sizes[size]} ${disabledClasses} ${className}`}
|
||||
>
|
||||
{children}
|
||||
</button>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// 新粗野主义卡片组件
|
||||
export function Card({
|
||||
children,
|
||||
className = '',
|
||||
padding = 'normal',
|
||||
shadow = 'normal'
|
||||
}) {
|
||||
const paddings = {
|
||||
none: '',
|
||||
small: 'p-3',
|
||||
normal: 'p-4',
|
||||
large: 'p-6'
|
||||
}
|
||||
|
||||
const shadows = {
|
||||
none: '',
|
||||
small: 'shadow-brutal-sm',
|
||||
normal: 'shadow-brutal',
|
||||
large: 'shadow-brutal-lg'
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`bg-white border-2 border-black ${shadows[shadow]} ${paddings[padding]} ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 卡片头部
|
||||
export function CardHeader({ children, className = '' }) {
|
||||
return (
|
||||
<div className={`border-b-2 border-black pb-3 mb-4 ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 卡片标题
|
||||
export function CardTitle({ children, className = '' }) {
|
||||
return (
|
||||
<h3 className={`text-lg font-bold ${className}`}>
|
||||
{children}
|
||||
</h3>
|
||||
)
|
||||
}
|
||||
|
||||
// 卡片内容
|
||||
export function CardContent({ children, className = '' }) {
|
||||
return (
|
||||
<div className={className}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
// 新粗野主义输入框组件
|
||||
export function Input({
|
||||
id,
|
||||
type = 'text',
|
||||
placeholder = '',
|
||||
value,
|
||||
onChange,
|
||||
className = '',
|
||||
disabled = false,
|
||||
required = false,
|
||||
name = ''
|
||||
}) {
|
||||
return (
|
||||
<input
|
||||
id={id}
|
||||
type={type}
|
||||
name={name}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
disabled={disabled}
|
||||
required={required}
|
||||
className={`
|
||||
w-full px-3 py-2
|
||||
border-2 border-black
|
||||
bg-white
|
||||
focus:outline-none focus:ring-2 focus:ring-brutal-yellow
|
||||
placeholder:text-black/40
|
||||
disabled:bg-gray-100 disabled:cursor-not-allowed
|
||||
${className}
|
||||
`}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// 文本域
|
||||
export function TextArea({
|
||||
id,
|
||||
placeholder = '',
|
||||
value,
|
||||
onChange,
|
||||
rows = 4,
|
||||
className = '',
|
||||
disabled = false,
|
||||
required = false,
|
||||
name = ''
|
||||
}) {
|
||||
return (
|
||||
<textarea
|
||||
id={id}
|
||||
name={name}
|
||||
placeholder={placeholder}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
rows={rows}
|
||||
disabled={disabled}
|
||||
required={required}
|
||||
className={`
|
||||
w-full px-3 py-2
|
||||
border-2 border-black
|
||||
bg-white
|
||||
focus:outline-none focus:ring-2 focus:ring-brutal-yellow
|
||||
placeholder:text-black/40
|
||||
disabled:bg-gray-100 disabled:cursor-not-allowed
|
||||
resize-vertical
|
||||
${className}
|
||||
`}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
// 标签
|
||||
export function Label({ children, htmlFor = '', className = '', required = false }) {
|
||||
return (
|
||||
<label
|
||||
htmlFor={htmlFor}
|
||||
className={`block text-sm font-bold mb-1 ${className}`}
|
||||
>
|
||||
{children}
|
||||
{required && <span className="text-brutal-pink ml-1">*</span>}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
// 表单组
|
||||
export function FormGroup({ children, className = '' }) {
|
||||
return (
|
||||
<div className={`mb-4 ${className}`}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
import { Sidebar } from './Sidebar'
|
||||
|
||||
// 页面布局组件
|
||||
export function Layout({ children, title, actions }) {
|
||||
return (
|
||||
<div className="flex min-h-screen bg-brutal-cream">
|
||||
<Sidebar />
|
||||
|
||||
<main className="flex-1 flex flex-col">
|
||||
{/* 顶部标题栏 */}
|
||||
<header className="bg-white border-b-2 border-black px-6 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<h1 className="text-2xl font-bold">{title}</h1>
|
||||
{actions && (
|
||||
<div className="flex items-center gap-3">
|
||||
{actions}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</header>
|
||||
|
||||
{/* 内容区域 */}
|
||||
<div className="flex-1 p-6 overflow-auto">
|
||||
{children}
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// 简单布局(无侧边栏,用于登录页)
|
||||
export function SimpleLayout({ children }) {
|
||||
return (
|
||||
<div className="min-h-screen bg-brutal-cream flex items-center justify-center p-4">
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { NavLink, useNavigate } from 'react-router-dom'
|
||||
import { authApi } from '../api/auth'
|
||||
|
||||
// 导航项
|
||||
function NavItem({ to, icon, label }) {
|
||||
return (
|
||||
<NavLink
|
||||
to={to}
|
||||
className={({ isActive }) =>
|
||||
`flex items-center gap-3 px-4 py-3 font-bold transition-all duration-150 ${
|
||||
isActive
|
||||
? 'bg-black text-brutal-yellow border-l-4 border-brutal-yellow'
|
||||
: 'text-black hover:bg-black/10 border-l-4 border-transparent'
|
||||
}`
|
||||
}
|
||||
>
|
||||
<span className="text-lg">{icon}</span>
|
||||
<span>{label}</span>
|
||||
</NavLink>
|
||||
)
|
||||
}
|
||||
|
||||
// 侧边栏组件
|
||||
export function Sidebar() {
|
||||
const navigate = useNavigate()
|
||||
|
||||
const handleLogout = async () => {
|
||||
// 1) 先调用后端清除 SSO Cookie,避免自动登录
|
||||
try {
|
||||
await authApi.logout()
|
||||
} catch {
|
||||
// 即使后端失败也继续本地清理
|
||||
}
|
||||
// 2) 再清除本地 token
|
||||
localStorage.removeItem('token')
|
||||
// 3) 跳转登录页
|
||||
navigate('/login')
|
||||
}
|
||||
|
||||
return (
|
||||
<aside className="w-64 bg-brutal-yellow border-r-2 border-black flex flex-col min-h-screen">
|
||||
{/* Logo */}
|
||||
<div className="p-4 border-b-2 border-black">
|
||||
<NavLink to="/" className="inline-block -rotate-2 border-2 border-black bg-black px-4 py-2 shadow-brutal hover:rotate-0 transition-transform">
|
||||
<span className="font-bold text-xl text-brutal-yellow">BLOG</span>
|
||||
</NavLink>
|
||||
</div>
|
||||
|
||||
{/* 导航菜单 */}
|
||||
<nav className="flex-1 py-4 space-y-1">
|
||||
<NavItem to="/admin" icon="🏠" label="控制台" />
|
||||
<NavItem to="/admin/posts" icon="📝" label="文章管理" />
|
||||
<NavItem to="/admin/categories" icon="📁" label="分类管理" />
|
||||
<NavItem to="/admin/images" icon="🖼️" label="图片管理" />
|
||||
<NavItem to="/admin/nanobot" icon="🤖" label="Nanobot 助手" />
|
||||
<NavItem to="/admin/settings" icon="⚙️" label="博客设置" />
|
||||
</nav>
|
||||
|
||||
{/* 退出登录 */}
|
||||
<div className="p-4 border-t-2 border-black">
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="w-full flex items-center gap-3 px-4 py-3 font-bold text-black hover:bg-red-100 border-l-4 border-transparent hover:border-red-500 transition-all"
|
||||
>
|
||||
<span className="text-lg">🚪</span>
|
||||
<span>退出登录</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* 底部信息 */}
|
||||
<div className="p-4 border-t-2 border-black">
|
||||
<div className="flex items-center justify-between">
|
||||
<p className="text-xs font-bold text-black/60">
|
||||
Personal Blog v1.0
|
||||
</p>
|
||||
<a
|
||||
href="/"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-xs font-bold text-black hover:underline"
|
||||
>
|
||||
查看首页 →
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user