fix(统计管理):新增生成统计数据的功能
This commit is contained in:
+1
@@ -264,6 +264,7 @@ const DeviceStatistics: React.FC<{ refreshKey: number }> = ({ refreshKey }) => {
|
||||
{/* 详细数据表格 */}
|
||||
<Card bordered={false}>
|
||||
<ProTable
|
||||
rowKey="groupKey"
|
||||
dataSource={statisticsData}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
|
||||
+1
@@ -273,6 +273,7 @@ const QrcodeStatistics: React.FC<QrcodeStatisticsProps> = ({
|
||||
{/* 详细数据表格 */}
|
||||
<Card bordered={false}>
|
||||
<ProTable
|
||||
rowKey="groupKey"
|
||||
dataSource={statisticsData}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
|
||||
+1
@@ -264,6 +264,7 @@ const TourismStatistics: React.FC<{ refreshKey: number }> = ({ refreshKey }) =>
|
||||
{/* 详细数据表格 */}
|
||||
<Card bordered={false}>
|
||||
<ProTable
|
||||
rowKey="groupKey"
|
||||
dataSource={statisticsData}
|
||||
columns={columns}
|
||||
loading={loading}
|
||||
|
||||
@@ -83,4 +83,18 @@
|
||||
border: 1px solid #f0f0f0;
|
||||
border-top: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ant-modal {
|
||||
.ant-picker {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.statistics-page-header {
|
||||
.ant-page-header-heading-extra {
|
||||
.ant-btn {
|
||||
margin-left: 8px;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,26 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { PageContainer } from '@ant-design/pro-components';
|
||||
import { Card, Tabs, Button, message } from 'antd';
|
||||
import { ReloadOutlined, DownloadOutlined } from '@ant-design/icons';
|
||||
import { Card, Tabs, Button, message, Modal, DatePicker } from 'antd';
|
||||
import { ReloadOutlined, DownloadOutlined, LineChartOutlined } from '@ant-design/icons';
|
||||
import type { TabsProps } from 'antd';
|
||||
import { getQrcodeList } from '@/services/statistics/api';
|
||||
import { getQrcodeList, generateStatistics } from '@/services/statistics/api';
|
||||
import QrcodeStatistics from './components/QrcodeStatistics';
|
||||
import DeviceStatistics from './components/DeviceStatistics';
|
||||
import TourismStatistics from './components/TourismStatistics';
|
||||
import moment from 'moment';
|
||||
|
||||
const { RangePicker } = DatePicker;
|
||||
|
||||
const Statistics: React.FC = () => {
|
||||
const [qrcodeOptions, setQrcodeOptions] = useState<{ label: string; value: string; }[]>([]);
|
||||
const [qrcodeId, setQrcodeId] = useState<string>();
|
||||
const [refreshKey, setRefreshKey] = useState(0);
|
||||
const [generateModalVisible, setGenerateModalVisible] = useState(false);
|
||||
const [generateTimeRange, setGenerateTimeRange] = useState<[moment.Moment, moment.Moment]>([
|
||||
moment().startOf('month'),
|
||||
moment().endOf('month')
|
||||
]);
|
||||
const [generating, setGenerating] = useState(false);
|
||||
|
||||
// 获取二维码列表
|
||||
const fetchQrcodeList = async () => {
|
||||
@@ -37,6 +46,34 @@ const Statistics: React.FC = () => {
|
||||
fetchQrcodeList();
|
||||
}, []);
|
||||
|
||||
// 生成统计数据
|
||||
const handleGenerateStatistics = async () => {
|
||||
if (!generateTimeRange) {
|
||||
message.error('请选择时间范围');
|
||||
return;
|
||||
}
|
||||
|
||||
setGenerating(true);
|
||||
try {
|
||||
const params = {
|
||||
startTime: generateTimeRange[0].format('YYYY-MM-DD HH:mm:ss'),
|
||||
endTime: generateTimeRange[1].format('YYYY-MM-DD HH:mm:ss'),
|
||||
};
|
||||
|
||||
const res = await generateStatistics(params);
|
||||
if (res.resp_code === 0) {
|
||||
message.success('统计数据生成成功');
|
||||
setGenerateModalVisible(false);
|
||||
// 刷新当前页面数据
|
||||
setRefreshKey(prev => prev + 1);
|
||||
}
|
||||
} catch (error) {
|
||||
message.error('统计数据生成失败');
|
||||
} finally {
|
||||
setGenerating(false);
|
||||
}
|
||||
};
|
||||
|
||||
const items: TabsProps['items'] = [
|
||||
{
|
||||
key: 'qrcode',
|
||||
@@ -73,6 +110,14 @@ const Statistics: React.FC = () => {
|
||||
return (
|
||||
<PageContainer
|
||||
extra={[
|
||||
<Button
|
||||
key="generate"
|
||||
type="primary"
|
||||
icon={<LineChartOutlined />}
|
||||
onClick={() => setGenerateModalVisible(true)}
|
||||
>
|
||||
生成统计
|
||||
</Button>,
|
||||
<Button
|
||||
key="refresh"
|
||||
icon={<ReloadOutlined />}
|
||||
@@ -99,6 +144,35 @@ const Statistics: React.FC = () => {
|
||||
// 切换 tab 时的处理逻辑
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 生成统计数据弹窗 */}
|
||||
<Modal
|
||||
title="生成统计数据"
|
||||
open={generateModalVisible}
|
||||
onCancel={() => setGenerateModalVisible(false)}
|
||||
onOk={handleGenerateStatistics}
|
||||
confirmLoading={generating}
|
||||
maskClosable={false}
|
||||
>
|
||||
<div style={{ padding: '20px 0' }}>
|
||||
<div style={{ marginBottom: 16 }}>请选择要生成统计数据的时间范围:</div>
|
||||
<RangePicker
|
||||
showTime
|
||||
style={{ width: '100%' }}
|
||||
value={generateTimeRange}
|
||||
onChange={(dates) => setGenerateTimeRange(dates as [moment.Moment, moment.Moment])}
|
||||
ranges={{
|
||||
'今天': [moment().startOf('day'), moment().endOf('day')],
|
||||
'本周': [moment().startOf('week'), moment().endOf('week')],
|
||||
'本月': [moment().startOf('month'), moment().endOf('month')],
|
||||
'上个月': [
|
||||
moment().subtract(1, 'months').startOf('month'),
|
||||
moment().subtract(1, 'months').endOf('month')
|
||||
],
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Modal>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -65,4 +65,15 @@ export async function getTourismStatistics(params: {
|
||||
method: 'GET',
|
||||
params,
|
||||
});
|
||||
}
|
||||
|
||||
/** 生成统计数据 */
|
||||
export async function generateStatistics(params: {
|
||||
startTime: string;
|
||||
endTime: string;
|
||||
}) {
|
||||
return request('/api-order/statistics/generate', {
|
||||
method: 'POST',
|
||||
params,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user