在 tailwind.config.js 中添加科技感主题配置:
// tailwind.config.js
module.exports = {
theme: {
extend: {
colors: {
'tech-primary': '#0f172a',
'tech-surface': '#1e293b',
'tech-card': 'rgba(30, 41, 59, 0.8)',
'tech-accent': '#8b5cf6',
'tech-cyan': '#06b6d4',
'tech-green': '#10b981',
},
backgroundImage: {
'tech-gradient': 'linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%)',
'card-glow': 'linear-gradient(145deg, rgba(30, 27, 75, 0.8), rgba(15, 23, 42, 0.6))',
},
boxShadow: {
'tech-glow': '0 0 20px rgba(139, 92, 246, 0.3)',
'card-shadow': '0 8px 32px rgba(0, 0, 0, 0.3)',
},
animation: {
'pulse-glow': 'pulse-glow 2s ease-in-out infinite alternate',
'float': 'float 6s ease-in-out infinite',
}
}
}
}
创建文件:src/client/admin/components/TechBackground.tsx
import React from 'react';
export const TechBackground: React.FC = () => {
return (
<div className="fixed inset-0 -z-10 overflow-hidden">
<div className="absolute inset-0 bg-gradient-to-br from-slate-900 via-purple-900/20 to-slate-900" />
{/* 网格背景 */}
<div
className="absolute inset-0 opacity-10"
style={{
backgroundImage: `
linear-gradient(rgba(139, 92, 246, 0.1) 1px, transparent 1px),
linear-gradient(90deg, rgba(139, 92, 246, 0.1) 1px, transparent 1px)
`,
backgroundSize: '50px 50px'
}}
/>
{/* 动态光效 */}
<div className="absolute top-0 left-0 w-full h-full overflow-hidden">
<div className="absolute -top-40 -right-40 w-80 h-80 bg-purple-500 rounded-full mix-blend-multiply filter blur-3xl opacity-20 animate-float" />
<div className="absolute -bottom-40 -left-40 w-80 h-80 bg-cyan-500 rounded-full mix-blend-multiply filter blur-3xl opacity-20 animate-float animation-delay-2000" />
</div>
</div>
);
};
创建文件:src/client/admin/components/TechStatCard.tsx
import React from 'react';
import { Card } from 'antd';
import { TrendingUpOutlined, TrendingDownOutlined } from '@ant-design/icons';
interface TechStatCardProps {
title: string;
value: string | number;
icon: React.ReactNode;
trend?: number;
color?: string;
description?: string;
}
export const TechStatCard: React.FC<TechStatCardProps> = ({
title,
value,
icon,
trend,
color = '#8b5cf6',
description
}) => {
const isPositive = trend && trend > 0;
return (
<div className="relative group">
<div
className="absolute inset-0 rounded-xl blur-lg opacity-0 group-hover:opacity-30 transition-opacity duration-300"
style={{ background: `linear-gradient(135deg, ${color}, ${color}aa)` }}
/>
<Card className="relative bg-slate-800/80 backdrop-blur-sm border border-slate-700/50 rounded-xl hover:border-purple-500/50 transition-all duration-300">
<div className="flex items-center justify-between">
<div>
<p className="text-sm text-slate-400 mb-1">{title}</p>
<p className="text-2xl font-bold text-white">{value}</p>
{description && (
<p className="text-xs text-slate-500 mt-1">{description}</p>
)}
</div>
<div
className="p-3 rounded-lg bg-slate-700/50"
style={{ color }}
>
{React.cloneElement(icon as React.ReactElement, { className: 'text-2xl' })}
</div>
</div>
{trend !== undefined && (
<div className="flex items-center mt-3">
{isPositive ? (
<TrendingUpOutlined className="text-green-400 mr-1" />
) : (
<TrendingDownOutlined className="text-red-400 mr-1" />
)}
<span className={`text-sm ${isPositive ? 'text-green-400' : 'text-red-400'}`}>
{Math.abs(trend)}%
</span>
<span className="text-xs text-slate-500 ml-1">vs last week</span>
</div>
)}
</Card>
</div>
);
};
首先升级MainLayout.tsx:
// 关键修改点
const TechMainLayout = () => {
return (
<Layout className="min-h-screen bg-slate-900">
<TechBackground />
<Sider
className="relative bg-slate-800/90 backdrop-blur-sm border-r border-slate-700/50"
style={{
boxShadow: '0 0 20px rgba(139, 92, 246, 0.1)',
zIndex: 100
}}
>
{/* 侧边栏品牌区域 */}
<div className="p-6 border-b border-slate-700/50">
<div className="flex items-center justify-center">
<div className="text-2xl font-bold bg-gradient-to-r from-purple-400 to-cyan-400 bg-clip-text text-transparent">
{collapsed ? 'Q' : '量子控制台'}
</div>
</div>
</div>
{/* 菜单区域 */}
<Menu
theme="dark"
mode="inline"
className="bg-transparent border-none"
style={{ background: 'transparent' }}
/>
</Sider>
<Layout className="bg-transparent">
<Header className="relative bg-slate-800/90 backdrop-blur-sm border-b border-slate-700/50">
<div className="flex items-center justify-between h-full">
<Button
type="text"
icon={collapsed ? <MenuUnfoldOutlined /> : <MenuFoldOutlined />}
onClick={() => setCollapsed(!collapsed)}
className="text-slate-300 hover:text-white"
/>
{/* 右侧用户区域 */}
<Space>
<Badge count={5} offset={[0, 5]}>
<Button
type="text"
icon={<BellOutlined />}
className="text-slate-300 hover:text-white"
/>
</Badge>
<Dropdown menu={{ items: userMenuItems }}>
<Space className="cursor-pointer text-slate-300 hover:text-white">
<Avatar
src={user?.avatar}
className="border-2 border-purple-500"
/>
<span>{user?.nickname || user?.username}</span>
</Space>
</Dropdown>
</Space>
</div>
</Header>
<Content className="p-6">
<div className="bg-slate-800/80 backdrop-blur-sm border border-slate-700/50 rounded-xl p-6 min-h-[calc(100vh-200px)]">
<Outlet />
</div>
</Content>
</Layout>
</Layout>
);
};
在 src/client/admin/index.tsx 中添加全局样式:
// 添加到文件顶部
import './styles/globals.css';
// 在globals.css中添加
@tailwind base;
@tailwind components;
@tailwind utilities;
@layer base {
body {
@apply bg-slate-900 text-slate-100;
}
}
@layer components {
.tech-card {
@apply bg-slate-800/80 backdrop-blur-sm border border-slate-700/50 rounded-xl hover:border-purple-500/50 transition-all duration-300;
}
.tech-button {
@apply bg-gradient-to-r from-purple-600 to-cyan-600 hover:from-purple-700 hover:to-cyan-700 text-white rounded-lg transition-all duration-300 hover:shadow-lg hover:shadow-purple-500/25;
}
}
@layer utilities {
.text-gradient {
@apply bg-gradient-to-r from-purple-400 to-cyan-400 bg-clip-text text-transparent;
}
}
/* 使用backdrop-filter的降级方案 */
@supports not (backdrop-filter: blur(10px)) {
.backdrop-blur-sm {
background-color: rgba(30, 41, 59, 0.95);
}
}
transform 和 opacity 进行动画will-change 属性// 使用响应式工具类
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
{/* 内容 */}
</div>
升级后的管理后台将具有以下特征: