feat:修改首页景区数量统计
This commit is contained in:
@@ -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 { ReloadOutlined } from '@ant-design/icons';
|
||||
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);
|
||||
|
||||
// 最多同时可见 5 条,通过容器滚动查看全部
|
||||
const MAX_SCENIC_BARS = 6;
|
||||
const ROW_HEIGHT = 35;
|
||||
const chartFullHeight = Math.max(((Array.isArray(scenicOrderData) ? scenicOrderData.length : 0) * ROW_HEIGHT), MAX_SCENIC_BARS * ROW_HEIGHT);
|
||||
// 每个条形的高度,容器固定高度显示8条,超出滚动
|
||||
const MAX_VISIBLE_BARS = 8;
|
||||
const BAR_HEIGHT = 50; // 每个条形的高度
|
||||
const chartFullHeight = Math.max((Array.isArray(scenicOrderData) ? scenicOrderData.length : 0) * BAR_HEIGHT, 400);
|
||||
const containerHeight = MAX_VISIBLE_BARS * BAR_HEIGHT; // 固定容器高度400px
|
||||
|
||||
// 景区订单数量横向条形图配置 - 景区名称在Y轴(左侧),订单数量横向展示
|
||||
const scenicOrderConfig: any = {
|
||||
const scenicOrderConfig: any = useMemo(() => ({
|
||||
data: scenicOrderData,
|
||||
xField: 'tourismName', // 这里反直觉:xField是分类(显示为Y轴)
|
||||
yField: 'orderCount', // yField是数值(显示为横向长度)
|
||||
autoFit: true,
|
||||
xField: 'orderCount', // 横向数值轴
|
||||
yField: 'tourismName', // 纵向分类轴(景区名称)
|
||||
autoFit: false, // 关闭自动适应,使用固定高度
|
||||
height: chartFullHeight,
|
||||
// 关键:转置坐标系,使横向条形图
|
||||
coordinate: {
|
||||
transpose: true,
|
||||
},
|
||||
// 使用绿色渐变,根据数值大小
|
||||
// 使用渐变色,根据数值大小
|
||||
color: ({ orderCount }: any) => {
|
||||
const maxCount = Math.max(...scenicOrderData.map(d => d.orderCount), 1);
|
||||
const ratio = orderCount / maxCount;
|
||||
@@ -297,64 +294,57 @@ const Welcome: React.FC = () => {
|
||||
return '#B7EB8F'; // 很浅绿
|
||||
},
|
||||
label: {
|
||||
position: 'right', // 标签显示在条形右侧外部
|
||||
offset: 8,
|
||||
position: 'right',
|
||||
offset: 10,
|
||||
content: (item: any) => {
|
||||
// 订单数为0时不显示标签,避免与景区名称重叠
|
||||
if (item.orderCount === 0) return '';
|
||||
return `${item.orderCount}单`;
|
||||
},
|
||||
style: {
|
||||
fill: '#666',
|
||||
fontSize: 12,
|
||||
fontWeight: 500,
|
||||
textAlign: 'left',
|
||||
fill: '#595959',
|
||||
fontSize: 13,
|
||||
fontWeight: 600,
|
||||
},
|
||||
},
|
||||
xAxis: {
|
||||
title: {
|
||||
text: '订单数量',
|
||||
style: {
|
||||
fontSize: 14,
|
||||
fontWeight: 500,
|
||||
},
|
||||
},
|
||||
grid: {
|
||||
line: {
|
||||
style: {
|
||||
stroke: '#E8E8E8',
|
||||
stroke: '#F0F0F0',
|
||||
lineWidth: 1,
|
||||
lineDash: [3, 3],
|
||||
lineDash: [4, 4],
|
||||
},
|
||||
},
|
||||
},
|
||||
label: {
|
||||
formatter: (val: string) => `${Number(val)}单`,
|
||||
style: {
|
||||
fontSize: 12,
|
||||
fill: '#8C8C8C',
|
||||
},
|
||||
},
|
||||
},
|
||||
yAxis: {
|
||||
label: {
|
||||
style: {
|
||||
fontSize: isMobile ? 11 : 13,
|
||||
fontSize: 13,
|
||||
fill: '#262626',
|
||||
fontWeight: 500,
|
||||
},
|
||||
autoEllipsis: true,
|
||||
autoRotate: false,
|
||||
},
|
||||
},
|
||||
barStyle: {
|
||||
radius: [0, 4, 4, 0], // 右侧圆角
|
||||
radius: [0, 6, 6, 0], // 右侧圆角
|
||||
},
|
||||
animation: {
|
||||
appear: {
|
||||
animation: 'scale-in-x',
|
||||
duration: 800,
|
||||
duration: 600,
|
||||
easing: 'ease-out',
|
||||
},
|
||||
},
|
||||
};
|
||||
}), [scenicOrderData, chartFullHeight]);
|
||||
|
||||
// 饼图配置
|
||||
const chartStats = stat?.chartStats || {};
|
||||
@@ -951,8 +941,21 @@ const Welcome: React.FC = () => {
|
||||
{/* 景区订单数量统计:单行展示 */}
|
||||
<Row gutter={[16, 16]} style={{ marginTop: 16 }}>
|
||||
<Col xs={24}>
|
||||
<Card title="景区订单数量统计" loading={pageLoading} style={{ height: '100%' }}>
|
||||
<div style={{ height: (MAX_SCENIC_BARS * ROW_HEIGHT), overflowY: 'auto' }}>
|
||||
<Card
|
||||
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} />
|
||||
</div>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user