# UI Components (Crawlful Hub)
> **定位**:Crawlful Hub 前端 UI 组件规范 - 基于 Ant Design 5.x 的组件库使用指南。
> **更新日期**: 2026-03-18
---
## 1. 设计系统
### 1.1 色彩规范
```typescript
// 主色调
const colors = {
primary: '#1890ff', // 主色
success: '#52c41a', // 成功
warning: '#faad14', // 警告
error: '#f5222d', // 错误
info: '#1890ff', // 信息
};
// 中性色
const neutral = {
textPrimary: 'rgba(0, 0, 0, 0.85)',
textSecondary: 'rgba(0, 0, 0, 0.65)',
textDisabled: 'rgba(0, 0, 0, 0.25)',
border: '#d9d9d9',
background: '#f5f5f5',
};
```
### 1.2 字体规范
```typescript
const typography = {
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial',
fontSize: {
small: '12px',
base: '14px',
medium: '16px',
large: '20px',
xlarge: '24px',
},
};
```
---
## 2. 基础组件
### 2.1 按钮 (Button)
**使用场景**
- 主操作:蓝色主按钮
- 次操作:默认按钮
- 危险操作:红色按钮
- 文字链接:链接按钮
**示例**
```tsx
import { Button, Space } from 'antd';
// 主操作
// 次操作
// 危险操作
// 图标按钮
}>新增
// 加载状态
```
### 2.2 表单 (Form)
**使用场景**
- 商品创建/编辑
- 订单审核
- 用户设置
**示例**
```tsx
import { Form, Input, Select, Button } from 'antd';
const ProductForm: React.FC = () => {
const [form] = Form.useForm();
const onFinish = (values: any) => {
console.log(values);
};
return (
);
};
```
### 2.3 表格 (Table)
**使用场景**
- 商品列表
- 订单列表
- 交易流水
**示例**
```tsx
import { Table, Tag } from 'antd';
const ProductTable: React.FC = () => {
const columns = [
{
title: '商品名称',
dataIndex: 'title',
key: 'title',
},
{
title: '平台',
dataIndex: 'platform',
key: 'platform',
},
{
title: '状态',
dataIndex: 'status',
key: 'status',
render: (status: string) => {
const colorMap: Record = {
DRAFTED: 'default',
PENDING_REVIEW: 'processing',
APPROVED: 'success',
REJECTED: 'error',
};
return {status};
},
},
{
title: '售价',
dataIndex: 'sellingPrice',
key: 'sellingPrice',
render: (price: number) => `$${price.toFixed(2)}`,
},
{
title: '操作',
key: 'action',
render: (_, record) => (
),
},
];
return (
);
};
```
### 2.4 卡片 (Card)
**使用场景**
- 仪表盘统计卡片
- 商品信息展示
- 订单概要
**示例**
```tsx
import { Card, Statistic } from 'antd';
import { ArrowUpOutlined } from '@ant-design/icons';
// 统计卡片
}
/>
// 带标题的卡片
更多}>
商品名称: Product Name
平台: Amazon
状态: 已上架
```
---
## 3. 业务组件
### 3.1 状态徽章 (StatusBadge)
**组件定义**
```tsx
import { Badge } from 'antd';
interface StatusBadgeProps {
status: string;
type: 'product' | 'order' | 'payment';
}
const statusMap: Record> = {
product: {
DRAFTED: { color: 'default', text: '草稿' },
PENDING_REVIEW: { color: 'processing', text: '待审核' },
APPROVED: { color: 'success', text: '已通过' },
REJECTED: { color: 'error', text: '已拒绝' },
LISTED: { color: 'success', text: '已上架' },
DELISTED: { color: 'default', text: '已下架' },
},
order: {
PULLED: { color: 'default', text: '已拉取' },
PENDING_REVIEW: { color: 'processing', text: '待审核' },
CONFIRMED: { color: 'success', text: '已确认' },
SHIPPED: { color: 'blue', text: '已发货' },
DELIVERED: { color: 'success', text: '已送达' },
},
payment: {
PENDING: { color: 'warning', text: '待支付' },
COMPLETED: { color: 'success', text: '已完成' },
FAILED: { color: 'error', text: '失败' },
REFUNDED: { color: 'default', text: '已退款' },
},
};
export const StatusBadge: React.FC = ({ status, type }) => {
const config = statusMap[type]?.[status] || { color: 'default', text: status };
return ;
};
```
### 3.2 筛选面板 (FilterPanel)
**组件定义**
```tsx
import { Form, Input, Select, DatePicker, Button, Space } from 'antd';
interface FilterPanelProps {
onFilter: (values: any) => void;
onReset: () => void;
}
export const FilterPanel: React.FC = ({ onFilter, onReset }) => {
const [form] = Form.useForm();
return (
);
};
```
### 3.3 数据表格 (DataTable)
**组件定义**
```tsx
import { Table, TableProps } from 'antd';
interface DataTableProps extends TableProps {
loading?: boolean;
pagination?: {
current: number;
pageSize: number;
total: number;
};
onPageChange?: (page: number, pageSize: number) => void;
}
export function DataTable({
loading,
pagination,
onPageChange,
...tableProps
}: DataTableProps) {
return (
{...tableProps}
loading={loading}
pagination={pagination ? {
...pagination,
showSizeChanger: true,
showTotal: (total) => `共 ${total} 条`,
onChange: onPageChange,
} : false}
scroll={{ x: 'max-content' }}
/>
);
}
```
---
## 4. 图表组件
### 4.1 利润趋势图
**使用 Ant Design Charts**
```tsx
import { Line } from '@ant-design/charts';
const ProfitChart: React.FC = () => {
const data = [
{ date: '2026-03-01', profit: 1000 },
{ date: '2026-03-02', profit: 1200 },
{ date: '2026-03-03', profit: 900 },
// ...
];
const config = {
data,
xField: 'date',
yField: 'profit',
smooth: true,
point: {
size: 5,
shape: 'diamond',
},
label: {
style: {
fill: '#aaa',
},
},
};
return ;
};
```
### 4.2 订单分布图
```tsx
import { Pie } from '@ant-design/charts';
const OrderDistributionChart: React.FC = () => {
const data = [
{ type: 'Amazon', value: 400 },
{ type: 'eBay', value: 300 },
{ type: 'Shopify', value: 300 },
];
const config = {
data,
angleField: 'value',
colorField: 'type',
radius: 0.8,
label: {
type: 'outer',
},
};
return ;
};
```
---
## 5. 布局组件
### 5.1 主布局 (MainLayout)
```tsx
import { Layout, Menu } from 'antd';
import { Outlet, useNavigate } from 'react-router-dom';
const { Header, Sider, Content } = Layout;
const MainLayout: React.FC = () => {
const navigate = useNavigate();
const menuItems = [
{ key: '/', label: '仪表盘', icon: },
{ key: '/products', label: '商品管理', icon: },
{ key: '/orders', label: '订单管理', icon: },
{ key: '/finance', label: '财务管理', icon: },
{ key: '/inventory', label: '库存管理', icon: },
{ key: '/marketing', label: '营销广告', icon: },
{ key: '/suppliers', label: '供应商', icon: },
{ key: '/reports', label: '报表分析', icon: },
{ key: '/settings', label: '系统设置', icon: },
];
return (
Crawlful Hub
);
};
```
---
## 6. 表单校验规则
```typescript
// utils/validators.ts
export const validators = {
required: (message: string) => ({ required: true, message }),
email: { type: 'email', message: '请输入有效的邮箱地址' },
price: (min: number = 0) => ({
validator: (_: any, value: number) => {
if (value >= min) return Promise.resolve();
return Promise.reject(new Error(`价格不能低于 ${min}`));
},
}),
url: { type: 'url', message: '请输入有效的URL' },
};
```
---
## 7. 相关文档
- [Frontend Design](./Frontend_Design.md)
- [Pages Flow](./Pages_Flow.md)
- [Ant Design 官方文档](https://ant.design/)
---
*本文档基于 Ant Design 5.x,最后更新: 2026-03-18*