fix(后台管理):首页商户统计功能实现
This commit is contained in:
@@ -9,43 +9,43 @@
|
||||
export default {
|
||||
dev: {
|
||||
'/api-uaa/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-user/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-log/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-search/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-generator/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-file/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-order/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
'/api-device/': {
|
||||
// target: 'http://119.45.169.13:9900',
|
||||
target: 'http://127.0.0.1:9900',
|
||||
target: 'http://119.45.169.13:9900',
|
||||
// target: 'http://127.0.0.1:9900',
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -1,62 +1,78 @@
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography } from 'antd';
|
||||
import { Card, Row, Col, Statistic, Progress, Typography, Select, DatePicker, Space, Button } from 'antd';
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { dashboard } from '@/services/orders/api';
|
||||
import { Area, Column, Pie } from '@ant-design/plots';
|
||||
import {
|
||||
ShoppingCartOutlined,
|
||||
RocketOutlined,
|
||||
MobileOutlined,
|
||||
UserOutlined,
|
||||
RiseOutlined,
|
||||
PayCircleOutlined,
|
||||
RiseOutlined,
|
||||
FilterOutlined,
|
||||
ReloadOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import styles from './Welcome.less';
|
||||
|
||||
const { Title } = Typography;
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
interface Statistics {
|
||||
totalOrders: number;
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
totalAmount: number;
|
||||
todayAmount: number;
|
||||
targetCompletion: number;
|
||||
totalWaylines: number;
|
||||
activeWaylines: number;
|
||||
waylineUsage: number;
|
||||
totalDevices: number;
|
||||
onlineDevices: number;
|
||||
deviceOnlineRate: number;
|
||||
orderTrend: {
|
||||
date: string;
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
deviceDistribution: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
incomeData: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
tourismRanking: {
|
||||
id: string;
|
||||
name: string;
|
||||
value: number;
|
||||
}[];
|
||||
orderStats: {
|
||||
totalOrders: number;
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
// 新增对账维度
|
||||
totalAmount: number; // 订单总金额(分)
|
||||
platformAmount: number; // 平台分账金额(分)
|
||||
tourismAmount: number; // 景区分账金额(分)
|
||||
refundAmount: number; // 退款金额(分)
|
||||
netIncome: number; // 净收入(分)
|
||||
};
|
||||
// 移除设备和航线统计
|
||||
chartStats: {
|
||||
orderTrend: {
|
||||
date: string;
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
orderDistribution: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
incomeBreakdown: {
|
||||
type: string;
|
||||
value: number;
|
||||
}[];
|
||||
};
|
||||
// 新增筛选维度数据
|
||||
filterOptions: {
|
||||
tourismList: { label: string; value: number; }[];
|
||||
qrcodeList: { label: string; value: string; }[];
|
||||
deviceList: { label: string; value: string; }[];
|
||||
};
|
||||
}
|
||||
|
||||
const Welcome: React.FC = () => {
|
||||
const [loading, setLoading] = useState<boolean>(true);
|
||||
const [statistics, setStatistics] = useState<any>({});
|
||||
|
||||
// 筛选条件
|
||||
const [selectedTourism, setSelectedTourism] = useState<number | undefined>();
|
||||
const [selectedQrcode, setSelectedQrcode] = useState<string | undefined>();
|
||||
const [selectedDevice, setSelectedDevice] = useState<string | undefined>();
|
||||
const [timeRange, setTimeRange] = useState<[string, string]>(['', '']);
|
||||
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
const result = await dashboard();
|
||||
const params = {
|
||||
tourismId: selectedTourism,
|
||||
qrcodeId: selectedQrcode,
|
||||
deviceSn: selectedDevice,
|
||||
startTime: timeRange[0],
|
||||
endTime: timeRange[1],
|
||||
};
|
||||
const result = await dashboard(params);
|
||||
if (result.resp_code === 0) {
|
||||
setStatistics(result.data);
|
||||
}
|
||||
@@ -69,16 +85,12 @@ const Welcome: React.FC = () => {
|
||||
|
||||
useEffect(() => {
|
||||
fetchData();
|
||||
const timer = setInterval(fetchData, 5 * 60 * 1000);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
}, [selectedTourism, selectedQrcode, selectedDevice, timeRange]);
|
||||
|
||||
// 更新数据访问方式
|
||||
const orderStats = statistics.orderStats || {};
|
||||
const incomeStats = statistics.incomeStats || {};
|
||||
const waylineStats = statistics.waylineStats || {};
|
||||
const deviceStats = statistics.deviceStats || {};
|
||||
const chartStats = statistics.chartStats || {};
|
||||
const filterOptions = statistics.filterOptions || {};
|
||||
|
||||
// 订单趋势配置
|
||||
const orderTrendConfig = {
|
||||
@@ -96,9 +108,9 @@ const Welcome: React.FC = () => {
|
||||
},
|
||||
};
|
||||
|
||||
// 设备分布配置
|
||||
const deviceDistConfig = {
|
||||
data: chartStats.deviceDistribution || [],
|
||||
// 订单分布配置
|
||||
const orderDistConfig = {
|
||||
data: chartStats.orderDistribution || [],
|
||||
angleField: 'value',
|
||||
colorField: 'type',
|
||||
radius: 0.8,
|
||||
@@ -108,9 +120,9 @@ const Welcome: React.FC = () => {
|
||||
},
|
||||
};
|
||||
|
||||
// 收入统计配置
|
||||
// 收入构成配置
|
||||
const incomeConfig = {
|
||||
data: chartStats.incomeData || [],
|
||||
data: chartStats.incomeBreakdown || [],
|
||||
xField: 'type',
|
||||
yField: 'value',
|
||||
label: {
|
||||
@@ -124,9 +136,58 @@ const Welcome: React.FC = () => {
|
||||
|
||||
return (
|
||||
<PageContainer className={styles.container}>
|
||||
{/* 筛选条件 */}
|
||||
<Card style={{ marginBottom: 16 }}>
|
||||
<Space size="large">
|
||||
<span>筛选条件:</span>
|
||||
<Select
|
||||
placeholder="选择景区"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
options={filterOptions.tourismList || []}
|
||||
value={selectedTourism}
|
||||
onChange={setSelectedTourism}
|
||||
/>
|
||||
<Select
|
||||
placeholder="选择二维码/点位"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
options={filterOptions.qrcodeList || []}
|
||||
value={selectedQrcode}
|
||||
onChange={setSelectedQrcode}
|
||||
/>
|
||||
<Select
|
||||
placeholder="选择设备"
|
||||
style={{ width: 200 }}
|
||||
allowClear
|
||||
options={filterOptions.deviceList || []}
|
||||
value={selectedDevice}
|
||||
onChange={setSelectedDevice}
|
||||
/>
|
||||
<RangePicker
|
||||
placeholder={['开始时间', '结束时间']}
|
||||
onChange={(dates) => {
|
||||
if (dates) {
|
||||
setTimeRange([
|
||||
dates[0]?.format('YYYY-MM-DD HH:mm:ss') || '',
|
||||
dates[1]?.format('YYYY-MM-DD HH:mm:ss') || ''
|
||||
]);
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<Button
|
||||
icon={<ReloadOutlined />}
|
||||
onClick={fetchData}
|
||||
type="primary"
|
||||
>
|
||||
刷新
|
||||
</Button>
|
||||
</Space>
|
||||
</Card>
|
||||
|
||||
{/* 核心指标 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24} sm={12} md={6}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<ShoppingCartOutlined className={styles.iconOrders} />
|
||||
@@ -152,65 +213,60 @@ const Welcome: React.FC = () => {
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={6}>
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<PayCircleOutlined className={styles.iconIncome} />
|
||||
<span>收入统计</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="总收入"
|
||||
value={(incomeStats.totalAmount || 0) / 100}
|
||||
title="订单总金额"
|
||||
value={(orderStats.totalAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic
|
||||
title="今日收入"
|
||||
value={(incomeStats.todayAmount || 0) / 100}
|
||||
title="景区净收入"
|
||||
value={(orderStats.netIncome || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<Statistic
|
||||
title="退款金额"
|
||||
value={(orderStats.refundAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={8}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<PayCircleOutlined className={styles.iconIncome} />
|
||||
<span>分账明细</span>
|
||||
</div>
|
||||
<Statistic
|
||||
title="平台分账"
|
||||
value={(orderStats.platformAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<div className={styles.subStats}>
|
||||
<Statistic
|
||||
title="景区分账"
|
||||
value={(orderStats.tourismAmount || 0) / 100}
|
||||
precision={2}
|
||||
prefix="¥"
|
||||
/>
|
||||
<Progress
|
||||
percent={incomeStats.targetCompletion || 0}
|
||||
size="small"
|
||||
status="active"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={6}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<RocketOutlined className={styles.iconWayline} />
|
||||
<span>航线概况</span>
|
||||
</div>
|
||||
<Statistic title="航线总数" value={waylineStats.totalWaylines || 0} />
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title="活跃航线" value={waylineStats.activeWaylines || 0} />
|
||||
<Progress
|
||||
percent={waylineStats.waylineUsage || 0}
|
||||
size="small"
|
||||
status="active"
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
|
||||
<Col xs={24} sm={12} md={6}>
|
||||
<Card className={styles.statCard} loading={loading}>
|
||||
<div className={styles.statHeader}>
|
||||
<MobileOutlined className={styles.iconDevice} />
|
||||
<span>设备状态</span>
|
||||
</div>
|
||||
<Statistic title="设备总数" value={deviceStats.totalDevices || 0} />
|
||||
<div className={styles.subStats}>
|
||||
<Statistic title="在线设备" value={deviceStats.onlineDevices || 0} />
|
||||
<Progress
|
||||
percent={deviceStats.deviceOnlineRate || 0}
|
||||
percent={orderStats.totalAmount > 0 ?
|
||||
((orderStats.tourismAmount || 0) / orderStats.totalAmount * 100) : 0}
|
||||
size="small"
|
||||
status="active"
|
||||
format={(percent) => `分账率 ${percent?.toFixed(1)}%`}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
@@ -225,34 +281,19 @@ const Welcome: React.FC = () => {
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={8}>
|
||||
<Card title="设备分布" loading={loading}>
|
||||
<Pie {...deviceDistConfig} height={300} />
|
||||
<Card title="订单状态分布" loading={loading}>
|
||||
<Pie {...orderDistConfig} height={300} />
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 业务数据 */}
|
||||
<Row gutter={[16, 16]} className={styles.businessRow}>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card title="收入统计" loading={loading}>
|
||||
{/* 收入构成 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col xs={24}>
|
||||
<Card title="收入构成分析" loading={loading}>
|
||||
<Column {...incomeConfig} height={300} />
|
||||
</Card>
|
||||
</Col>
|
||||
<Col xs={24} lg={12}>
|
||||
<Card title="景区排名" loading={loading}>
|
||||
<div className={styles.rankList}>
|
||||
{statistics.tourismRanking?.map((item: { id: string; name: string; value: number }, index: number) => (
|
||||
<div key={item.id} className={styles.rankItem}>
|
||||
<span className={`${styles.rankNum} ${index < 3 ? 'topThree' : ''}`}>
|
||||
{index + 1}
|
||||
</span>
|
||||
<span className={styles.rankName}>{item.name}</span>
|
||||
<span className={styles.rankValue}>{item.value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</Card>
|
||||
</Col>
|
||||
</Row>
|
||||
</PageContainer>
|
||||
);
|
||||
|
||||
@@ -79,6 +79,15 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
label="租户ID"
|
||||
width="md"
|
||||
placeholder="请输入租户ID"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormTextArea
|
||||
name="tourismDesc"
|
||||
|
||||
@@ -142,6 +142,12 @@ const TableList: React.FC = () => {
|
||||
dataIndex: 'tourismPhone',
|
||||
copyable: true,
|
||||
},
|
||||
{
|
||||
title: '租户ID',
|
||||
dataIndex: 'tenantId',
|
||||
copyable: true,
|
||||
hideInSearch: true,
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
@@ -259,6 +265,15 @@ const TableList: React.FC = () => {
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormText
|
||||
name="tenantId"
|
||||
label="租户ID"
|
||||
width="md"
|
||||
placeholder="请输入租户ID(可选,不填将自动获取当前租户)"
|
||||
/>
|
||||
</ProForm.Group>
|
||||
|
||||
<ProForm.Group>
|
||||
<ProFormTextArea
|
||||
name="tourismDesc"
|
||||
|
||||
+21
-4
@@ -1,6 +1,6 @@
|
||||
// 设备维度统计组件
|
||||
import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react';
|
||||
import { ProForm, ProFormDateRangePicker, ProTable } from '@ant-design/pro-components';
|
||||
import { ProForm, ProFormDateRangePicker, ProFormSelect, ProTable } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, message } from 'antd';
|
||||
import { Column } from '@ant-design/plots';
|
||||
import moment from 'moment';
|
||||
@@ -24,9 +24,12 @@ interface DeviceStatisticsItem {
|
||||
|
||||
interface DeviceStatisticsProps {
|
||||
refreshKey: number;
|
||||
deviceOptions: { label: string; value: string; }[];
|
||||
deviceSn?: string;
|
||||
onDeviceChange: (deviceSn: string) => void;
|
||||
}
|
||||
|
||||
const DeviceStatistics = forwardRef(({ refreshKey }: DeviceStatisticsProps, ref) => {
|
||||
const DeviceStatistics = forwardRef(({ refreshKey, deviceOptions, deviceSn, onDeviceChange }: DeviceStatisticsProps, ref) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().startOf('month'),
|
||||
@@ -41,6 +44,7 @@ const DeviceStatistics = forwardRef(({ refreshKey }: DeviceStatisticsProps, ref)
|
||||
const params = {
|
||||
startTime: timeRange[0].format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: timeRange[1].format('YYYY-MM-DD HH:mm:ss'),
|
||||
deviceSn: deviceSn,
|
||||
};
|
||||
|
||||
const res = await getDeviceStatistics(params);
|
||||
@@ -191,8 +195,8 @@ const DeviceStatistics = forwardRef(({ refreshKey }: DeviceStatisticsProps, ref)
|
||||
submitter={false}
|
||||
initialValues={{ timeRange }}
|
||||
>
|
||||
<Row>
|
||||
<Col span={24}>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<ProFormDateRangePicker
|
||||
name="timeRange"
|
||||
label="统计时间"
|
||||
@@ -208,6 +212,19 @@ const DeviceStatistics = forwardRef(({ refreshKey }: DeviceStatisticsProps, ref)
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<ProFormSelect
|
||||
name="deviceSn"
|
||||
label="选择设备"
|
||||
fieldProps={{
|
||||
value: deviceSn,
|
||||
onChange: onDeviceChange,
|
||||
options: deviceOptions,
|
||||
placeholder: '请选择设备',
|
||||
allowClear: true,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</ProForm>
|
||||
</Card>
|
||||
|
||||
+21
-4
@@ -1,5 +1,5 @@
|
||||
import React, { forwardRef, useImperativeHandle, useState, useEffect } from 'react';
|
||||
import { ProForm, ProFormDateRangePicker, ProTable } from '@ant-design/pro-components';
|
||||
import { ProForm, ProFormDateRangePicker, ProFormSelect, ProTable } from '@ant-design/pro-components';
|
||||
import { Card, Row, Col, Statistic, message } from 'antd';
|
||||
import { Column } from '@ant-design/plots';
|
||||
import moment from 'moment';
|
||||
@@ -23,9 +23,12 @@ interface TourismStatisticsItem {
|
||||
|
||||
interface TourismStatisticsProps {
|
||||
refreshKey: number;
|
||||
tourismOptions: { label: string; value: string; }[];
|
||||
tourismId?: string;
|
||||
onTourismChange: (tourismId: string) => void;
|
||||
}
|
||||
|
||||
const TourismStatistics = forwardRef(({ refreshKey }: TourismStatisticsProps, ref) => {
|
||||
const TourismStatistics = forwardRef(({ refreshKey, tourismOptions, tourismId, onTourismChange }: TourismStatisticsProps, ref) => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [timeRange, setTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().startOf('month'),
|
||||
@@ -40,6 +43,7 @@ const TourismStatistics = forwardRef(({ refreshKey }: TourismStatisticsProps, re
|
||||
const params = {
|
||||
startTime: timeRange[0].format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: timeRange[1].format('YYYY-MM-DD HH:mm:ss'),
|
||||
tourismId: tourismId,
|
||||
};
|
||||
|
||||
const res = await getTourismStatistics(params);
|
||||
@@ -191,8 +195,8 @@ const TourismStatistics = forwardRef(({ refreshKey }: TourismStatisticsProps, re
|
||||
submitter={false}
|
||||
initialValues={{ timeRange }}
|
||||
>
|
||||
<Row>
|
||||
<Col span={24}>
|
||||
<Row gutter={16}>
|
||||
<Col span={12}>
|
||||
<ProFormDateRangePicker
|
||||
name="timeRange"
|
||||
label="统计时间"
|
||||
@@ -208,6 +212,19 @@ const TourismStatistics = forwardRef(({ refreshKey }: TourismStatisticsProps, re
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<ProFormSelect
|
||||
name="tourismId"
|
||||
label="选择景区"
|
||||
fieldProps={{
|
||||
value: tourismId,
|
||||
onChange: onTourismChange,
|
||||
options: tourismOptions,
|
||||
placeholder: '请选择景区',
|
||||
allowClear: true,
|
||||
}}
|
||||
/>
|
||||
</Col>
|
||||
</Row>
|
||||
</ProForm>
|
||||
</Card>
|
||||
|
||||
@@ -3,7 +3,7 @@ import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Tabs, Button, message, Modal, DatePicker } from 'antd';
|
||||
import { ReloadOutlined, DownloadOutlined, LineChartOutlined } from '@ant-design/icons';
|
||||
import type { TabsProps } from 'antd';
|
||||
import { getQrcodeList, generateStatistics } from '@/services/statistics/api';
|
||||
import { getQrcodeList, getDeviceList, getTourismList, generateStatistics } from '@/services/statistics/api';
|
||||
import QrcodeStatistics from './components/QrcodeStatistics';
|
||||
import DeviceStatistics from './components/DeviceStatistics';
|
||||
import TourismStatistics from './components/TourismStatistics';
|
||||
@@ -13,7 +13,11 @@ const { RangePicker } = DatePicker;
|
||||
|
||||
const Statistics: React.FC = () => {
|
||||
const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||
const [deviceOptions, setDeviceOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||
const [tourismOptions, setTourismOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||
const [qrcodeId, setQrcodeId] = useState<string>();
|
||||
const [deviceSn, setDeviceSn] = useState<string>();
|
||||
const [tourismId, setTourismId] = useState<string>();
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [generateModalVisible, setGenerateModalVisible] = useState(false);
|
||||
const [generateTimeRange, setGenerateTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
@@ -27,24 +31,73 @@ const Statistics: React.FC = () => {
|
||||
const fetchQrcodeList = async () => {
|
||||
try {
|
||||
const res = await getQrcodeList({ page: 1, limit: 100 });
|
||||
console.log('二维码列表响应:', res); // 添加调试日志
|
||||
if (res.resp_code === 0 && res.data) {
|
||||
const options = res.data.map((item: any) => ({
|
||||
label: `${item.name || item.qrcode} | ${item.deviceSn || '无设备'} | ${((item.price || 0) / 100).toFixed(2)}元`,
|
||||
label: `${item.name || item.codeId} | ${item.deviceSn || '无设备'} | ${((item.price || 0) / 100).toFixed(2)}元`,
|
||||
value: item.codeId,
|
||||
}));
|
||||
console.log('二维码选项:', options); // 添加调试日志
|
||||
setQrcodeOptions(options);
|
||||
if (options.length > 0) {
|
||||
setQrcodeId(options[0].value);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取二维码列表失败:', error); // 添加错误日志
|
||||
message.error('获取二维码列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 获取设备列表
|
||||
const fetchDeviceList = async () => {
|
||||
try {
|
||||
const res = await getDeviceList({ page: 1, limit: 100 });
|
||||
console.log('设备列表响应:', res);
|
||||
if (res.resp_code === 0 && res.data) {
|
||||
const options = res.data.map((item: any) => ({
|
||||
label: `${item.deviceSn || '未知设备'} | ${item.deviceName || '无名称'}`,
|
||||
value: item.deviceSn,
|
||||
}));
|
||||
console.log('设备选项:', options);
|
||||
setDeviceOptions(options);
|
||||
if (options.length > 0) {
|
||||
setDeviceSn(options[0].value);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取设备列表失败:', error);
|
||||
message.error('获取设备列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 获取景区列表
|
||||
const fetchTourismList = async () => {
|
||||
try {
|
||||
const res = await getTourismList({ page: 1, limit: 100 });
|
||||
console.log('景区列表响应:', res);
|
||||
if (res.resp_code === 0 && res.data) {
|
||||
const options = res.data.map((item: any) => ({
|
||||
label: `${item.name || '未知景区'} | ${item.address || '无地址'}`,
|
||||
value: item.id?.toString(),
|
||||
}));
|
||||
console.log('景区选项:', options);
|
||||
setTourismOptions(options);
|
||||
if (options.length > 0) {
|
||||
setTourismId(options[0].value);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取景区列表失败:', error);
|
||||
message.error('获取景区列表失败');
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化加载
|
||||
useEffect(() => {
|
||||
fetchQrcodeList();
|
||||
fetchDeviceList();
|
||||
fetchTourismList();
|
||||
}, []);
|
||||
|
||||
// 生成统计数据
|
||||
@@ -158,6 +211,9 @@ const Statistics: React.FC = () => {
|
||||
children: (
|
||||
<DeviceStatistics
|
||||
ref={deviceRef}
|
||||
deviceOptions={deviceOptions}
|
||||
deviceSn={deviceSn}
|
||||
onDeviceChange={setDeviceSn}
|
||||
refreshKey={refreshKey}
|
||||
/>
|
||||
),
|
||||
@@ -168,6 +224,9 @@ const Statistics: React.FC = () => {
|
||||
children: (
|
||||
<TourismStatistics
|
||||
ref={tourismRef}
|
||||
tourismOptions={tourismOptions}
|
||||
tourismId={tourismId}
|
||||
onTourismChange={setTourismId}
|
||||
refreshKey={refreshKey}
|
||||
/>
|
||||
),
|
||||
|
||||
@@ -184,9 +184,16 @@ export async function getOrderDetail(orderNo: string) {
|
||||
}
|
||||
|
||||
/** 获取首页统计数据 GET /api-order/dashboard/statistics */
|
||||
export async function dashboard() {
|
||||
export async function dashboard(params?: {
|
||||
tourismId?: number;
|
||||
qrcodeId?: string;
|
||||
deviceSn?: string;
|
||||
startTime?: string;
|
||||
endTime?: string;
|
||||
}) {
|
||||
return request('/api-order/dashboard/statistics', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -108,21 +108,12 @@ declare namespace ORDERS {
|
||||
todayOrders: number;
|
||||
orderGrowth: number;
|
||||
completionRate: number;
|
||||
};
|
||||
incomeStats: {
|
||||
totalAmount: number;
|
||||
todayAmount: number;
|
||||
targetCompletion: number;
|
||||
};
|
||||
waylineStats: {
|
||||
totalWaylines: number;
|
||||
activeWaylines: number;
|
||||
waylineUsage: number;
|
||||
};
|
||||
deviceStats: {
|
||||
totalDevices: number;
|
||||
onlineDevices: number;
|
||||
deviceOnlineRate: number;
|
||||
// 对账相关字段
|
||||
totalAmount: number; // 订单总金额(分)
|
||||
platformAmount: number; // 平台分账金额(分)
|
||||
tourismAmount: number; // 景区分账金额(分)
|
||||
refundAmount: number; // 退款金额(分)
|
||||
netIncome: number; // 净收入(分)
|
||||
};
|
||||
chartStats: {
|
||||
orderTrend: Array<{
|
||||
@@ -130,20 +121,29 @@ declare namespace ORDERS {
|
||||
type: string;
|
||||
value: number;
|
||||
}>;
|
||||
deviceDistribution: Array<{
|
||||
orderDistribution: Array<{
|
||||
type: string;
|
||||
value: number;
|
||||
}>;
|
||||
incomeData: Array<{
|
||||
incomeBreakdown: Array<{
|
||||
type: string;
|
||||
value: number;
|
||||
}>;
|
||||
};
|
||||
tourismRanking: Array<{
|
||||
id: string;
|
||||
name: string;
|
||||
value: number;
|
||||
}>;
|
||||
filterOptions: {
|
||||
tourismList: Array<{
|
||||
label: string;
|
||||
value: number;
|
||||
}>;
|
||||
qrcodeList: Array<{
|
||||
label: string;
|
||||
value: string;
|
||||
}>;
|
||||
deviceList: Array<{
|
||||
label: string;
|
||||
value: string;
|
||||
}>;
|
||||
};
|
||||
}
|
||||
|
||||
interface ProfitSharing {
|
||||
|
||||
@@ -14,6 +14,34 @@ export async function getQrcodeList(params: QrcodeListParams = { page: 1, limit:
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取设备列表参数 */
|
||||
interface DeviceListParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
/** 获取设备列表 */
|
||||
export async function getDeviceList(params: DeviceListParams = { page: 1, limit: 100 }) {
|
||||
return request('/api-device/device', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取景区列表参数 */
|
||||
interface TourismListParams {
|
||||
page: number;
|
||||
limit: number;
|
||||
}
|
||||
|
||||
/** 获取景区列表 */
|
||||
export async function getTourismList(params: TourismListParams = { page: 1, limit: 100 }) {
|
||||
return request('/api-order/tourism', {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 时间维度类型 */
|
||||
type TimeType = 'hour' | 'day' | 'month';
|
||||
|
||||
@@ -46,6 +74,7 @@ export async function getTimeStatistics(params: TimeStatisticsParams) {
|
||||
interface DeviceStatisticsParams {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
deviceSn?: string;
|
||||
}
|
||||
|
||||
/** 获取设备维度统计数据 */
|
||||
@@ -56,11 +85,15 @@ export async function getDeviceStatistics(params: DeviceStatisticsParams) {
|
||||
});
|
||||
}
|
||||
|
||||
/** 获取景区维度统计数据 */
|
||||
export async function getTourismStatistics(params: {
|
||||
/** 获取景区维度统计数据参数 */
|
||||
interface TourismStatisticsParams {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
tourismId?: string;
|
||||
}
|
||||
|
||||
/** 获取景区维度统计数据 */
|
||||
export async function getTourismStatistics(params: TourismStatisticsParams) {
|
||||
return request('/api-order/statistics/tourism', {
|
||||
method: 'GET',
|
||||
params,
|
||||
|
||||
Reference in New Issue
Block a user