多租户层级查询优化

This commit is contained in:
2025-10-09 14:33:15 +08:00
parent da9bf97667
commit 6bfc01d2fc
25 changed files with 581 additions and 309 deletions
+99 -33
View File
@@ -33,7 +33,6 @@ const Welcome: React.FC = () => {
}
};
// 仅当选择了租户后再拉取,避免进入页面出现“空 -> 有”的闪动
useEffect(() => {
if (!tenantId) return;
load();
@@ -43,33 +42,79 @@ const Welcome: React.FC = () => {
const orderStats = stat?.orderStats || {};
const chartStats = stat?.chartStats || {};
const trendData = chartStats?.orderTrend || [];
// 每日趋势:订单数/订单金额(元)/退款订单数/退款金额(元)
const trendData = chartStats?.dailySummary || [];
const distributionData = chartStats?.orderDistribution || [];
const trendColors: Record<string, string> = {
'订单数': '#1668DC',
'订单金额(元)': '#FA8C16',
'退款订单数': '#A0D911',
'退款金额(元)': '#F5222D',
};
const trendConfig: any = {
data: trendData,
xField: 'date',
yField: 'value',
seriesField: 'type',
smooth: true,
height: 300,
height: 320,
legend: { position: 'top' },
tooltip: { shared: true },
color: ({ type }: any) => trendColors[type] || '#5B8FF9',
lineStyle: { lineWidth: 2 },
point: { size: 2, shape: 'circle' },
tooltip: {
shared: true,
customContent: (title: string, items: any[]) => {
if (!items || !items.length) return '';
const rows = items
.map((it) => {
const name = it?.name || it?.data?.type;
const v = it?.data?.value ?? 0;
const isAmount = name && String(name).includes('金额');
const text = isAmount ? `¥${Number(v).toFixed(2)}` : `${Math.round(Number(v))}`;
const color = it?.color || '#333';
return `<div style="display:flex;align-items:center;gap:8px;">
<span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:${color}"></span>
<span>${name}</span>
<span style="margin-left:auto;font-weight:600;">${text}</span>
</div>`;
})
.join('');
return `<div style="padding:8px 8px 4px 8px;min-width:200px;">
<div style="margin-bottom:6px;font-weight:600;">${title}</div>
${rows}
</div>`;
},
},
animation: false,
};
const distributionPalette = [
'#1668DC', '#5AD8A6', '#F6BD16', '#E8684A', '#6DC8EC', '#9270CA', '#FF9D4D', '#269A99', '#FF99C3', '#1D9ED1',
];
const distributionConfig: any = {
data: distributionData,
angleField: 'value',
colorField: 'type',
radius: 0.9,
label: { type: 'outer', content: '{name}\n{percentage}' },
color: distributionPalette,
legend: { position: 'right' },
label: {
type: 'spider',
content: (data: any) => {
const total = (distributionData || []).reduce((s: number, d: any) => s + (Number(d.value) || 0), 0);
const pct = total > 0 ? `${((Number(data.value) / total) * 100).toFixed(1)}%` : '0%';
return `${data.type} ${pct} (${data.value})`;
},
},
animation: false,
};
return (
<div className="page-enter" style={{ padding: 24 }}>
{/* 顶部工具区:左标题,右侧筛选/粒度/刷新 */}
{/* 顶部工具区 */}
<Card className="modern-card" style={{ marginBottom: 16 }}>
<Row align="middle" justify="space-between" gutter={[12, 12]}>
<Col flex="none">
@@ -96,14 +141,14 @@ const Welcome: React.FC = () => {
</Row>
</Card>
{/* KPI 指标卡:两列均分,内容居中,不留空白 */}
{/* 第一行:总订单概览 / 收入总览(两侧对称,各3项) */}
<Row gutter={[16, 16]}>
<Col xs={24} md={12}>
<Card loading={pageLoading}>
<Card loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Space align="center" size={8}>
<ShoppingCartOutlined />
<Text strong>订单</Text>
<Text strong>总订单概览</Text>
</Space>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">总订单数</Text></Col>
@@ -118,35 +163,29 @@ const Welcome: React.FC = () => {
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">今日订单</Text></Col>
<Col xs={12} sm={10} md={10}><Text type="secondary">净订单数</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={orderStats.todayOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">今日退款</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={orderStats.todayRefundedOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
<Statistic value={(orderStats.totalOrders || 0) - (orderStats.refundedOrders || 0)} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
</Space>
</Card>
</Col>
<Col xs={24} md={12}>
<Card loading={pageLoading}>
<Card loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Space align="center" size={8}>
<PayCircleOutlined />
<Text strong>收入</Text>
<Text strong>收入总览</Text>
</Space>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">订单总金额(元)</Text></Col>
<Col xs={12} sm={10} md={10}><Text type="secondary">订单总金额</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={(orderStats.totalAmount || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">退款金额(元)</Text></Col>
<Col xs={12} sm={10} md={10}><Text type="secondary">退款订单总金额</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={(orderStats.refundAmount || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
@@ -157,32 +196,59 @@ const Welcome: React.FC = () => {
<Statistic value={(orderStats.netIncome || 0) / 100} precision={2} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">净订单数(笔)</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={(orderStats.totalOrders || 0) - (orderStats.refundedOrders || 0)} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
</Space>
</Card>
</Col>
</Row>
{/* 图表区:趋势 + 状态分布 */}
{/* 第二行:今日统计 / 状态分布(两侧对称) */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col xs={24} md={16}>
<Card title="订单趋势(创建/完成/退款)" loading={pageLoading}>
<Line {...trendConfig} />
<Col xs={24} md={12}>
<Card loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Space align="center" size={8}>
<PayCircleOutlined />
<Text strong>今日统计</Text>
</Space>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">今日订单数</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={orderStats.todayOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">今日退款订单数</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={orderStats.todayRefundedOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
<Row gutter={8} align="middle" style={{ width: '100%' }}>
<Col xs={12} sm={10} md={10}><Text type="secondary">今日收款订单数</Text></Col>
<Col xs={12} sm={14} md={14} style={{ textAlign: 'right' }}>
<Statistic value={orderStats.todayPaidOrders || 0} valueStyle={{ fontWeight: 600, whiteSpace: 'nowrap' }} groupSeparator="," />
</Col>
</Row>
</Space>
</Card>
</Col>
<Col xs={24} md={8}>
<Card title="订单状态分布" loading={pageLoading}>
<Col xs={24} md={12}>
<Card title="订单状态分布" loading={pageLoading} style={{ height: '100%' }}>
<Pie {...distributionConfig} />
</Card>
</Col>
</Row>
{/* 第三行:每日趋势(满宽) */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col span={24}>
<Card title="每日趋势:订单数 / 订单金额 / 退款" loading={pageLoading}>
<Line {...trendConfig} />
</Card>
</Col>
</Row>
</div>
);
};
export default Welcome;