feat:修改首页景区数量统计

This commit is contained in:
2026-04-20 14:55:49 +08:00
parent f2663b8181
commit 3a23adbf7c
2 changed files with 43 additions and 38 deletions
+3 -1
View File
@@ -20,4 +20,6 @@ zlt-web/yingyan/public/cesium/
# 忽略 dist 目录(所有层级) # 忽略 dist 目录(所有层级)
dist/ dist/
# 忽略 dist.zip 文件 # 忽略 dist.zip 文件
dist.zip zlt-web/react-web-next/dist.zip
zlt-web/yingyan/dist.zip
+40 -37
View File
@@ -1,4 +1,4 @@
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState, useMemo } from 'react';
import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic, Grid, Slider, InputNumber, Tooltip } from 'antd'; import { Card, Space, Typography, Row, Col, Button, message, DatePicker, Segmented, List, Tag, Statistic, Grid, Slider, InputNumber, Tooltip } from 'antd';
import { ReloadOutlined } from '@ant-design/icons'; import { ReloadOutlined } from '@ant-design/icons';
import { Line, Pie, Bar } from '@ant-design/plots'; import { Line, Pie, Bar } from '@ant-design/plots';
@@ -270,23 +270,20 @@ const Welcome: React.FC = () => {
// 计算总订单数用于百分比显示 // 计算总订单数用于百分比显示
const totalScenicOrders = scenicOrderData.reduce((sum, item) => sum + item.orderCount, 0); const totalScenicOrders = scenicOrderData.reduce((sum, item) => sum + item.orderCount, 0);
// 最多同时可见 5 条,通过容器滚动查看全部 // 每个条形的高度,容器固定高度显示8条,超出滚动
const MAX_SCENIC_BARS = 6; const MAX_VISIBLE_BARS = 8;
const ROW_HEIGHT = 35; const BAR_HEIGHT = 50; // 每个条形的高度
const chartFullHeight = Math.max(((Array.isArray(scenicOrderData) ? scenicOrderData.length : 0) * ROW_HEIGHT), MAX_SCENIC_BARS * ROW_HEIGHT); const chartFullHeight = Math.max((Array.isArray(scenicOrderData) ? scenicOrderData.length : 0) * BAR_HEIGHT, 400);
const containerHeight = MAX_VISIBLE_BARS * BAR_HEIGHT; // 固定容器高度400px
// 景区订单数量横向条形图配置 - 景区名称在Y轴(左侧),订单数量横向展示 // 景区订单数量横向条形图配置 - 景区名称在Y轴(左侧),订单数量横向展示
const scenicOrderConfig: any = { const scenicOrderConfig: any = useMemo(() => ({
data: scenicOrderData, data: scenicOrderData,
xField: 'tourismName', // 这里反直觉:xField是分类(显示为Y轴) xField: 'orderCount', // 横向数值轴
yField: 'orderCount', // yField是数值(显示为横向长度) yField: 'tourismName', // 纵向分类轴(景区名称)
autoFit: true, autoFit: false, // 关闭自动适应,使用固定高度
height: chartFullHeight, height: chartFullHeight,
// 关键:转置坐标系,使横向条形图 // 使用渐变色,根据数值大小
coordinate: {
transpose: true,
},
// 使用绿色渐变,根据数值大小
color: ({ orderCount }: any) => { color: ({ orderCount }: any) => {
const maxCount = Math.max(...scenicOrderData.map(d => d.orderCount), 1); const maxCount = Math.max(...scenicOrderData.map(d => d.orderCount), 1);
const ratio = orderCount / maxCount; const ratio = orderCount / maxCount;
@@ -297,64 +294,57 @@ const Welcome: React.FC = () => {
return '#B7EB8F'; // 很浅绿 return '#B7EB8F'; // 很浅绿
}, },
label: { label: {
position: 'right', // 标签显示在条形右侧外部 position: 'right',
offset: 8, offset: 10,
content: (item: any) => { content: (item: any) => {
// 订单数为0时不显示标签,避免与景区名称重叠
if (item.orderCount === 0) return ''; if (item.orderCount === 0) return '';
return `${item.orderCount}单`; return `${item.orderCount}单`;
}, },
style: { style: {
fill: '#666', fill: '#595959',
fontSize: 12, fontSize: 13,
fontWeight: 500, fontWeight: 600,
textAlign: 'left',
}, },
}, },
xAxis: { xAxis: {
title: {
text: '订单数量',
style: {
fontSize: 14,
fontWeight: 500,
},
},
grid: { grid: {
line: { line: {
style: { style: {
stroke: '#E8E8E8', stroke: '#F0F0F0',
lineWidth: 1, lineWidth: 1,
lineDash: [3, 3], lineDash: [4, 4],
}, },
}, },
}, },
label: { label: {
formatter: (val: string) => `${Number(val)}单`,
style: { style: {
fontSize: 12, fontSize: 12,
fill: '#8C8C8C',
}, },
}, },
}, },
yAxis: { yAxis: {
label: { label: {
style: { style: {
fontSize: isMobile ? 11 : 13, fontSize: 13,
fill: '#262626', fill: '#262626',
fontWeight: 500,
}, },
autoEllipsis: true, autoEllipsis: true,
autoRotate: false, autoRotate: false,
}, },
}, },
barStyle: { barStyle: {
radius: [0, 4, 4, 0], // 右侧圆角 radius: [0, 6, 6, 0], // 右侧圆角
}, },
animation: { animation: {
appear: { appear: {
animation: 'scale-in-x', animation: 'scale-in-x',
duration: 800, duration: 600,
easing: 'ease-out',
}, },
}, },
}; }), [scenicOrderData, chartFullHeight]);
// 饼图配置 // 饼图配置
const chartStats = stat?.chartStats || {}; const chartStats = stat?.chartStats || {};
@@ -951,8 +941,21 @@ const Welcome: React.FC = () => {
{/* 景区订单数量统计:单行展示 */} {/* 景区订单数量统计:单行展示 */}
<Row gutter={[16, 16]} style={{ marginTop: 16 }}> <Row gutter={[16, 16]} style={{ marginTop: 16 }}>
<Col xs={24}> <Col xs={24}>
<Card title="景区订单数量统计" loading={pageLoading} style={{ height: '100%' }}> <Card
<div style={{ height: (MAX_SCENIC_BARS * ROW_HEIGHT), overflowY: 'auto' }}> title="景区订单数量统计"
loading={pageLoading}
style={{ height: '100%' }}
bodyStyle={{ padding: '16px 24px' }}
>
<div style={{
height: containerHeight,
overflowY: 'auto',
overflowX: 'hidden',
paddingRight: 8,
// 美化滚动条
scrollbarWidth: 'thin',
scrollbarColor: '#bfbfbf #f0f0f0',
}}>
<Bar {...scenicOrderConfig} /> <Bar {...scenicOrderConfig} />
</div> </div>
</Card> </Card>