feat: 修改首页,添加景区订单列表统计

This commit is contained in:
2025-10-21 19:05:26 +08:00
parent 57ce4301fa
commit 37d15d17ef
3 changed files with 97 additions and 67 deletions
+93 -63
View File
@@ -147,7 +147,7 @@ const Welcome: React.FC = () => {
if (rangeType === 'date') {
unit = 'hour';
fmtLabel = (m: moment.Moment) => m.format('HH:00');
apiStatType = 'hour';
apiStatType = 'date';
} else {
// 月、年、周都按天显示
unit = 'day';
@@ -194,9 +194,15 @@ const Welcome: React.FC = () => {
dataMap[type][date] = value;
});
// 获取接口返回的实际数据范围
const actualDates = [...new Set(seriesData.map((item: any) => item.date))].sort();
// 如果没有数据,使用生成的labels;否则使用实际数据范围
const effectiveLabels = actualDates.length > 0 ? actualDates : labels;
// 填充所有时间点,缺失的补 0
const lineSeries: { date: string; value: number; type: string }[] = [];
labels.forEach((label) => {
effectiveLabels.forEach((label) => {
targetTypes.forEach((type) => {
lineSeries.push({
date: label,
@@ -337,6 +343,11 @@ const Welcome: React.FC = () => {
const platformAmountYuan = Number(((netIncomeYuan * platformSharePercent) / 100).toFixed(2));
const scenicAmountYuan = Number((netIncomeYuan - platformAmountYuan).toFixed(2));
const axisLeft = 40;
const axisTop = 40;
const axisBottom = 370;
const axisRight = 1850;
// 首次加载/筛选变化
useEffect(() => {
if (!tenantId) return;
@@ -388,9 +399,9 @@ const Welcome: React.FC = () => {
</Row>
</Card>
{/* 概览卡片:左侧订单数统计 + 右侧金额统计 */}
{/* 概览卡片:总订单 / 金额 / 分账 */}
<Row gutter={[16, 16]}>
<Col xs={24} md={12}>
<Col xs={24} lg={8} xl={8}>
<Card loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Text strong>总订单概览</Text>
@@ -415,7 +426,7 @@ const Welcome: React.FC = () => {
</Space>
</Card>
</Col>
<Col xs={24} md={12}>
<Col xs={24} lg={8} xl={8}>
<Card loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Text strong>金额统计</Text>
@@ -441,12 +452,8 @@ const Welcome: React.FC = () => {
</Space>
</Card>
</Col>
</Row>
{/* 分账计算 + 景区订单数量统计 */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col xs={24} lg={12}>
<Card className="modern-card">
<Col xs={24} lg={8} xl={8}>
<Card className="modern-card" loading={pageLoading} style={{ height: '100%' }}>
<Space direction="vertical" style={{ width: '100%' }} size={12}>
<Row align="middle" justify="space-between" gutter={[8, 8]}>
<Col flex="none"><Text strong>分账计算</Text></Col>
@@ -495,11 +502,6 @@ const Welcome: React.FC = () => {
</Space>
</Card>
</Col>
<Col xs={24} lg={12}>
<Card title="景区订单数量统计" loading={pageLoading} style={{ height: '100%' }}>
<Column {...scenicOrderConfig} />
</Card>
</Col>
</Row>
{/* 订单趋势 - 单独一列 */}
@@ -509,33 +511,33 @@ const Welcome: React.FC = () => {
<div
style={{
width: '100%',
height: rangeType === 'year' ? 600 : 500,
height: 450,
padding: '10px 0',
position: 'relative'
}}
onMouseLeave={() => setTooltipData(null)}
>
<svg width="100%" height="100%" viewBox={`0 0 ${rangeType === 'year' ? 1200 : 1100} ${rangeType === 'year' ? 600 : 500}`}>
<svg width="100%" height="100%" viewBox={`0 0 1900 450`}>
{/* 绘制坐标轴 */}
<line
x1="60"
y1={rangeType === 'year' ? 520 : 430}
x2={rangeType === 'year' ? 1150 : 1050}
y2={rangeType === 'year' ? 520 : 430}
x1={axisLeft}
y1={axisBottom}
x2={axisRight}
y2={axisBottom}
stroke="#e8e8e8"
strokeWidth="1"
/>
<line
x1="60"
y1="40"
x2="60"
y2={rangeType === 'year' ? 520 : 430}
x1={axisLeft}
y1={axisTop}
x2={axisLeft}
y2={axisBottom}
stroke="#e8e8e8"
strokeWidth="1"
/>
{/* 图例 */}
<g transform="translate(60, 10)">
<g transform={`translate(${axisLeft}, 10)`}>
<circle cx="0" cy="5" r="4" fill="#1677FF"/>
<text x="10" y="8" fontSize="12" fill="#666">订单创建</text>
@@ -550,8 +552,8 @@ const Welcome: React.FC = () => {
{(() => {
const allDates = [...new Set(orderLineSeries.map(item => item.date))].sort();
const maxValue = Math.max(...orderLineSeries.map(item => item.value), 1);
const chartRight = rangeType === 'year' ? 1150 : 1050;
const xStep = (chartRight - 60) / Math.max(allDates.length - 1, 1);
const chartRight = axisRight;
const xStep = (chartRight - axisLeft) / Math.max(allDates.length - 1, 1);
// Y轴刻度和标签
const ySteps = 5;
@@ -562,24 +564,24 @@ const Welcome: React.FC = () => {
{/* Y轴刻度和标签 */}
{Array.from({ length: ySteps + 1 }, (_, i) => {
const value = i * yStepValue;
const chartBottom = rangeType === 'year' ? 520 : 430;
const chartTop = 40;
const chartBottom = axisBottom;
const chartTop = axisTop;
const chartHeight = chartBottom - chartTop;
const y = chartBottom - (value / maxValue) * chartHeight;
return (
<g key={i}>
<line
x1="55" y1={y} x2="60" y2={y}
x1={axisLeft - 5} y1={y} x2={axisLeft} y2={y}
stroke="#e8e8e8" strokeWidth="1"
/>
<text
x="45" y={y + 4}
x={axisLeft - 15} y={y + 4}
fontSize="10" fill="#666" textAnchor="end"
>
{value}
</text>
<line
x1="60" y1={y} x2={chartRight - 50} y2={y}
x1={axisLeft} y1={y} x2={chartRight - 50} y2={y}
stroke="#f0f0f0" strokeWidth="1" strokeDasharray="3,3"
/>
</g>
@@ -591,9 +593,9 @@ const Welcome: React.FC = () => {
// 根据日期数量和时间范围计算显示策略
let maxLabels = 12;
if (rangeType === 'year') {
maxLabels = 20; // 年视图时可以显示更多标签,因为有更宽的空间
maxLabels = 24; // 年视图显示月份标记,每月1-2个标签
} else if (rangeType === 'month') {
maxLabels = 15;
maxLabels = Math.min(allDates.length, 31);
} else if (rangeType === 'week') {
maxLabels = 10;
}
@@ -602,13 +604,26 @@ const Welcome: React.FC = () => {
return allDates.map((date, index) => {
// 判断是否显示此标签
const shouldShow = index === 0 ||
index === allDates.length - 1 ||
index % labelInterval === 0;
let shouldShow = index === 0 || index === allDates.length - 1;
// 年视图特殊处理:优先显示每月1日或15日
if (rangeType === 'year') {
if (date.includes('-')) {
const parts = date.split('-');
if (parts.length >= 3) {
const day = parseInt(parts[2]);
// 显示每月1日,或者每月中间的某个日期
shouldShow = shouldShow || day === 1 || day === 15;
}
}
} else {
// 其他视图按间隔显示
shouldShow = shouldShow || index % labelInterval === 0;
}
if (!shouldShow) return null;
const x = 60 + index * xStep;
const x = axisLeft + index * xStep;
// 智能格式化日期显示
let displayText = date;
@@ -621,16 +636,22 @@ const Welcome: React.FC = () => {
const parts = date.split('-');
if (parts.length >= 3) {
if (rangeType === 'year') {
displayText = `${parts[1]}-${parts[2]}`; // 月-日
} else if (rangeType === 'month') {
displayText = `${parts[1]}-${parts[2]}`; // 月-日
} else {
displayText = `${parts[1]}-${parts[2]}`; // 月-日
}
const day = parseInt(parts[2]);
// 年视图:每月1日显示"月月",其他日期显示"月-日"
if (day === 1) {
displayText = `${parseInt(parts[1])}月`;
} else {
displayText = `${parts[1]}-${parts[2]}`;
}
} else if (rangeType === 'month') {
displayText = `${parts[1]}-${parts[2]}`; // 月-日
} else {
displayText = `${parts[1]}-${parts[2]}`; // 月-日
}
}
}
const chartBottom = rangeType === 'year' ? 520 : 430;
const chartBottom = axisBottom;
return (
<g key={index}>
<text
@@ -657,10 +678,10 @@ const Welcome: React.FC = () => {
return datesWithData.map((date, dateIndex) => {
const actualDateIndex = allDates.indexOf(date);
const x = 60 + actualDateIndex * xStep;
const x = axisLeft + actualDateIndex * xStep;
const chartBottom = rangeType === 'year' ? 520 : 430;
const chartTop = 40;
const chartBottom = axisBottom;
const chartTop = axisTop;
const chartHeight = chartBottom - chartTop;
return (
<rect
@@ -673,8 +694,8 @@ const Welcome: React.FC = () => {
style={{ cursor: 'pointer' }}
onMouseEnter={(e: any) => {
const svgRect = e.currentTarget.closest('svg').getBoundingClientRect();
const svgWidth = rangeType === 'year' ? 1200 : 1100;
const svgHeight = rangeType === 'year' ? 600 : 500;
const svgWidth = 1900;
const svgHeight = 450;
const tooltipX = (e.clientX - svgRect.left) * (svgWidth / svgRect.width);
const tooltipY = (e.clientY - svgRect.top) * (svgHeight / svgRect.height);
@@ -683,7 +704,7 @@ const Welcome: React.FC = () => {
if (allDataForDate.length > 0) {
const contentLines = allDataForDate.map(item => {
const colorMap = {
const colorMap: Record<string, string> = {
'订单创建': '#1677FF',
'订单完成': '#52C41A',
'退款': '#FF4D4F'
@@ -753,11 +774,11 @@ const Welcome: React.FC = () => {
const pathData = (() => {
if (filledData.length === 0) return '';
const chartBottom = rangeType === 'year' ? 520 : 430;
const chartTop = 40;
const chartBottom = axisBottom;
const chartTop = axisTop;
const chartHeight = chartBottom - chartTop;
const points = filledData.map((item, index) => {
const x = 60 + index * xStep;
const x = axisLeft + index * xStep;
const y = chartBottom - (item.value / maxValue) * chartHeight;
return { x, y };
});
@@ -820,9 +841,9 @@ const Welcome: React.FC = () => {
if (item.value <= 0) return null;
const dateIndex = allDates.indexOf(item.date);
const x = 60 + dateIndex * xStep;
const chartBottom = rangeType === 'year' ? 520 : 430;
const chartTop = 40;
const x = axisLeft + dateIndex * xStep;
const chartBottom = axisBottom;
const chartTop = axisTop;
const chartHeight = chartBottom - chartTop;
const y = chartBottom - (item.value / maxValue) * chartHeight;
return (
@@ -851,9 +872,9 @@ const Welcome: React.FC = () => {
{tooltipData && (
<line
x1={tooltipData.lineX}
y1="40"
y1={axisTop}
x2={tooltipData.lineX}
y2={rangeType === 'year' ? 520 : 430}
y2={axisBottom}
stroke="#999"
strokeWidth="1"
strokeDasharray="5,5"
@@ -867,8 +888,8 @@ const Welcome: React.FC = () => {
<div
style={{
position: 'absolute',
left: `${(tooltipData.x / (rangeType === 'year' ? 1200 : 1100)) * 100}%`,
top: `${(tooltipData.y / (rangeType === 'year' ? 600 : 500)) * 100}%`,
left: `${(tooltipData.x / 1900) * 100}%`,
top: `${(tooltipData.y / 450) * 100}%`,
transform: 'translate(-50%, 0)',
backgroundColor: 'rgba(0, 0, 0, 0.8)',
color: '#fff',
@@ -888,6 +909,15 @@ const Welcome: React.FC = () => {
</Col>
</Row>
{/* 景区订单数量统计:单行展示 */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col xs={24}>
<Card title="景区订单数量统计" loading={pageLoading} style={{ height: '100%' }}>
<Column {...scenicOrderConfig} />
</Card>
</Col>
</Row>
{/* 订单状态分布 + 订单列表 */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col xs={24} md={12}>