feat: add settings page and theme toggle component
- Implemented a new SettingsPage component for user preferences including appearance, behavior, and account security settings. - Added a ThemeToggle component to switch between light, dark, and system modes. - Created reusable UI components: AlertDialog, Avatar, Badge, Button, Card, Dialog, Input, Label, Progress, ScrollArea, Separator, Sheet, Skeleton, Tooltip. - Introduced utility functions for class name merging and formatting bytes/uptime. - Added a custom hook for media query handling
This commit is contained in:
65 files changed
+4687
-4530
No files matched your search
@@ -1,251 +0,0 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { Activity, LayoutDashboard, Settings, Sparkles, Terminal } from 'lucide-react';
|
||||
import { Sidebar } from './Sidebar';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
type Page = '总览' | '配置' | '日志';
|
||||
|
||||
interface MainLayoutProps {
|
||||
activePage: Page;
|
||||
onNavigate: (page: Page) => void;
|
||||
status: string;
|
||||
onLogout: () => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
const pageMeta: Record<Page, { title: string; subtitle: string; badge: string; icon: typeof LayoutDashboard }> = {
|
||||
'总览': { title: '总览', subtitle: '查看当前接入的 QQ 账号及服务运行状态', badge: '控制台视图', icon: LayoutDashboard },
|
||||
'配置': { title: '节点配置', subtitle: '管理 OneBot 协议端点与通信参数', badge: '协议编排', icon: Settings },
|
||||
'日志': { title: '日志', subtitle: '查看后端运行日志与实时事件流', badge: 'SSE 实时流', icon: Terminal },
|
||||
};
|
||||
|
||||
export function MainLayout({ activePage, onNavigate, status, onLogout, children }: MainLayoutProps) {
|
||||
const meta = pageMeta[activePage];
|
||||
const { resolved } = useTheme();
|
||||
const dark = resolved === 'dark';
|
||||
const PageIcon = meta.icon;
|
||||
const runtimeLabel = status === '已连接' ? '运行中' : status;
|
||||
|
||||
return (
|
||||
<div className="h-screen w-screen flex overflow-hidden font-(--font-sans)" style={{ background: 'var(--bg-body)' }}>
|
||||
{/* Full-screen ambient gradient — matches login page */}
|
||||
<div
|
||||
className="pointer-events-none fixed inset-0"
|
||||
style={{
|
||||
background: dark
|
||||
? 'linear-gradient(135deg, rgba(8,11,18,1) 0%, rgba(10,16,27,1) 42%, rgba(7,10,17,1) 100%)'
|
||||
: 'linear-gradient(135deg, #f8fbff 0%, #eef6ff 45%, #f9fafc 100%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Animated orbs */}
|
||||
<div className="pointer-events-none fixed inset-0 overflow-hidden">
|
||||
<motion.div
|
||||
className="absolute -left-24 -top-24 h-[60vh] w-[60vh] rounded-full"
|
||||
style={{
|
||||
background: dark
|
||||
? 'radial-gradient(circle, rgba(56,189,248,0.12) 0%, transparent 68%)'
|
||||
: 'radial-gradient(circle, rgba(56,189,248,0.18) 0%, transparent 70%)',
|
||||
filter: 'blur(42px)',
|
||||
}}
|
||||
animate={{ scale: [1, 1.08, 1] }}
|
||||
transition={{ duration: 10, ease: 'easeInOut', repeat: Infinity }}
|
||||
/>
|
||||
<motion.div
|
||||
className="absolute -right-16 -bottom-32 h-[50vh] w-[50vh] rounded-full"
|
||||
style={{
|
||||
background: dark
|
||||
? 'radial-gradient(circle, rgba(129,140,248,0.10) 0%, transparent 68%)'
|
||||
: 'radial-gradient(circle, rgba(129,140,248,0.14) 0%, transparent 70%)',
|
||||
filter: 'blur(52px)',
|
||||
}}
|
||||
animate={{ scale: [1, 1.12, 1] }}
|
||||
transition={{ duration: 12, ease: 'easeInOut', repeat: Infinity, delay: 0.8 }}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Sidebar */}
|
||||
<Sidebar activePage={activePage} onNavigate={onNavigate} status={status} onLogout={onLogout} />
|
||||
|
||||
{/* Main content */}
|
||||
<div className="flex-1 flex flex-col min-h-0 p-3 pl-0 z-10 relative">
|
||||
<main
|
||||
className="flex-1 overflow-y-auto rounded-2xl relative"
|
||||
style={{
|
||||
background: dark
|
||||
? 'linear-gradient(135deg, rgba(8,13,22,0.72), rgba(14,20,32,0.82))'
|
||||
: 'linear-gradient(135deg, rgba(255,255,255,0.68), rgba(255,255,255,0.85))',
|
||||
border: '1px solid var(--glass-border)',
|
||||
backdropFilter: 'blur(38px) saturate(1.35)',
|
||||
WebkitBackdropFilter: 'blur(38px) saturate(1.35)',
|
||||
boxShadow: dark
|
||||
? '0 24px 80px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05)'
|
||||
: '0 20px 60px rgba(15,23,42,0.08), inset 0 1px 0 rgba(255,255,255,0.7)',
|
||||
}}
|
||||
>
|
||||
{/* Top highlight */}
|
||||
<div className="absolute inset-x-0 top-0 h-px bg-linear-to-r from-transparent via-white/8 to-transparent rounded-t-2xl" />
|
||||
|
||||
{/* Grid texture overlay */}
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0 rounded-2xl"
|
||||
style={{
|
||||
backgroundImage: dark
|
||||
? 'linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px), linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px)'
|
||||
: 'linear-gradient(90deg, rgba(15,23,42,0.03) 1px, transparent 1px), linear-gradient(rgba(15,23,42,0.03) 1px, transparent 1px)',
|
||||
backgroundSize: '36px 36px',
|
||||
maskImage: 'linear-gradient(180deg, rgba(0,0,0,0.35), transparent 60%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Accent glow in corner */}
|
||||
<motion.div
|
||||
className="pointer-events-none absolute right-[12%] top-[8%] h-32 w-32 rounded-full"
|
||||
style={{
|
||||
background: 'radial-gradient(circle, rgba(56,189,248,0.18), transparent 68%)',
|
||||
filter: 'blur(20px)',
|
||||
}}
|
||||
animate={{ scale: [1, 1.15, 1], opacity: [0.6, 1, 0.6] }}
|
||||
transition={{ duration: 6, ease: 'easeInOut', repeat: Infinity }}
|
||||
/>
|
||||
|
||||
<div className="relative w-full min-h-full px-4 py-4 sm:px-6 sm:py-6 xl:px-8 2xl:px-10 flex flex-col">
|
||||
{/* Page header */}
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.header
|
||||
key={meta.title + '_header'}
|
||||
initial={{ opacity: 0, y: -10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: 8 }}
|
||||
transition={{ duration: 0.25 }}
|
||||
className="mb-6"
|
||||
>
|
||||
<div
|
||||
className="relative overflow-hidden rounded-[1.75rem] border px-4 py-4 sm:px-5 sm:py-5 xl:px-6"
|
||||
style={{
|
||||
background: dark
|
||||
? 'linear-gradient(135deg, rgba(8,12,20,0.48), rgba(14,20,32,0.62))'
|
||||
: 'linear-gradient(135deg, rgba(255,255,255,0.5), rgba(255,255,255,0.72))',
|
||||
borderColor: 'var(--glass-border)',
|
||||
boxShadow: dark
|
||||
? '0 18px 48px rgba(0,0,0,0.26), inset 0 1px 0 rgba(255,255,255,0.04)'
|
||||
: '0 14px 40px rgba(15,23,42,0.05), inset 0 1px 0 rgba(255,255,255,0.5)',
|
||||
}}
|
||||
>
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
style={{
|
||||
backgroundImage: dark
|
||||
? 'linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px), linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px)'
|
||||
: 'linear-gradient(90deg, rgba(15,23,42,0.03) 1px, transparent 1px), linear-gradient(rgba(15,23,42,0.03) 1px, transparent 1px)',
|
||||
backgroundSize: '34px 34px',
|
||||
maskImage: 'linear-gradient(90deg, rgba(0,0,0,0.45), transparent 85%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
<motion.div
|
||||
className="pointer-events-none absolute -right-8 -top-10 h-28 w-28 rounded-full"
|
||||
style={{
|
||||
background: 'radial-gradient(circle, rgba(56,189,248,0.16), transparent 68%)',
|
||||
filter: 'blur(18px)',
|
||||
}}
|
||||
animate={{ scale: [1, 1.12, 1], opacity: [0.45, 0.78, 0.45] }}
|
||||
transition={{ duration: 6, ease: 'easeInOut', repeat: Infinity }}
|
||||
/>
|
||||
|
||||
<div className="relative flex items-center justify-between gap-6">
|
||||
<div className="flex min-w-0 items-center gap-4">
|
||||
{/* Icon */}
|
||||
<div
|
||||
className="relative flex h-11 w-11 shrink-0 items-center justify-center rounded-2xl border"
|
||||
style={{
|
||||
borderColor: 'color-mix(in srgb, var(--accent) 26%, transparent)',
|
||||
background: dark
|
||||
? 'linear-gradient(135deg, rgba(56,189,248,0.16), rgba(129,140,248,0.14))'
|
||||
: 'linear-gradient(135deg, rgba(56,189,248,0.16), rgba(129,140,248,0.12))',
|
||||
boxShadow: '0 8px 22px color-mix(in srgb, var(--accent) 16%, transparent)',
|
||||
}}
|
||||
>
|
||||
<PageIcon size={20} strokeWidth={2.2} style={{ color: 'var(--accent)' }} />
|
||||
</div>
|
||||
|
||||
{/* Title block */}
|
||||
<div className="min-w-0">
|
||||
<div className="flex items-center gap-2.5 flex-wrap">
|
||||
<h1 className="text-xl font-bold tracking-[-0.03em]" style={{ color: 'var(--text-primary)' }}>
|
||||
{meta.title}
|
||||
</h1>
|
||||
<span
|
||||
className="inline-flex items-center rounded-full px-2 py-0.5 text-[11px] font-medium"
|
||||
style={{
|
||||
color: 'var(--accent)',
|
||||
background: 'var(--accent-subtle)',
|
||||
border: '1px solid color-mix(in srgb, var(--accent) 22%, transparent)',
|
||||
}}
|
||||
>
|
||||
<Sparkles size={10} className="mr-1" />
|
||||
{meta.badge}
|
||||
</span>
|
||||
</div>
|
||||
<p className="mt-0.5 text-sm" style={{ color: 'var(--text-secondary)' }}>
|
||||
{meta.subtitle}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<motion.div
|
||||
whileHover={{ y: -1.5 }}
|
||||
className="hidden sm:flex shrink-0 overflow-hidden rounded-2xl border px-4 py-3 items-center gap-3"
|
||||
style={{
|
||||
borderColor: dark ? 'rgba(255,255,255,0.05)' : 'rgba(255,255,255,0.82)',
|
||||
background: dark ? 'rgba(255,255,255,0.03)' : 'rgba(255,255,255,0.52)',
|
||||
backdropFilter: 'blur(18px)',
|
||||
WebkitBackdropFilter: 'blur(18px)',
|
||||
}}
|
||||
>
|
||||
<Activity size={14} style={{ color: 'var(--accent)', flexShrink: 0 }} />
|
||||
<div>
|
||||
<div className="text-[11px] font-semibold uppercase tracking-widest mb-0.5" style={{ color: 'var(--text-tertiary)' }}>运行状态</div>
|
||||
<div className="text-sm font-semibold" style={{ color: 'var(--accent)' }}>{runtimeLabel}</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
</div>
|
||||
</div>
|
||||
</motion.header>
|
||||
</AnimatePresence>
|
||||
|
||||
{/* Page content */}
|
||||
<div className="flex-1 flex flex-col">
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={activePage}
|
||||
initial={{ opacity: 0, y: 12 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -12 }}
|
||||
transition={{ duration: 0.25, ease: [0.16, 1, 0.3, 1] }}
|
||||
className="flex-1"
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
|
||||
<motion.footer
|
||||
initial={{ opacity: 0, y: 8 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.3, delay: 0.08 }}
|
||||
className="mt-8 flex items-center justify-center border-t pt-5 text-[11px] tracking-wide"
|
||||
style={{
|
||||
color: 'var(--text-tertiary)',
|
||||
borderColor: 'var(--border-subtle)',
|
||||
}}
|
||||
>
|
||||
© {new Date().getFullYear()} SnowLuma. All rights reserved.
|
||||
</motion.footer>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,193 +1,91 @@
|
||||
import { LayoutDashboard, Settings, LogOut, Sun, Moon, Monitor, Terminal } from 'lucide-react';
|
||||
import { Avatar } from '@heroui/react';
|
||||
import { StatusBadge } from '../ui/StatusBadge';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useTheme, type ThemeMode } from '../../contexts/ThemeContext';
|
||||
import { LayoutDashboard, Settings, SlidersHorizontal, Terminal } from 'lucide-react';
|
||||
import { motion } from 'motion/react';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { APP_NAME, APP_VERSION } from '@/types';
|
||||
|
||||
type Page = '总览' | '配置' | '日志';
|
||||
export type Page = 'overview' | 'config' | 'logs' | 'settings';
|
||||
|
||||
export const NAV_ITEMS: { page: Page; label: string; icon: typeof LayoutDashboard; description: string }[] = [
|
||||
{ page: 'overview', label: '总览', icon: LayoutDashboard, description: '主机与服务状态' },
|
||||
{ page: 'config', label: '节点配置', icon: Settings, description: 'OneBot 协议端点' },
|
||||
{ page: 'logs', label: '日志', icon: Terminal, description: '实时事件流' },
|
||||
{ page: 'settings', label: '系统设置', icon: SlidersHorizontal, description: '主题与账号' },
|
||||
];
|
||||
|
||||
interface SidebarProps {
|
||||
activePage: Page;
|
||||
active: Page;
|
||||
onNavigate: (page: Page) => void;
|
||||
status: string;
|
||||
onLogout: () => void;
|
||||
collapsed?: boolean;
|
||||
onItemClick?: () => void;
|
||||
}
|
||||
|
||||
const navItems: { page: Page; label: string; icon: typeof LayoutDashboard }[] = [
|
||||
{ page: '总览', label: '总览', icon: LayoutDashboard },
|
||||
{ page: '配置', label: '配置', icon: Settings },
|
||||
{ page: '日志', label: '日志', icon: Terminal },
|
||||
];
|
||||
|
||||
const THEME_OPTIONS: { mode: ThemeMode; icon: typeof Sun; label: string }[] = [
|
||||
{ mode: 'system', icon: Monitor, label: '跟随系统' },
|
||||
{ mode: 'light', icon: Sun, label: '浅色' },
|
||||
{ mode: 'dark', icon: Moon, label: '深色' },
|
||||
];
|
||||
|
||||
export function Sidebar({ activePage, onNavigate, status, onLogout }: SidebarProps) {
|
||||
const { resolved, mode, setMode } = useTheme();
|
||||
const dark = resolved === 'dark';
|
||||
|
||||
export function Sidebar({ active, onNavigate, collapsed = false, onItemClick }: SidebarProps) {
|
||||
return (
|
||||
<aside
|
||||
className="w-55 shrink-0 flex flex-col z-40 m-3 rounded-2xl overflow-hidden relative"
|
||||
style={{
|
||||
background: dark
|
||||
? 'linear-gradient(135deg, rgba(8,13,22,0.78), rgba(14,20,32,0.88))'
|
||||
: 'linear-gradient(135deg, rgba(255,255,255,0.72), rgba(255,255,255,0.9))',
|
||||
border: '1px solid var(--glass-border)',
|
||||
backdropFilter: 'blur(38px) saturate(1.35)',
|
||||
WebkitBackdropFilter: 'blur(38px) saturate(1.35)',
|
||||
boxShadow: dark
|
||||
? '0 24px 80px rgba(0,0,0,0.45), inset 0 1px 0 rgba(255,255,255,0.05)'
|
||||
: '0 20px 60px rgba(15,23,42,0.08), inset 0 1px 0 rgba(255,255,255,0.7)',
|
||||
}}
|
||||
>
|
||||
{/* Top highlight */}
|
||||
<div className="absolute inset-x-0 top-0 h-px bg-linear-to-r from-transparent via-white/8 to-transparent" />
|
||||
|
||||
{/* Grid texture overlay */}
|
||||
<div
|
||||
className="pointer-events-none absolute inset-0"
|
||||
style={{
|
||||
backgroundImage: dark
|
||||
? 'linear-gradient(90deg, rgba(255,255,255,0.02) 1px, transparent 1px), linear-gradient(rgba(255,255,255,0.02) 1px, transparent 1px)'
|
||||
: 'linear-gradient(90deg, rgba(15,23,42,0.03) 1px, transparent 1px), linear-gradient(rgba(15,23,42,0.03) 1px, transparent 1px)',
|
||||
backgroundSize: '36px 36px',
|
||||
maskImage: 'linear-gradient(180deg, rgba(0,0,0,0.3), transparent 70%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Accent glow at top-left */}
|
||||
<motion.div
|
||||
className="pointer-events-none absolute -left-6 -top-6 h-24 w-24 rounded-full"
|
||||
style={{
|
||||
background: 'radial-gradient(circle, rgba(56,189,248,0.2), transparent 68%)',
|
||||
filter: 'blur(14px)',
|
||||
}}
|
||||
animate={{ scale: [1, 1.15, 1], opacity: [0.5, 0.8, 0.5] }}
|
||||
transition={{ duration: 7, ease: 'easeInOut', repeat: Infinity }}
|
||||
/>
|
||||
|
||||
{/* Logo */}
|
||||
<div className="relative h-16 px-5 flex items-center gap-2" style={{ borderBottom: '1px solid var(--border-subtle)' }}>
|
||||
<div className="relative shrink-0">
|
||||
<div
|
||||
className="absolute -inset-1.5 rounded-full blur-lg"
|
||||
style={{ background: 'linear-gradient(135deg, rgba(56,189,248,0.2), rgba(129,140,248,0.18))' }}
|
||||
/>
|
||||
<div
|
||||
className="relative rounded-full border p-0.5"
|
||||
style={{
|
||||
borderColor: 'var(--glass-border)',
|
||||
background: dark ? 'rgba(8,12,19,0.7)' : 'rgba(255,255,255,0.8)',
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
className="rounded-full"
|
||||
style={{ width: 32, height: 32, borderRadius: '50%', overflow: 'hidden', flexShrink: 0 }}
|
||||
>
|
||||
<Avatar.Image src="/logo.png" alt="SnowLuma" className="object-cover" />
|
||||
<Avatar.Fallback>SL</Avatar.Fallback>
|
||||
</Avatar>
|
||||
</div>
|
||||
<div className="flex h-full w-full flex-col bg-sidebar text-sidebar-foreground">
|
||||
{/* Brand */}
|
||||
<div className={cn('flex h-16 items-center gap-3 border-b px-4', collapsed && 'justify-center px-2')}>
|
||||
<div className="relative flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-primary/10 ring-1 ring-primary/20">
|
||||
<img src="/logo.png" alt="SnowLuma" className="size-7 object-contain" />
|
||||
</div>
|
||||
<span className="text-sm font-bold tracking-tight" style={{ color: 'var(--text-primary)' }}>
|
||||
SnowLuma
|
||||
</span>
|
||||
{!collapsed && (
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-baseline gap-1.5">
|
||||
<span className="text-sm font-bold tracking-tight">{APP_NAME}</span>
|
||||
<span className="text-[10px] font-medium text-muted-foreground tabular-nums">v{APP_VERSION}</span>
|
||||
</div>
|
||||
<span className="text-[10px] text-muted-foreground">OneBot v11 控制台</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Navigation */}
|
||||
<nav className="flex-1 px-3 pt-4 flex flex-col gap-1.5">
|
||||
{navItems.map(({ page, label, icon: Icon }) => {
|
||||
const isActive = activePage === page;
|
||||
return (
|
||||
<motion.button
|
||||
whileHover={{ scale: 1.01 }}
|
||||
whileTap={{ scale: 0.98 }}
|
||||
key={page}
|
||||
onClick={() => onNavigate(page)}
|
||||
className="flex items-center gap-2.5 h-9 px-3 rounded-xl text-sm font-medium cursor-pointer relative overflow-hidden"
|
||||
style={{
|
||||
color: isActive ? 'var(--accent)' : 'var(--text-secondary)',
|
||||
background: isActive ? 'var(--accent-subtle)' : 'transparent',
|
||||
transition: 'var(--transition-fast)',
|
||||
}}
|
||||
onMouseEnter={e => { if (!isActive) (e.currentTarget.style.background = 'var(--bg-hover)'); }}
|
||||
onMouseLeave={e => { if (!isActive) (e.currentTarget.style.background = 'transparent'); }}
|
||||
>
|
||||
{isActive && (
|
||||
<motion.div
|
||||
layoutId="sidebarActive"
|
||||
className="absolute inset-0 rounded-xl"
|
||||
style={{
|
||||
background: 'var(--accent-subtle)',
|
||||
border: '1px solid color-mix(in srgb, var(--accent) 24%, transparent)',
|
||||
boxShadow: 'inset 0 1px 0 rgba(255,255,255,0.06)',
|
||||
}}
|
||||
initial={false}
|
||||
transition={{ type: 'spring', stiffness: 400, damping: 30 }}
|
||||
/>
|
||||
)}
|
||||
<Icon
|
||||
size={16}
|
||||
strokeWidth={isActive ? 2.2 : 1.8}
|
||||
className="relative z-10 shrink-0"
|
||||
style={{ color: isActive ? 'var(--accent)' : undefined }}
|
||||
/>
|
||||
<span className="relative z-10">{label}</span>
|
||||
</motion.button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
{/* Nav */}
|
||||
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
|
||||
<nav className={cn('flex flex-col gap-1 p-2', collapsed && 'items-center')}>
|
||||
{NAV_ITEMS.map(({ page, label, icon: Icon, description }) => {
|
||||
const isActive = active === page;
|
||||
return (
|
||||
<button
|
||||
key={page}
|
||||
type="button"
|
||||
title={collapsed ? label : undefined}
|
||||
onClick={() => {
|
||||
onNavigate(page);
|
||||
onItemClick?.();
|
||||
}}
|
||||
className={cn(
|
||||
'group relative flex w-full items-center gap-3 rounded-lg px-3 py-2.5 text-sm font-medium transition-colors cursor-pointer outline-none',
|
||||
collapsed && 'w-10 justify-center px-0',
|
||||
isActive
|
||||
? 'text-sidebar-accent-foreground'
|
||||
: 'text-muted-foreground hover:bg-sidebar-accent/40 hover:text-foreground'
|
||||
)}
|
||||
>
|
||||
{isActive && (
|
||||
<motion.span
|
||||
layoutId="sidebar-active-pill"
|
||||
className="absolute inset-0 rounded-lg bg-sidebar-accent ring-1 ring-primary/20"
|
||||
transition={{ type: 'spring', stiffness: 380, damping: 32 }}
|
||||
/>
|
||||
)}
|
||||
<Icon className={cn('relative z-10 size-4 shrink-0', isActive && 'text-primary')} />
|
||||
{!collapsed && (
|
||||
<span className="relative z-10 flex min-w-0 flex-1 flex-col items-start">
|
||||
<span className="truncate leading-tight">{label}</span>
|
||||
<span className="text-[10px] font-normal text-muted-foreground truncate">{description}</span>
|
||||
</span>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</nav>
|
||||
</ScrollArea>
|
||||
|
||||
{/* Bottom */}
|
||||
<div className="relative p-3 flex flex-col gap-2" style={{ borderTop: '1px solid var(--border-subtle)' }}>
|
||||
<div className="flex items-center justify-between px-1">
|
||||
<StatusBadge status={status} />
|
||||
<div className="flex items-center gap-0.5">
|
||||
{THEME_OPTIONS.map(({ mode: m, icon: Icon, label }) => {
|
||||
const active = mode === m;
|
||||
return (
|
||||
<button
|
||||
key={m}
|
||||
title={label}
|
||||
onClick={() => setMode(m)}
|
||||
className="relative flex size-7 cursor-pointer items-center justify-center rounded-lg transition-colors duration-200"
|
||||
style={{ color: active ? 'var(--accent)' : 'var(--text-tertiary)' }}
|
||||
>
|
||||
{active && (
|
||||
<motion.div
|
||||
layoutId="sidebar-theme-pill"
|
||||
className="absolute inset-0 rounded-lg"
|
||||
style={{ background: 'var(--accent-subtle)' }}
|
||||
transition={{ type: 'spring', stiffness: 400, damping: 30 }}
|
||||
/>
|
||||
)}
|
||||
<Icon size={13} className="relative z-10" />
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
<motion.button
|
||||
whileHover={{ scale: 1.01 }}
|
||||
whileTap={{ scale: 0.98 }}
|
||||
onClick={onLogout}
|
||||
className="flex items-center justify-center gap-2 h-8 rounded-lg text-xs font-medium cursor-pointer"
|
||||
style={{
|
||||
color: 'var(--text-tertiary)',
|
||||
border: '1px solid var(--border-subtle)',
|
||||
transition: 'var(--transition-fast)',
|
||||
}}
|
||||
onMouseEnter={e => { e.currentTarget.style.color = 'var(--color-danger)'; e.currentTarget.style.borderColor = 'rgba(248,113,113,0.2)'; e.currentTarget.style.background = 'rgba(248,113,113,0.06)'; }}
|
||||
onMouseLeave={e => { e.currentTarget.style.color = 'var(--text-tertiary)'; e.currentTarget.style.borderColor = 'var(--border-subtle)'; e.currentTarget.style.background = 'transparent'; }}
|
||||
>
|
||||
<LogOut size={13} strokeWidth={2} />
|
||||
登出
|
||||
</motion.button>
|
||||
<Separator />
|
||||
<div className={cn('px-4 py-3 text-[10px] text-muted-foreground', collapsed && 'text-center px-2')}>
|
||||
{collapsed ? '©' : `© ${new Date().getFullYear()} SnowLuma`}
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
import { Moon, Sun } from 'lucide-react';
|
||||
import { useTheme } from '../../contexts/ThemeContext';
|
||||
|
||||
interface TopBarProps {
|
||||
title: string;
|
||||
subtitle?: string;
|
||||
}
|
||||
|
||||
export function TopBar({ title, subtitle }: TopBarProps) {
|
||||
const { resolved, mode, setMode } = useTheme();
|
||||
const cycleTheme = () => setMode(mode === 'system' ? 'light' : mode === 'light' ? 'dark' : 'system');
|
||||
|
||||
return (
|
||||
<header className="h-14 shrink-0 flex items-center justify-between px-6 border-b border-zinc-200/60 dark:border-white/6 bg-white/60 dark:bg-zinc-900/60 backdrop-blur-xl">
|
||||
<div>
|
||||
<h1 className="text-lg font-semibold text-zinc-900 dark:text-zinc-100 tracking-tight">{title}</h1>
|
||||
{subtitle && <p className="text-xs text-zinc-400 dark:text-zinc-500 mt-0.5">{subtitle}</p>}
|
||||
</div>
|
||||
<button
|
||||
onClick={cycleTheme}
|
||||
className="size-8 flex items-center justify-center rounded-lg text-zinc-400 hover:text-zinc-700 dark:hover:text-zinc-200 hover:bg-zinc-100 dark:hover:bg-white/8 transition-all duration-150 cursor-pointer"
|
||||
>
|
||||
{resolved === 'light' ? <Moon size={16} /> : <Sun size={16} />}
|
||||
</button>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
import { useEffect, useState, type ReactNode } from 'react';
|
||||
import { motion, AnimatePresence } from 'motion/react';
|
||||
import { Sheet, SheetContent } from '@/components/ui/sheet';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { Sidebar, type Page } from '@/components/layout/sidebar';
|
||||
import { TopBar } from '@/components/layout/top-bar';
|
||||
import { useMediaQuery } from '@/hooks/use-media-query';
|
||||
import { cn } from '@/lib/utils';
|
||||
|
||||
interface MainLayoutProps {
|
||||
active: Page;
|
||||
onNavigate: (page: Page) => void;
|
||||
status: string;
|
||||
onLogout: () => void;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function MainLayout({ active, onNavigate, status, onLogout, children }: MainLayoutProps) {
|
||||
const isMobile = !useMediaQuery('(min-width: 768px)');
|
||||
const [collapsed, setCollapsed] = useState(() => {
|
||||
return localStorage.getItem('snowluma_sidebar_collapsed') === '1';
|
||||
});
|
||||
const [mobileOpen, setMobileOpen] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
localStorage.setItem('snowluma_sidebar_collapsed', collapsed ? '1' : '0');
|
||||
}, [collapsed]);
|
||||
|
||||
return (
|
||||
<div className="flex h-screen w-screen overflow-hidden bg-background text-foreground">
|
||||
{/* Desktop sidebar */}
|
||||
{!isMobile && (
|
||||
<motion.aside
|
||||
initial={false}
|
||||
animate={{ width: collapsed ? 64 : 248 }}
|
||||
transition={{ type: 'spring', stiffness: 280, damping: 32 }}
|
||||
className="relative h-full shrink-0 border-r overflow-hidden"
|
||||
>
|
||||
<Sidebar active={active} onNavigate={onNavigate} collapsed={collapsed} />
|
||||
</motion.aside>
|
||||
)}
|
||||
|
||||
{/* Mobile sidebar in sheet */}
|
||||
{isMobile && (
|
||||
<Sheet open={mobileOpen} onOpenChange={setMobileOpen}>
|
||||
<SheetContent side="left" className="w-64 max-w-[80vw] p-0">
|
||||
<Sidebar
|
||||
active={active}
|
||||
onNavigate={onNavigate}
|
||||
onItemClick={() => setMobileOpen(false)}
|
||||
/>
|
||||
</SheetContent>
|
||||
</Sheet>
|
||||
)}
|
||||
|
||||
{/* Main column */}
|
||||
<div className="flex min-w-0 flex-1 flex-col">
|
||||
<TopBar
|
||||
active={active}
|
||||
status={status}
|
||||
collapsed={collapsed}
|
||||
onToggleCollapse={() => setCollapsed((v) => !v)}
|
||||
onOpenMobile={() => setMobileOpen(true)}
|
||||
onLogout={onLogout}
|
||||
isMobile={isMobile}
|
||||
/>
|
||||
|
||||
<main className={cn('flex min-h-0 flex-1 flex-col')}>
|
||||
<ScrollArea className="flex-1 min-h-0" viewportClassName="[&>div]:!block">
|
||||
<div className="mx-auto w-full max-w-7xl px-4 py-5 sm:px-6 sm:py-6 lg:px-8">
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={active}
|
||||
initial={{ opacity: 0, y: 10 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -8 }}
|
||||
transition={{ duration: 0.22, ease: [0.16, 1, 0.3, 1] }}
|
||||
>
|
||||
{children}
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
import { useState } from 'react';
|
||||
import { LogOut, Menu, PanelLeftClose, PanelLeftOpen } from 'lucide-react';
|
||||
import { motion, AnimatePresence } from 'motion/react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { ThemeToggle } from '@/components/theme-toggle';
|
||||
import { ConfirmDialog } from '@/components/confirm-dialog';
|
||||
import type { Page } from '@/components/layout/sidebar';
|
||||
import { NAV_ITEMS } from '@/components/layout/sidebar';
|
||||
|
||||
interface TopBarProps {
|
||||
active: Page;
|
||||
status: string;
|
||||
collapsed: boolean;
|
||||
onToggleCollapse: () => void;
|
||||
onOpenMobile: () => void;
|
||||
onLogout: () => void;
|
||||
isMobile: boolean;
|
||||
}
|
||||
|
||||
export function TopBar({
|
||||
active,
|
||||
status,
|
||||
collapsed,
|
||||
onToggleCollapse,
|
||||
onOpenMobile,
|
||||
onLogout,
|
||||
isMobile,
|
||||
}: TopBarProps) {
|
||||
const [confirmLogout, setConfirmLogout] = useState(false);
|
||||
const meta = NAV_ITEMS.find((n) => n.page === active);
|
||||
const PageIcon = meta?.icon;
|
||||
const online = status === '已连接';
|
||||
|
||||
return (
|
||||
<header className="sticky top-0 z-30 flex h-16 shrink-0 items-center gap-2 border-b bg-background/55 px-3 backdrop-blur-xl backdrop-saturate-150 supports-[backdrop-filter]:bg-background/45 sm:px-4">
|
||||
{/* Collapse toggle (desktop) / menu (mobile) */}
|
||||
{isMobile ? (
|
||||
<Button variant="ghost" size="icon-sm" onClick={onOpenMobile} aria-label="打开菜单">
|
||||
<Menu className="size-4" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={onToggleCollapse}
|
||||
aria-label={collapsed ? '展开侧边栏' : '收起侧边栏'}
|
||||
title={collapsed ? '展开侧边栏' : '收起侧边栏'}
|
||||
>
|
||||
{collapsed ? <PanelLeftOpen className="size-4" /> : <PanelLeftClose className="size-4" />}
|
||||
</Button>
|
||||
)}
|
||||
|
||||
<div className="mx-1 h-6 w-px bg-border" />
|
||||
|
||||
{/* Page title */}
|
||||
<AnimatePresence mode="wait">
|
||||
<motion.div
|
||||
key={active}
|
||||
initial={{ opacity: 0, x: -8 }}
|
||||
animate={{ opacity: 1, x: 0 }}
|
||||
exit={{ opacity: 0, x: 8 }}
|
||||
transition={{ duration: 0.18 }}
|
||||
className="flex min-w-0 items-center gap-2"
|
||||
>
|
||||
{PageIcon && <PageIcon className="size-4 text-primary" />}
|
||||
<h1 className="truncate text-sm font-semibold tracking-tight">{meta?.label}</h1>
|
||||
<span className="hidden sm:inline truncate text-xs text-muted-foreground">{meta?.description}</span>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
|
||||
<div className="ml-auto flex items-center gap-2">
|
||||
<Badge
|
||||
variant={online ? 'success' : 'destructive'}
|
||||
className="hidden sm:inline-flex gap-1.5"
|
||||
>
|
||||
<span
|
||||
className={`size-1.5 rounded-full ${online ? 'bg-success' : 'bg-destructive'} ${online ? 'animate-pulse' : ''}`}
|
||||
/>
|
||||
{status}
|
||||
</Badge>
|
||||
|
||||
<ThemeToggle />
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
onClick={() => setConfirmLogout(true)}
|
||||
aria-label="登出"
|
||||
title="登出"
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
<LogOut className="size-4" />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<ConfirmDialog
|
||||
open={confirmLogout}
|
||||
onOpenChange={setConfirmLogout}
|
||||
title="确认登出?"
|
||||
description="登出后将清除当前会话令牌,您需要重新输入访问密码才能进入控制台。"
|
||||
confirmText="登出"
|
||||
destructive
|
||||
onConfirm={onLogout}
|
||||
/>
|
||||
</header>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user