一个轻量级的 React 18 后台管理系统模板,开箱即用。
- 🚀 最新技术栈 - React 18 + TypeScript + Vite
- 📦 组件丰富 - 基于 Ant Design 5 + ProComponents
- 🎨 主题定制 - 支持动态主题色切换
- 📊 数据可视化 - 集成 @ant-design/plots 图表库
- 🔐 权限管理 - 内置登录认证流程
- 📱 响应式设计 - 完美适配各种屏幕尺寸
- 🛠️ 工程化 - ESLint + Prettier + Husky + Commitlint
src/
├── components/ # 公共组件
│ ├── ErrorPage/ # 错误页面
│ └── NoAuthPage/ # 无权限页面
├── config/ # 配置文件
│ └── router.tsx # 路由配置
├── layout/ # 布局组件
│ ├── components/
│ │ ├── Header.tsx # 头部组件
│ │ ├── Login.tsx # 登录页面
│ │ └── RightContent.tsx
│ └── index.tsx # 主布局
├── pages/ # 页面组件
│ ├── Dashboard/ # 仪表盘
│ ├── FormPage/ # 表单页
│ ├── TablePage/ # 列表页
│ ├── DetailPage/ # 详情页
│ └── AccountPage/ # 个人中心/设置
├── services/ # API 服务
├── stores/ # 状态管理 (Zustand)
├── utils/ # 工具函数
│ ├── request.ts # HTTP 请求封装
│ ├── func.ts # 通用工具函数
│ └── chartConfig.ts # 图表配置
└── global.d.ts # 类型声明
- Node.js >= 16.0.0
- npm >= 8.0.0 或 pnpm >= 7.0.0
npm install
# 或
pnpm installnpm run start访问 http://localhost:5173 查看应用。
npm run buildnpm run preview路径: /
展示数据统计和图表:
- 统计卡片:支付金额、访客数、订单数、浏览量
- 折线图:趋势数据展示
- 柱状图:分类数据对比
- 饼图:占比数据展示
路径: /form
完整的表单示例,包含:
- 表单验证
- 级联选择
- 自动完成
- 密码确认
路径: /table
高级表格功能:
- 搜索过滤
- 可编辑行
- 排序功能
- 操作按钮
路径: /detail
订单详情展示:
- 金额卡片
- 订单信息
- 用户信息
- 商品列表
- 物流进度时间线
路径: /account/center
用户个人信息展示。
路径: /account/settings
用户设置页面。
使用 Zustand 进行状态管理,支持持久化存储。
// stores/global.ts - 全局状态
import { create } from "zustand";
import { persist } from "zustand/middleware";
interface GlobalState {
primaryColor: string;
setColor: (color: string) => void;
}
export const useGlobalStore = create<GlobalState>()(
persist(
(set) => ({
primaryColor: "#247fff",
setColor: (color) => set({ primaryColor: color }),
}),
{ name: "global-storage" }
)
);封装了 Axios,支持请求/响应拦截器。
import http from "@utils/request";
// GET 请求
const response = await http.get("/api/users", { page: 1 });
// POST 请求
const response = await http.post("/api/users", { name: "John" });
// PUT 请求
const response = await http.put("/api/users/1", { name: "Jane" });
// DELETE 请求
const response = await http.delete("/api/users/1");路由配置位于 src/config/router.tsx,支持懒加载和嵌套路由。
const routes = [
{
path: "/",
element: <App />,
children: [
{ index: true, element: <Dashboard /> },
{ path: "form", element: <FormPage /> },
// ...
],
},
];统一的图表配置,便于维护和扩展。
import {
CHART_COLORS,
COMMON_CONFIG,
createAxisConfig,
} from "@utils/chartConfig";
const config = {
...COMMON_CONFIG,
data: yourData,
xField: "x",
yField: "y",
color: CHART_COLORS.primary,
...createAxisConfig({ formatY: true }),
};import { debounce } from "@utils/func";
const debouncedFn = debounce((value) => {
console.log(value);
}, 300);import { throttle } from "@utils/func";
const throttledFn = throttle((value) => {
console.log(value);
}, 300);import { formatDate } from "@utils/func";
formatDate(new Date()); // "2024-01-15 14:30:25"
formatDate(new Date(), "YYYY-MM-DD"); // "2024-01-15"import { deepClone } from "@utils/func";
const cloned = deepClone(originalObject);在头部右侧点击颜色选择器即可切换主题色。
编辑 src/stores/global.ts:
primaryColor: "#your-color",创建 .env 文件:
VITE_API_BASE_URL=https://your-api.com
VITE_APP_TITLE=Your App Name
使用 Commitizen 规范提交信息:
npm run commit提交类型:
feat: 新功能fix: 修复 bugdocs: 文档更新style: 代码格式调整refactor: 代码重构test: 测试相关chore: 构建/工具相关
# 运行 ESLint
npm run lint
# 自动修复
npm run lint -- --fix- 在
src/pages/下创建页面组件 - 在
src/pages/index.ts中导出 - 在
src/config/router.tsx中添加路由 - 在
src/layout/index.tsx中添加菜单项
- 在
src/services/下创建服务文件 - 使用
http实例发起请求
// services/user.ts
import http from "@utils/request";
export const getUserList = () => http.get("/api/users");
export const createUser = (data) => http.post("/api/users", data);- 在
src/pages/Dashboard/components/下创建图表组件 - 使用
@utils/chartConfig中的通用配置 - 在 Dashboard 页面引入并使用
A: 修改 vite.config.ts:
export default defineConfig({
server: {
port: 3000,
},
});A: 修改 vite.config.ts:
export default defineConfig({
server: {
proxy: {
"/api": {
target: "http://your-api-server.com",
changeOrigin: true,
},
},
},
});A: 在路由配置中使用 loader 进行权限验证:
const routes = [
{
path: "/admin",
element: <AdminPage />,
loader: authLoader,
},
];| 技术 | 版本 | 说明 |
|---|---|---|
| React | 18.2.0 | UI 框架 |
| TypeScript | 4.9.5 | 类型支持 |
| Vite | 4.3.3 | 构建工具 |
| Ant Design | 5.4.2 | UI 组件库 |
| ProComponents | 2.4.4 | 高级组件 |
| Zustand | 4.3.7 | 状态管理 |
| React Router | 6.10.0 | 路由管理 |
| Axios | 1.3.6 | HTTP 请求 |
| Day.js | 1.11.7 | 日期处理 |
MIT