Công thức trang
Cách ghép component cho các loại trang hay gặp như dashboard, danh sách, form dài, cài đặt, trang kết quả, theo bố cục của ant-design-pro, kèm các tên prop cũ cần thay.
Mỗi công thức là thứ tự các khối từ trên xuống. Chọn công thức gần với trang bạn cần nhất, rồi thay dữ liệu và chữ cho đúng nghiệp vụ. Ví dụ dưới đây là dashboard của chủ một cửa hàng, dựng theo công thức đầu tiên.
// Dashboard của chủ cửa hàng nội thất 3 kênh: chọn kỳ (hôm nay / 7 ngày / tháng / 12 tháng) đổi mọi con số, 4 KPI có so sánh kỳ trước, biểu đồ doanh thu – lợi nhuận, tỷ trọng kênh, sản phẩm bán chạy, việc cần xử lý và tồn kho cảnh báo.
// Trong app thật: api.reports.summary({ period }) trả KPI + chuỗi theo ngày/tháng; api.tasks.counts(), api.inventory.lowStock() thay cho dữ liệu mẫu.
import { useMemo, useState } from "react";
import { PageContainer, ProCard, StatisticCard } from "@ant-design/pro-components";
import { Badge, Button, Col, Flex, Progress, Row, Segmented, Table, Tooltip, Typography, theme, type TableProps } from "antd";
import { ArrowDownOutlined, ArrowUpOutlined, ClockCircleOutlined, DollarOutlined, DownloadOutlined, InboxOutlined, RightOutlined, CarOutlined } from "@ant-design/icons";
import { Column, Pie, Tiny } from "@ant-design/charts";
import dayjs, { type Dayjs } from "dayjs";
type Period = "today" | "7d" | "month" | "12m";
type Day = { date: Dayjs; rev: number[]; gp: number[]; orders: number[] };
const NOW = dayjs("2026-11-13T14:30:00");
const TODAY_SHARE = 0.58; // phần doanh thu một ngày thường đạt được trước 14:30
const CHANNELS = [{ label: "Showroom", aov: 9.2e6, margin: 0.41 }, { label: "Website", aov: 4.6e6, margin: 0.35 }, { label: "Dự án B2B", aov: 0, margin: 0.27 }];
const nf = new Intl.NumberFormat("vi-VN");
const vnd = (n: number) => `${nf.format(Math.round(n))} ₫`;
const num = (n: number, d: number) => new Intl.NumberFormat("vi-VN", { maximumFractionDigits: d }).format(n);
const short = (n: number) => (Math.abs(n) >= 1e9 ? `${num(n / 1e9, 2)} tỷ` : `${num(n / 1e6, Math.abs(n) >= 1e8 ? 0 : 1)} tr`);
const pct = (x: number) => `${new Intl.NumberFormat("vi-VN", { minimumFractionDigits: 1, maximumFractionDigits: 1 }).format(x * 100)}%`;
const sum = (a: number[]) => a.reduce((s, v) => s + v, 0);
// Dữ liệu mẫu: 731 ngày bán hàng sinh từ một seed cố định (mulberry32) — cùng kết quả mỗi lần render.
function rng(seed: number) {
return () => { seed = (seed + 0x6d2b79f5) | 0; let t = Math.imul(seed ^ (seed >>> 15), 1 | seed); t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t; return ((t ^ (t >>> 14)) >>> 0) / 4294967296; };
}
const DAYS: Day[] = (() => {
const r = rng(2026);
const round = (v: number) => Math.round(v / 1e5) * 1e5;
return Array.from({ length: 731 }, (_, i) => {
const date = NOW.startOf("day").subtract(730 - i, "day");
const k = (0.8 + (0.2 * i) / 730) * (i === 730 ? TODAY_SHARE : 1);
const weekend = date.day() === 0 || date.day() === 6 ? 1.55 : 1;
const rev = [round(48e6 * k * weekend * (0.75 + 0.5 * r())), round(22e6 * k * (0.7 + 0.6 * r())), r() < 0.22 ? round((60 + 220 * r()) * 1e6 * k) : 0];
const gp = rev.map((v, c) => round(v * (CHANNELS[c].margin + (r() - 0.5) * 0.04)));
const orders = [Math.max(1, Math.round(rev[0] / CHANNELS[0].aov)), Math.max(1, Math.round(rev[1] / CHANNELS[1].aov)), rev[2] ? 1 : 0];
return { date, rev, gp, orders };
});
})();
const between = (a: Dayjs, b: Dayjs) => DAYS.filter((d) => !d.date.isBefore(a, "day") && !d.date.isAfter(b, "day"));
const scale = (d: Day, k: number): Day => ({ ...d, rev: d.rev.map((v) => v * k), gp: d.gp.map((v) => v * k), orders: d.orders.map((v) => Math.round(v * k)) });
const total = (days: Day[]) => ({
rev: [0, 1, 2].map((c) => sum(days.map((d) => d.rev[c]))),
gp: [0, 1, 2].map((c) => sum(days.map((d) => d.gp[c]))),
orders: [0, 1, 2].map((c) => sum(days.map((d) => d.orders[c]))),
});
const HOURS = [8, 9, 10, 11, 12, 13, 14];
const HOUR_W = [0.06, 0.12, 0.16, 0.18, 0.14, 0.17, 0.17];
function buildPeriod(p: Period) {
const t = NOW.startOf("day");
const [cur, prev, prevLabel] =
p === "today" ? [between(t, t), between(t.subtract(1, "day"), t.subtract(1, "day")).map((d) => scale(d, TODAY_SHARE)), "hôm qua cùng giờ"]
: p === "7d" ? [between(t.subtract(6, "day"), t), between(t.subtract(13, "day"), t.subtract(7, "day")), "7 ngày trước đó"]
: p === "month" ? [between(t.startOf("month"), t), between(t.subtract(1, "month").startOf("month"), t.subtract(1, "month")), `cùng kỳ tháng ${t.subtract(1, "month").month() + 1}`]
: [between(t.subtract(11, "month").startOf("month"), t), between(t.subtract(23, "month").startOf("month"), t.subtract(12, "month")), "12 tháng trước đó"];
// Cột biểu đồ: theo giờ (hôm nay), theo ngày (7 ngày, tháng này), theo tháng (12 tháng).
const groups = new Map<string, Day[]>();
if (p === "today") HOURS.forEach((h, i) => groups.set(`${h}h`, [scale(cur[0], HOUR_W[i])]));
else cur.forEach((d) => { const key = d.date.format(p === "12m" ? "MM/YY" : "DD/MM"); groups.set(key, [...(groups.get(key) ?? []), d]); });
const buckets = [...groups].map(([label, days]) => ({ label, ...total(days) }));
// Đơn đang xử lý: đơn của kỳ chưa giao xong, chia theo tuổi đơn.
const status = [0, 0, 0];
cur.forEach((d) => {
const age = t.diff(d.date, "day");
d.orders.forEach((n, c) => {
const open = Math.round(n * (age === 0 ? 0.9 : age <= 6 ? 0.55 : age <= 20 ? 0.18 : c === 2 && age <= 60 ? 0.4 : 0));
status[age === 0 ? 0 : age <= 6 ? 1 : 2] += open;
});
});
return { cur: total(cur), prev: total(prev), prevLabel, buckets, status };
}
const PRODUCTS = [
{ name: "Sofa da Milano 3 chỗ", price: 32.9e6, share: [0.16, 0.08, 0.02] },
{ name: "Bàn ăn gỗ sồi Oslo 6 ghế", price: 18.5e6, share: [0.12, 0.07, 0.03] },
{ name: "Giường óc chó Kyoto 1m8", price: 24.9e6, share: [0.11, 0.06, 0.02] },
{ name: "Ghế công thái học ErgoPro", price: 4.29e6, share: [0.03, 0.12, 0.1] },
{ name: "Bàn nâng hạ Flex 1m4", price: 8.9e6, share: [0.03, 0.09, 0.14] },
{ name: "Ghế văn phòng Mesh", price: 2.19e6, share: [0.01, 0.04, 0.22] },
{ name: "Tủ áo Nordic 4 cánh", price: 15.9e6, share: [0.08, 0.05, 0.04] },
];
type Stock = { sku: string; name: string; warehouse: string; onHand: number; min: number; incoming: number; eta?: string; perDay: number };
const STOCK: Stock[] = [
{ sku: "SF-MIL3-GR", name: "Sofa da Milano 3 chỗ · xám", warehouse: "Showroom Q7", onHand: 0, min: 3, incoming: 4, eta: "25/11", perDay: 0.4 },
{ sku: "GVP-MESH-BK", name: "Ghế văn phòng Mesh · đen", warehouse: "Kho Bình Dương", onHand: 18, min: 60, incoming: 120, eta: "20/11", perDay: 7.5 },
{ sku: "BNH-FLX14-WH", name: "Bàn nâng hạ Flex 1m4 · trắng", warehouse: "Kho Bình Dương", onHand: 6, min: 15, incoming: 0, perDay: 1.6 },
{ sku: "GCT-ERGO-BK", name: "Ghế công thái học ErgoPro", warehouse: "Kho Bình Dương", onHand: 9, min: 20, incoming: 40, eta: "18/11", perDay: 2.1 },
{ sku: "KTV-WAL20", name: "Kệ tivi Walnut 2m", warehouse: "Showroom Q7", onHand: 4, min: 5, incoming: 0, perDay: 0.3 },
];
const DEBTS = [186_000_000, 142_500_000, 84_000_000]; // 3 khách B2B quá hạn thanh toán
const STATUS_LABELS = ["Chờ xác nhận", "Đang chuẩn bị hàng", "Đang giao & lắp đặt"];
export default function Page() {
const { token } = theme.useToken();
const [period, setPeriod] = useState<Period>("month");
const d = useMemo(() => buildPeriod(period), [period]);
const rev = sum(d.cur.rev), prevRev = sum(d.prev.rev), gp = sum(d.cur.gp), prevGp = sum(d.prev.gp);
const orders = sum(d.cur.orders), prevOrders = sum(d.prev.orders);
const margin = gp / rev, prevMargin = prevGp / prevRev;
const open = sum(d.status);
const chColors = [token.colorPrimary, token.cyan, token.gold];
const stColors = [token.colorWarning, token.colorPrimary, token.colorSuccess];
const unit = period === "today" ? "giờ" : period === "12m" ? "tháng" : "ngày";
const delta = (x: number, text: string) => (
<Typography.Text style={{ color: x >= 0 ? token.colorSuccess : token.colorError }}>
{x >= 0 ? <ArrowUpOutlined /> : <ArrowDownOutlined />} {text} <Typography.Text type="secondary">so với {d.prevLabel}</Typography.Text>
</Typography.Text>
);
const spark = (data: number[]) => (
<Tiny.Area height={44} data={data.map((value, index) => ({ index, value }))} xField="index" yField="value" shapeField="smooth"
style={{ fill: token.colorPrimary, fillOpacity: 0.18 }} />
);
const top = PRODUCTS.map((p) => {
const value = sum(p.share.map((s, c) => s * d.cur.rev[c]));
return { ...p, value, units: Math.max(1, Math.round(value / p.price)) };
}).sort((a, b) => b.value - a.value).slice(0, 6);
const tasks = [
{ icon: <ClockCircleOutlined />, title: "Đơn chờ xác nhận quá 2 giờ", note: "Lâu nhất 5 giờ 10 phút · 3 đơn website", count: 4, color: token.colorWarning },
{ icon: <CarOutlined />, title: "Đơn giao trễ hẹn", note: "2 đơn showroom · 1 dự án B2B", count: 3, color: token.colorError },
{ icon: <InboxOutlined />, title: "Hàng dưới mức tồn tối thiểu", note: `${STOCK.filter((s) => s.onHand === 0).length} mã đã hết hàng`, count: STOCK.length, color: token.colorWarning },
{ icon: <DollarOutlined />, title: "Công nợ B2B quá hạn", note: `${vnd(sum(DEBTS))} · quá hạn lâu nhất 34 ngày`, count: DEBTS.length, color: token.colorError },
];
const stockCols: TableProps<Stock>["columns"] = [
{ title: "Sản phẩm", dataIndex: "name", render: (_, r) => <Flex vertical><Typography.Link>{r.name}</Typography.Link><Typography.Text type="secondary" style={{ fontSize: 12 }}>{r.sku} · {r.warehouse}</Typography.Text></Flex> },
{ title: "Tình trạng", key: "st", width: 140, render: (_, r) => <Badge status={r.onHand === 0 ? "error" : "warning"} text={r.onHand === 0 ? "Hết hàng" : "Dưới tối thiểu"} /> },
{ title: "Tồn / tối thiểu", key: "qty", align: "right", width: 130, render: (_, r) => <span><b>{r.onHand}</b> / {r.min}</span> },
{ title: "Đủ bán", key: "days", align: "right", width: 100, render: (_, r) => (r.onHand === 0 ? "—" : `${Math.floor(r.onHand / r.perDay)} ngày`) },
{ title: "Hàng đang về", key: "in", width: 150, render: (_, r) => (r.incoming ? `${r.incoming} cái · ngày ${r.eta}` : <Typography.Text type="danger">Chưa đặt hàng</Typography.Text>) },
{ title: "", key: "act", width: 130, align: "right", render: (_, r) => <Button size="small">{r.incoming ? "Xem đơn nhập" : "Tạo đơn nhập"}</Button> },
];
return (
<PageContainer
title="Chào buổi chiều, anh Tuấn"
subTitle={`Nội thất Mộc An · số liệu tính đến ${NOW.format("HH:mm")}, thứ Sáu ${NOW.format("DD/MM/YYYY")}`}
extra={[
<Segmented<Period> key="p" value={period} onChange={setPeriod}
options={[{ label: "Hôm nay", value: "today" }, { label: "7 ngày", value: "7d" }, { label: "Tháng này", value: "month" }, { label: "12 tháng", value: "12m" }]} />,
<Button key="x" icon={<DownloadOutlined />}>Xuất báo cáo</Button>,
]}
>
<Flex vertical gap={16}>
<Row gutter={[16, 16]}>
<Col xs={24} sm={12} xl={6}>
<StatisticCard style={{ height: "100%" }} chart={spark(d.buckets.map((b) => sum(b.rev)))}
statistic={{ title: "Doanh thu", value: rev, formatter: () => <Tooltip title={vnd(rev)}>{short(rev)} ₫</Tooltip>, description: delta(rev / prevRev - 1, pct(Math.abs(rev / prevRev - 1))) }}
footer={<Typography.Text type="secondary">Lợi nhuận gộp {short(gp)} ₫</Typography.Text>} />
</Col>
<Col xs={24} sm={12} xl={6}>
<StatisticCard style={{ height: "100%" }} chart={spark(d.buckets.map((b) => sum(b.orders)))}
statistic={{ title: "Đơn mới", value: orders, formatter: () => nf.format(orders), description: delta(orders / prevOrders - 1, pct(Math.abs(orders / prevOrders - 1))) }}
footer={<Typography.Text type="secondary">Giá trị trung bình {short(rev / Math.max(1, orders))} ₫/đơn</Typography.Text>} />
</Col>
<Col xs={24} sm={12} xl={6}>
<StatisticCard style={{ height: "100%" }} chart={spark(d.buckets.map((b) => sum(b.gp) / Math.max(1, sum(b.rev))))}
statistic={{ title: "Biên lợi nhuận gộp", value: margin, formatter: () => pct(margin), description: delta(margin - prevMargin, `${num(Math.abs(margin - prevMargin) * 100, 1)} điểm %`) }}
footer={<Typography.Text type="secondary">B2B thấp nhất: {pct(d.cur.gp[2] / Math.max(1, d.cur.rev[2]))}</Typography.Text>} />
</Col>
<Col xs={24} sm={12} xl={6}>
<StatisticCard style={{ height: "100%" }}
statistic={{ title: "Đơn đang xử lý", value: open, formatter: () => nf.format(open), description: <Typography.Text type="secondary">trong {nf.format(orders)} đơn của kỳ</Typography.Text> }}
chart={
<Flex vertical gap={8} style={{ paddingTop: 8 }}>
<Flex style={{ height: 10, borderRadius: 5, overflow: "hidden", background: token.colorFillSecondary }}>
{d.status.map((n, i) => <Tooltip key={i} title={`${STATUS_LABELS[i]}: ${n}`}><div style={{ width: `${(n / Math.max(1, open)) * 100}%`, background: stColors[i] }} /></Tooltip>)}
</Flex>
{d.status.map((n, i) => (
<Flex key={i} justify="space-between" style={{ fontSize: 12 }}>
<Badge color={stColors[i]} text={STATUS_LABELS[i]} /><b>{n}</b>
</Flex>
))}
</Flex>
} />
</Col>
</Row>
<Row gutter={[16, 16]}>
<Col xs={24} lg={15}>
<ProCard title="Doanh thu và lợi nhuận gộp" subTitle={`theo ${unit}`} headerBordered style={{ height: "100%" }}>
<Column height={300} data={d.buckets.flatMap((b) => [{ label: b.label, kind: "Doanh thu", value: sum(b.rev) }, { label: b.label, kind: "Lợi nhuận gộp", value: sum(b.gp) }])}
xField="label" yField="value" colorField="kind" group
scale={{ color: { range: [token.colorPrimary, token.colorSuccess] } }}
axis={{ y: { labelFormatter: (v: number) => short(v) } }}
legend={{ color: { position: "top", layout: { justifyContent: "flex-end" } } }}
tooltip={{ items: [{ channel: "y", valueFormatter: (v: number) => vnd(v) }] }} />
</ProCard>
</Col>
<Col xs={24} lg={9}>
<ProCard title="Việc cần xử lý" subTitle="cập nhật lúc 14:30" headerBordered style={{ height: "100%" }} bodyStyle={{ padding: 8 }}>
<Flex vertical>
{tasks.map((t) => (
<a key={t.title} href="#" onClick={(e) => e.preventDefault()}
style={{ display: "flex", alignItems: "center", gap: 12, padding: "12px 12px", borderRadius: token.borderRadius, color: token.colorText, borderBottom: `1px solid ${token.colorSplit}` }}>
<span style={{ color: t.color, fontSize: 18 }}>{t.icon}</span>
<Flex vertical style={{ flex: 1, minWidth: 0 }}>
<Typography.Text strong>{t.title}</Typography.Text>
<Typography.Text type="secondary" style={{ fontSize: 12 }}>{t.note}</Typography.Text>
</Flex>
<Typography.Text strong style={{ fontSize: 20, color: t.color }}>{t.count}</Typography.Text>
<RightOutlined style={{ color: token.colorTextTertiary }} />
</a>
))}
</Flex>
</ProCard>
</Col>
</Row>
<Row gutter={[16, 16]}>
<Col xs={24} lg={10}>
<ProCard title="Doanh thu theo kênh" subTitle={`tổng ${vnd(rev)}`} headerBordered style={{ height: "100%" }}>
<Pie height={220} data={CHANNELS.map((c, i) => ({ type: c.label, value: d.cur.rev[i] }))} angleField="value" colorField="type"
innerRadius={0.66} label={false} legend={false} scale={{ color: { range: chColors } }}
tooltip={{ items: [{ field: "value", valueFormatter: (v: number) => vnd(v) }] }}
annotations={[{ type: "text", style: { text: `${short(rev)} ₫`, x: "50%", y: "50%", textAlign: "center", fontSize: 18, fontWeight: 600 } }]} />
<Flex vertical gap={8}>
{CHANNELS.map((c, i) => (
<Flex key={c.label} justify="space-between" gap={8}>
<Badge color={chColors[i]} text={c.label} />
<Typography.Text type="secondary">{nf.format(d.cur.orders[i])} đơn</Typography.Text>
<span><b>{short(d.cur.rev[i])} ₫</b> <Typography.Text type="secondary">· {pct(d.cur.rev[i] / rev)}</Typography.Text></span>
</Flex>
))}
</Flex>
</ProCard>
</Col>
<Col xs={24} lg={14}>
<ProCard title="Sản phẩm bán chạy" subTitle="theo doanh thu" extra={<a>Xem báo cáo sản phẩm</a>} headerBordered style={{ height: "100%" }}>
<Flex vertical gap={12}>
{top.map((p, i) => (
<Flex key={p.name} align="center" gap={12}>
<Typography.Text strong style={{ width: 20, color: i < 3 ? token.colorPrimary : token.colorTextTertiary }}>{i + 1}</Typography.Text>
<Flex vertical style={{ flex: 1, minWidth: 0 }}>
<Flex justify="space-between" gap={8}>
<Typography.Text ellipsis>{p.name}</Typography.Text>
<Typography.Text strong>{short(p.value)} ₫</Typography.Text>
</Flex>
<Flex align="center" gap={8}>
<Progress percent={(p.value / top[0].value) * 100} showInfo={false} size="small" style={{ flex: 1, margin: 0 }} />
<Typography.Text type="secondary" style={{ fontSize: 12, width: 64, textAlign: "right" }}>{nf.format(p.units)} sp</Typography.Text>
</Flex>
</Flex>
</Flex>
))}
</Flex>
</ProCard>
</Col>
</Row>
<ProCard title="Tồn kho cảnh báo" subTitle={`${STOCK.length} mã dưới mức tồn tối thiểu`} extra={<a>Mở kho hàng</a>} headerBordered bodyStyle={{ paddingTop: 0 }}>
<Table<Stock> rowKey="sku" size="small" columns={stockCols} dataSource={STOCK} pagination={false} scroll={{ x: 760 }} />
</ProCard>
</Flex>
</PageContainer>
);
}
Làm màn hình dashboard điều hành hằng ngày cho chủ chuỗi nội thất bán qua 3 kênh (showroom, website, dự án B2B). Đầu trang có lời chào kèm thời điểm số liệu và bộ chọn kỳ Hôm nay / 7 ngày / Tháng này / 12 tháng; đổi kỳ thì mọi con số đổi theo và so với kỳ trước tương ứng (hôm qua cùng giờ, cùng kỳ tháng trước…). Hàng trên cùng là 4 thẻ KPI có sparkline: doanh thu, đơn mới, biên lợi nhuận gộp (chênh lệch tính bằng điểm %), và đơn đang xử lý với thanh xếp chồng theo trạng thái. Tiếp theo là biểu đồ cột doanh thu và lợi nhuận gộp theo giờ/ngày/tháng, cạnh đó là khung "Việc cần xử lý": mỗi dòng bấm được, có số đếm, gồm đơn chờ xác nhận quá 2 giờ, đơn giao trễ hẹn, hàng dưới mức tồn tối thiểu và công nợ B2B quá hạn. Thêm biểu đồ donut tỷ trọng doanh thu theo kênh (tổng các kênh phải khớp tổng doanh thu), danh sách "Sản phẩm bán chạy" có thanh tiến độ, và bảng tồn kho cảnh báo kèm nút tạo đơn nhập. Tiền định dạng vi-VN, dùng "tr"/"tỷ" trên biểu đồ. Mọi số liệu lấy từ API của app qua useApiClient() (báo cáo tổng hợp theo kỳ, số việc cần xử lý, danh sách hàng sắp hết), không viết cứng dữ liệu.
Dashboard của người duyệt
Người duyệt mở app để biết còn bao nhiêu việc. Vì vậy việc cần làm nằm trên, số liệu nằm dưới.
PageContainer lời chào + số việc đang chờ
└── StatRow 3 con số, mỗi số có dòng phụ
└── Row gutter
├── Col lg={15} ProList: việc cần duyệt
└── Col lg={9} biểu đồ cơ cấuDashboard phân tích
Chủ doanh nghiệp xem xu hướng theo kỳ và so sánh các nhóm.
Row 4 thẻ KPI: số lớn + biểu đồ nhỏ + chỉ số ở chân thẻ
Card có tab doanh số / lượt xem, chọn khoảng thời gian ở tabBarExtraContent
├── Col xl={16} biểu đồ cột
└── Col xl={8} bảng xếp hạng
Row 2 thẻ rộng nửa trang: danh sách top, biểu đồ tròn có SegmentedTrang danh sách
PageContainer → ProTable (ô tìm kiếm, tab có số đếm, nút tạo ở toolBarRender, rowSelection kèm thao tác hàng loạt). Bấm một dòng thì mở trang chi tiết. Bản ghi ít trường thì mở Drawer size={600} chứa ProDescriptions. Xem thêm ở Trang danh sách.
Danh sách dạng thẻ
Danh mục sản phẩm, dự án: ProList grid={{ gutter: 16, column: 3 }} với metas gồm title, subTitle (Tag), avatar, description, content (tiến độ), actions.
Form dài nhiều phần
ProForm bọc toàn bộ nội dung PageContainer
├── ProCard mỗi phần một thẻ, 3 trường một hàng
├── EditableProTable các dòng hàng hoá
└── FooterToolbar nút gửi + danh sách lỗiForm nhiều bước
PageContainer → ProCard → StepsForm: điền thông tin → xác nhận (Descriptions + Alert) → Result status="success". Xem Form.
Trang cài đặt
Hai cột: bên trái Menu mode="inline" rộng 224px liệt kê các phần, bên phải một ProForm layout="vertical" cho phần đang chọn, chỉ có nút lưu.
<Flex gap={24}>
<Menu mode="inline" style={{ width: 224 }} selectedKeys={[section]}
onClick={(e) => setSection(e.key)} items={SECTIONS} />
<ProForm layout="vertical" style={{ flex: 1 }} key={section}
request={() => api.settings.list()}
submitter={{ searchConfig: { submitText: "Lưu" }, resetButtonProps: false }}
onFinish={async (v) => { await api.settings.put(v); message.success("Đã lưu"); return true; }}>
{/* … các trường của phần đang chọn */}
</ProForm>
</Flex>Trang kết quả và lỗi
Result status="success" | "error" | "403" | "404" | "500" kèm một nút chính, ví dụ Về danh sách. Đặt trong PageContainer để người dùng vẫn thấy menu.
Tên cũ cần thay
Ví dụ trên internet thường dùng tên prop cũ. Dùng tên bên phải mũi tên:
Cardcủa antd:bordered→variant;bodyStyle/headStyle→styles={{ body, header }}. RiêngProCardvàStatisticCard2.x vẫn dùngbodyStyle/bordered, nên ở đó giữ tên cũ.Modal/Drawer:visible→open;destroyOnClose→destroyOnHidden(xem lưu ý về xoá dữ liệu cũ của form ở Form);widthcủaDrawer→size.Tabs.TabPane/Menu.Itemviết bằng JSX → propitems.Space direction→orientation,split→separator.Steps direction→orientation,items.description→items.content.Statistic valueStyle→styles.content.Alert message→title.Dropdown.Button/Button.Group→Space.Compact.- Tên prop của pro-components v3 không có ở bản 2.8.10: dùng
renderFormItem(không phảiformItemRender);layout="mix"vẫn đúng.
Cần biết
- Không chép
createStyles, less hayclassName={styles.x}từ ant-design-pro. Dùng token +styleinline,Grid.useBreakpoint()thay cho@media, chuỗi viết thẳng thay chouseIntl,useNavigatethay chohistorycủa umi. - Xếp thẻ thành cột bằng
Row gutter+Col, không dùngProCard guttervì thẻ sẽ thụt vào so với thẻ rộng ở trên và dưới. Listcủa antd không còn được khuyên dùng từ bản 6.4. Lưới thẻ viết mới thì dùngProListhoặcRow/ColchứaProCard.
Bước tiếp theo
- Chọn component theo việc — việc người dùng làm → component cần dùng.
- Dashboard — thẻ KPI và biểu đồ.
- Trang chi tiết — đầu trang, tiến độ duyệt và lịch sử.