refactor: ♻️ 使用Ant Design全局化配置

This commit is contained in:
Stev_Wang
2025-12-27 20:31:42 +08:00
parent 2d8566132e
commit 598cd3026b
4 changed files with 58 additions and 9 deletions

6
.gitignore vendored
View File

@@ -58,14 +58,14 @@ Thumbs.db
*.temp *.temp
.cache/ .cache/
# Frontend specific # Frontend specific (React + Vite)
frontend/dist/ frontend/dist/
frontend/node_modules/ frontend/node_modules/
frontend/.env frontend/.env
frontend/.env.local frontend/.env.local
frontend/.env.*.local frontend/.env.*.local
# Backend specific # Backend specific (NestJS)
backend/dist/ backend/dist/
backend/node_modules/ backend/node_modules/
backend/.env backend/.env
@@ -73,7 +73,7 @@ backend/.env.local
backend/.env.*.local backend/.env.*.local
backend/test-game-server.js backend/test-game-server.js
# Package manager files # Package manager lock files
package-lock.json package-lock.json
yarn.lock yarn.lock
pnpm-lock.yaml pnpm-lock.yaml

View File

@@ -1,4 +1,4 @@
import { Layout, Menu, Button, Dropdown } from 'antd'; import { Layout, Menu, Button, Dropdown, theme } from 'antd';
import { import {
HomeOutlined, HomeOutlined,
UserOutlined, UserOutlined,
@@ -12,6 +12,9 @@ import { playerAuthService } from '../services/playerAuthService';
const { Header, Content, Footer } = Layout; const { Header, Content, Footer } = Layout;
const PlayerLayout = () => { const PlayerLayout = () => {
const {
token: { colorBgContainer, colorBgLayout },
} = theme.useToken();
const navigate = useNavigate(); const navigate = useNavigate();
const location = useLocation(); const location = useLocation();
@@ -55,7 +58,7 @@ const PlayerLayout = () => {
display: 'flex', display: 'flex',
alignItems: 'center', alignItems: 'center',
justifyContent: 'space-between', justifyContent: 'space-between',
background: '#001529', background: colorBgLayout,
padding: '0 24px', padding: '0 24px',
}} }}
> >
@@ -93,7 +96,7 @@ const PlayerLayout = () => {
style={{ style={{
padding: '24px 50px', padding: '24px 50px',
minHeight: 'calc(100vh - 128px)', minHeight: 'calc(100vh - 128px)',
background: '#f0f2f5', background: colorBgContainer,
}} }}
> >
<div style={{ padding: 24, minHeight: 380, background: 'white', borderRadius: 8 }}> <div style={{ padding: 24, minHeight: 380, background: 'white', borderRadius: 8 }}>
@@ -103,7 +106,7 @@ const PlayerLayout = () => {
<Footer <Footer
style={{ style={{
textAlign: 'center', textAlign: 'center',
background: '#001529', background: colorBgLayout,
color: 'rgba(255, 255, 255, 0.65)', color: 'rgba(255, 255, 255, 0.65)',
}} }}
> >

View File

@@ -1,14 +1,21 @@
import { StrictMode } from 'react'; import { StrictMode } from 'react';
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import { RouterProvider } from 'react-router-dom'; import { RouterProvider } from 'react-router-dom';
import { ConfigProvider } from 'antd'; import { ConfigProvider, theme } from 'antd';
import zhCN from 'antd/locale/zh_CN'; import zhCN from 'antd/locale/zh_CN';
import './index.css'; import './index.css';
import router from './router'; import router from './router';
import { appTheme } from './theme';
createRoot(document.getElementById('root')!).render( createRoot(document.getElementById('root')!).render(
<StrictMode> <StrictMode>
<ConfigProvider locale={zhCN}> <ConfigProvider
locale={zhCN}
theme={{
algorithm: theme.defaultAlgorithm,
...appTheme,
}}
>
<RouterProvider router={router} /> <RouterProvider router={router} />
</ConfigProvider> </ConfigProvider>
</StrictMode>, </StrictMode>,

View File

@@ -0,0 +1,39 @@
// 全局主题配置
import type { ThemeConfig } from 'antd';
// 自定义主题配置
export const appTheme: ThemeConfig = {
token: {
// 主色调
colorPrimary: '#1890ff',
colorSuccess: '#52c41a',
colorWarning: '#faad14',
colorError: '#ff4d4f',
colorInfo: '#1890ff',
// 字体设置
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif',
fontSize: 14,
// 圆角
borderRadius: 6,
},
components: {
// Layout 组件主题
Layout: {
headerBg: '#001529', // 顶部导航和侧边栏背景色
footerBg: '#001529', // 页脚背景色
siderBg: '#001529', // 侧边栏背景色
},
// Menu 组件主题
Menu: {
darkItemSelectedBg: '#1890ff', // 菜单激活背景色
darkItemHoverBg: 'rgba(24, 144, 255, 0.2)', // 菜单悬停背景色
darkItemColor: 'rgba(255, 255, 255, 0.65)', // 菜单项文字颜色
darkItemSelectedColor: '#fff', // 菜单激活文字颜色
darkItemHoverColor: '#fff', // 菜单悬停文字颜色
},
},
};