1:首页优化 2:首页适配手机

This commit is contained in:
2025-10-14 16:27:25 +08:00
parent f6b02a9bd9
commit ba366587f4
6 changed files with 54 additions and 29 deletions
+26 -19
View File
@@ -1,5 +1,5 @@
import React, { useEffect, useRef, useState } from 'react';
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic } from 'antd';
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic, Grid } from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import { Line, Pie } from '@ant-design/plots';
import TenantScopeFilter from '@/components/TenantScopeFilter';
@@ -22,7 +22,7 @@ const computeRangeByType = (type: RangeType, anchor?: Moment): [Moment, Moment]
const STATUS_OPTIONS: { value: number; label: string; color?: string }[] = [
{ value: 0, label: '待支付' },
{ value: 1, label: '排队中', color: 'gold' },
{ value: 2, label: '已取消', color: 'red' },
{ value: 2, label: '已取号', color: 'red' },
{ value: 3, label: '设备执行完成', color: 'green' },
{ value: 4, label: '正在服务', color: 'blue' },
{ value: 5, label: '素材上传', color: 'geekblue' },
@@ -63,8 +63,9 @@ const Welcome: React.FC = () => {
const handleRangeTypeChange = (val: any) => {
const t = (val as RangeType) || 'date';
setRangeType(t);
const anchor = range?.[0] || moment();
setRange(computeRangeByType(t, anchor));
// 切换粒度时,以“当前时间”为锚点,确保切回日/周/月回到“当前日/当前周/当前月”
const anchorNow = moment();
setRange(computeRangeByType(t, anchorNow));
};
const handleRangeChange = (vals: any) => {
@@ -86,7 +87,7 @@ const Welcome: React.FC = () => {
setLoading(true);
try {
const { startTime, endTime } = getTimeParams();
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day'|'month'|'year';
const statType = (rangeType === 'month' ? 'month' : (rangeType === 'year' ? 'year' : 'day')) as 'day' | 'month' | 'year';
const res: any = await dashboardApi.statistics({ tenantId, includeChildren, startTime, endTime, statType, includeTestQrcodes: false });
setStat(res?.data || res);
@@ -108,7 +109,6 @@ const Welcome: React.FC = () => {
setOrdersLoading(false);
}
// 刷新折线(刷新按钮也会触发到这里)
try { await loadAggregations(); } catch {}
} catch (e) {
message.error('加载统计失败');
@@ -144,14 +144,14 @@ const Welcome: React.FC = () => {
const seriesRes: any = await ordersApi.getOrderSeries({ tenantId, includeChildren, startTime, endTime, statType: rangeType, includeTestQrcodes: false });
const seriesData: any[] = seriesRes?.data || [];
// 构建数据映射表
// 构建数据映射
const dataMap: Record<string, Record<string, number>> = {
'订单创建': {},
'完成': {},
'退款': {}
};
// 将后端数据填充到映射表
// 将后端数据填充到映射
seriesData.forEach((item: any) => {
const date = item.date || '';
const type = item.type || '';
@@ -161,7 +161,7 @@ const Welcome: React.FC = () => {
}
});
// 填充所有时间点,缺失的补0
// 填充所有时间点,缺失的补 0
const lineSeries: { date: string; value: number; type: string }[] = [];
labels.forEach((label) => {
lineSeries.push({ date: label, type: '订单创建', value: dataMap['订单创建'][label] || 0 });
@@ -187,17 +187,18 @@ const Welcome: React.FC = () => {
return colorMapping[type] || '#1890ff';
};
const screens = Grid.useBreakpoint();
const isMobile = !screens.md; // 小于 md 视为移动端
const orderLineConfig: any = {
data: orderLineSeries,
xField: 'date',
yField: 'value',
seriesField: 'type',
smooth: true,
height: 220,
legend: { position: 'top' as const },
color: (datum: any) => {
return getColorByType(datum.type);
},
autoFit: true,
height: isMobile ? 180 : 220,
legend: { position: 'top' },
color: (datum: any) => getColorByType(datum.type),
};
// 饼图配置
@@ -211,7 +212,7 @@ const Welcome: React.FC = () => {
colorField: 'type',
radius: 0.9,
color: distributionPalette,
legend: { position: 'right' },
legend: { position: (isMobile ? 'bottom' : 'right') as 'top' | 'right' | 'bottom' | 'left' },
label: false,
animation: false,
};
@@ -230,16 +231,18 @@ const Welcome: React.FC = () => {
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"><Title level={4} style={{ margin: 0 }}>首页统计</Title></Col>
<Col flex="auto">
<Space style={{ width: '100%', justifyContent: 'flex-end', flexWrap: 'wrap' }} size={12}>
<Space direction={isMobile ? 'vertical' : 'horizontal'} style={{ width: '100%', justifyContent: 'flex-end', flexWrap: 'wrap' }} size={12}>
<TenantScopeFilter autoApply onChanged={(tid, inc) => { setTenantId(tid); setIncludeChildren(!!inc); }} />
<Space>
<Space direction={isMobile ? 'vertical' : 'horizontal'} wrap>
<span>统计时间</span>
<Segmented
block={isMobile}
size={isMobile ? 'small' : 'middle'}
options={[{ label: '日', value: 'date' }, { label: '周', value: 'week' }, { label: '月', value: 'month' }, { label: '年', value: 'year' }]}
value={rangeType}
onChange={handleRangeTypeChange}
@@ -250,8 +253,12 @@ const Welcome: React.FC = () => {
value={range as any}
picker={rangeType as any}
onChange={handleRangeChange}
size={isMobile ? 'small' : 'middle'}
getPopupContainer={(trigger: any) => (trigger?.parentElement || document.body)}
placement={isMobile ? 'bottomLeft' : 'bottomRight'}
style={{ width: isMobile ? '100%' : undefined, minWidth: isMobile ? 220 : undefined }}
/>
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} onClick={() => { load(); }}>刷新</Button>
<Button type="primary" icon={<ReloadOutlined />} loading={loading && !pageLoading} size={isMobile ? 'small' : 'middle'} onClick={() => { load(); }}>刷新</Button>
</Space>
</Space>
</Col>