Dashboard
Dashboard cho người dùng ở mỗi vai trò thấy ngay việc cần làm và vài con số chính. Dựng trang bằng StatRow, ProCard, ProList và biểu đồ của @ant-design/charts.
Đây là trang đầu tiên sau khi đăng nhập. Người duyệt cần biết còn bao nhiêu đề xuất chờ mình và cái nào sắp tới hạn. Nhân viên cần biết đề xuất của mình đang ở bước nào. Mỗi con số có một dòng phụ, còn danh sách việc cần làm là phần chính của trang.
// Dashboard người duyệt: StatisticCard.Group (mỗi số có dòng phụ) + danh sách việc cần làm (Listy) + biểu đồ donut.
import { PageContainer, ProCard, StatisticCard } from "@ant-design/pro-components";
import { Avatar, Button, Col, Flex, Grid, Listy, Row, Space, Typography, theme } from "antd";
import { ClockCircleOutlined, RightOutlined } from "@ant-design/icons";
import { Pie } from "@ant-design/charts";
/** Mock people get a face (manh.run avatars 01–24), the same one for the same name. */
const face = (name: string) => {
let h = 0;
for (const ch of name) h = (h * 31 + ch.charCodeAt(0)) >>> 0;
return `https://manh.run/avatars/${String((h % 24) + 1).padStart(2, "0")}.svg`;
};
const { Statistic } = StatisticCard;
const vnd = (n: number) => `${n.toLocaleString("vi-VN")} ₫`;
const todo = [
{ id: 10, title: "Sửa điều hoà phòng họp tầng 3", who: "Trần Thị Lan · Hành chính", due: "08/11 · quá hạn", late: true, amount: 1500000 },
{ id: 9, title: "Gia hạn Microsoft 365 (12 tháng)", who: "Trần Thị Lan · Hành chính", due: "13/11", late: false, amount: 18600000 },
{ id: 8, title: "2 màn hình Dell P2423", who: "Lê Văn Minh · Kỹ thuật", due: "15/11", late: false, amount: 7800000 },
];
export default function Page() {
const { token } = theme.useToken();
const md = Grid.useBreakpoint().md;
return (
<PageContainer title="Chào buổi chiều, Nguyễn Thu Hà" subTitle="3 đề xuất đang chờ bạn duyệt"
extra={<Button type="primary">Mở hộp duyệt <RightOutlined /></Button>}>
{/* Cards share one left/right edge: Flex for the vertical rhythm, Row/Col for columns (not ProCard gutter). */}
<Flex vertical gap={16}>
<StatisticCard.Group direction={md ? "row" : "column"}>
<StatisticCard statistic={{ title: "Đang chờ duyệt", value: 3, description: <Statistic title="Giá trị" value={vnd(27900000)} /> }} />
<StatisticCard.Divider type={md ? "vertical" : "horizontal"} />
<StatisticCard statistic={{ title: "Đã duyệt tháng này", value: 12090000, formatter: (v) => vnd(Number(v)), description: <Statistic title="So với tháng trước" value="tăng 12%" /> }} />
<StatisticCard.Divider type={md ? "vertical" : "horizontal"} />
<StatisticCard statistic={{ title: "Từ chối tháng này", value: 1, description: <Statistic title="Tổng đề xuất" value={8} /> }} />
</StatisticCard.Group>
<Row gutter={[16, 16]}>
<Col xs={24} lg={15}>
<ProCard title="Cần tôi duyệt" subTitle="gần hạn trước" extra={<a>Xem tất cả</a>} headerBordered style={{ height: "100%" }}>
<Listy
rowKey="id"
items={todo}
rowHoverable={false}
itemRender={(r) => (
<div className="flex items-start gap-3">
<Avatar className="shrink-0" src={face(r.who)} alt={r.who} />
<div className="min-w-0 flex-1">
<div className="font-medium">{r.title}</div>
<Space size={12} className="text-fg-secondary"><span>{r.who}</span><Typography.Text type={r.late ? "danger" : "secondary"}><ClockCircleOutlined /> {r.due}</Typography.Text></Space>
</div>
<b className="shrink-0">{vnd(r.amount)}</b>
</div>
)}
/>
</ProCard>
</Col>
<Col xs={24} lg={9}>
<ProCard title="Đã duyệt tháng này" subTitle="theo hạng mục" headerBordered style={{ height: "100%" }}>
<Pie
height={260}
data={[{ type: "Thiết bị", value: 4990000 }, { type: "Văn phòng phẩm", value: 2400000 }, { type: "Dịch vụ", value: 4700000 }]}
angleField="value"
colorField="type"
innerRadius={0.62}
label={false}
legend={{ color: { position: "bottom", layout: { justifyContent: "center" } } }}
tooltip={{ items: [{ field: "value", valueFormatter: (v: number) => vnd(v) }] }}
/>
</ProCard>
</Col>
</Row>
</Flex>
</PageContainer>
);
}
Làm màn hình "Dashboard" cho app của tôi theo mẫu manh.run UI playbook (framework_docs("pro")): Dashboard người duyệt: StatisticCard.Group (mỗi số có dòng phụ) + danh sách việc cần làm (Listy) + biểu đồ donut. Dữ liệu lấy từ API của app qua useApiClient(); nhãn và trường theo spec của tôi.Bố cục trang
Trang gồm các khối xếp dọc, thẳng hàng ở mép trái và mép phải:
PageContainer lời chào · số việc chờ · một nút chính
└── Flex vertical gap={16}
├── StatRow 3–4 số KPI, mỗi số một dòng phụ
└── Row gutter={[16, 16]}
├── Col lg={15} ProCard "Cần tôi duyệt" → ProList
└── Col lg={9} ProCard "Theo hạng mục" → PieĐầu trang cho biết việc cần làm
title là lời chào, subTitle là số việc đang chờ, extra là một nút dẫn tới việc đó.
<PageContainer
title={`Chào buổi sáng, ${user.name}`}
subTitle={manager ? `${s?.pending ?? "…"} đề xuất đang chờ bạn duyệt` : "Đề xuất mua sắm của bạn"}
extra={<Button type="primary" onClick={() => nav("/requests")}>Mở hộp duyệt</Button>}
>
{/* … */}
</PageContainer>Hàng KPI có dòng phụ
StatRow từ manh/shell hiện mỗi con số một ô, bốn ô một hàng trên máy tính và 2 × 2 trên điện thoại. description là dòng phụ: so với kỳ trước, giá trị tiền hoặc số lượng. Con số đứng một mình trông như trang chưa làm xong.
<StatRow loading={!s} items={[
{ title: "Đang chờ duyệt", value: s?.pending ?? 0, status: "processing",
description: `Giá trị ${vndShort(s?.pendingAmount ?? 0)}`, onClick: () => nav("/requests") },
{ title: "Đã duyệt tháng này", value: vndShort(cur),
description: "Tăng 12% so với tháng trước", chart: <Tiny.Area height={46} data={series} /> },
]} />- Tối đa 3–4 số. Nhiều hơn thì người xem không biết nên nhìn vào đâu.
onClickđưa người xem tới danh sách đứng sau con số đó. Mụcfalsehaynullđược bỏ qua, tiện cho số chỉ một vai trò được thấy.
Việc cần làm và biểu đồ cạnh nhau
Chia cột bằng Row gutter + Col để thẻ thẳng mép với hàng KPI phía trên. Danh sách việc xếp theo hạn, việc gần hạn nhất lên đầu, mục quá hạn tô màu danger.
<Row gutter={[16, 16]}>
<Col xs={24} lg={15}>
<ProCard title="Cần tôi duyệt" subTitle="gần hạn trước" headerBordered
extra={<a onClick={() => nav("/requests")}>Xem tất cả</a>} style={{ height: "100%" }}>
<ProList<Request> rowKey="id" split dataSource={rows}
onItem={(r) => ({ onClick: () => nav(`/requests/${r.id}`) })}
locale={{ emptyText: <Empty description="Không còn đề xuất nào chờ duyệt." /> }}
metas={{
avatar: { render: (_, r) => <Avatar>{r.creatorName?.[0]}</Avatar> },
title: { dataIndex: "title" },
description: { render: (_, r) => <Space>{r.creatorName}<span>{CATEGORY[r.category]}</span><Due r={r} /></Space> },
actions: { render: (_, r) => [<b key="amt">{vnd(r.amount)}</b>] },
}} />
</ProCard>
</Col>
<Col xs={24} lg={9}>
<ProCard title="Theo hạng mục" headerBordered style={{ height: "100%" }}>
<Pie data={byCategory} angleField="value" colorField="type" innerRadius={0.62} label={false} height={280}
tooltip={{ items: [{ field: "value", valueFormatter: (v: number) => vnd(v) }] }} />
</ProCard>
</Col>
</Row>Chọn biểu đồ theo điều cần xem
- Xu hướng theo thời gian →
Line/Area. - So sánh nhóm →
Column/Bar. - Tỷ trọng, tối đa 6 phần →
PiecóinnerRadius. - Mục tiêu so với thực tế →
Progress/Gauge/Liquid. - Hai đại lượng, hai thang →
DualAxes. - Số nhỏ trong thẻ KPI →
Tiny.Area,Tiny.Column.
Đặt mỗi biểu đồ trong một ProCard có tiêu đề, ghi đơn vị trong tooltip hoặc nhãn trục.
Cần biết
trend="up"tô đỏ,"down"tô xanh (quy ước thị trường Trung Quốc). App cho người Việt nên ghi bằng chữ (“tăng 12%”) hoặc tự tô màu bằng token.- Không dùng
ProCard gutterđể chia cột vì thẻ sẽ thụt vào khoảng 8px so với hàng KPI. - Đặt
heightvàautoFitcho mọi biểu đồ để biểu đồ vừa với thẻ.
Biến thể
Dashboard điều hành. Đổi kỳ là mọi con số đổi theo. Trang có biểu đồ doanh thu và lợi nhuận, tỷ trọng kênh bán, sản phẩm bán chạy và hàng tồn cần chú ý.
// 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.
Bước tiếp theo
- Khung app và đầu trang —
PageContainercho lời chào và nút chính. - Trang danh sách — nút Xem tất cả mở trang này.
- Công thức trang — bố cục dashboard người duyệt và dashboard phân tích.