Commit 72739bfb authored by 李纪文's avatar 李纪文

fix: 统计查看

parent 2a683881
...@@ -10,9 +10,9 @@ const Demo = () => { ...@@ -10,9 +10,9 @@ const Demo = () => {
// statisticType: '', // statisticType: '',
// } // }
const params = { const params = {
deviceCode: 'SC00000023', deviceCode: 'LLJ00000001',
sensors: '出水累计流量', sensors: '今日水量',
deviceType: '水厂', deviceType: '流量计',
statisticType: '', statisticType: '',
} }
return ( return (
......
...@@ -4,7 +4,9 @@ import moment from 'moment'; ...@@ -4,7 +4,9 @@ import moment from 'moment';
import Empty from '@wisdom-components/empty'; import Empty from '@wisdom-components/empty';
import LoadBox from '@wisdom-components/loadbox'; import LoadBox from '@wisdom-components/loadbox';
import BasicTable from '@wisdom-components/basictable'; import BasicTable from '@wisdom-components/basictable';
import { ConfigProvider, Select, DatePicker, Radio } from 'antd'; import { ExportExcel } from '@wisdom-components/exportexcel';
import { ConfigProvider, Select, DatePicker, Radio, Table, Button } from 'antd';
import { VerticalAlignBottomOutlined } from '@ant-design/icons';
import { BasicChart } from '@wisdom-components/basicchart'; import { BasicChart } from '@wisdom-components/basicchart';
import { getStatisticsInfo } from './apis'; import { getStatisticsInfo } from './apis';
import './index.less'; import './index.less';
...@@ -32,7 +34,6 @@ const StatisticalHistoryView = (props) => { ...@@ -32,7 +34,6 @@ const StatisticalHistoryView = (props) => {
const [picker, setPicker] = useState('day'); const [picker, setPicker] = useState('day');
const [time, setTime] = useState({ startTime: '', endTime: '' }); const [time, setTime] = useState({ startTime: '', endTime: '' });
const [dateTime, setDateTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss')); const [dateTime, setDateTime] = useState(moment().format('YYYY-MM-DD HH:mm:ss'));
const [hoverIndex, setHoverIndex] = useState(null);
// 时间切换筛选 // 时间切换筛选
const onTimeChange = (e) => { const onTimeChange = (e) => {
...@@ -55,11 +56,41 @@ const StatisticalHistoryView = (props) => { ...@@ -55,11 +56,41 @@ const StatisticalHistoryView = (props) => {
setTime({ startDate: start, endDate: end }); setTime({ startDate: start, endDate: end });
}; };
const exportExcelBtn = (e) => {
if (!dataSource.length) return false;
const sheetFilter = columns.map((item) => {
return item.dataIndex;
});
const sheetHeader = columns.map((item) => {
return item.title;
});
const sheetData = dataSource.map((item) => {
return {
pt: item.pt,
value0: String(item.value0),
value1: String(item.value1),
value2: String(item.value2),
};
});
ExportExcel({
name: `${props?.deviceParams?.sensors || ''}指标数据`,
content: [
{
sheetData: sheetData,
sheetName: 'sheet1',
sheetFilter: sheetFilter,
sheetHeader: sheetHeader,
columnWidths: [10, 10, 10, 10],
},
],
});
};
// 获取历史统计数据 // 获取历史统计数据
const getHistoryData = async () => { const getHistoryData = async () => {
const { deviceCode = '', sensors = '', deviceType = '', statisticType = '' } = historyParams; const { deviceCode = '', sensors = '', deviceType = '', statisticType = '' } = historyParams;
const nameTypeList = []; const nameTypeList = [];
if (!deviceCode || !sensors) return setHistoryRender(false); if (!deviceCode || !sensors) return setOptions(null);
nameTypeList.push({ nameTypeList.push({
name: sensors, name: sensors,
type: statisticType || 'Sub', type: statisticType || 'Sub',
...@@ -75,13 +106,18 @@ const StatisticalHistoryView = (props) => { ...@@ -75,13 +106,18 @@ const StatisticalHistoryView = (props) => {
dateType: picker, dateType: picker,
}; };
setLoading(true); setLoading(true);
const results = await getStatisticsInfo(params); let results = null;
try {
results = await getStatisticsInfo(params);
} catch (err) {
return setLoading(false);
}
setLoading(false); setLoading(false);
const list = results?.data?.list || []; const list = results?.data?.list || [];
const dataList = list.length ? list[0] : {}; const dataList = list.length ? list[0] : {};
const dNameDataList = dataList.dNameDataList ? dataList.dNameDataList : []; const dNameDataList = dataList.dNameDataList ? dataList.dNameDataList : [];
const data = dNameDataList.length ? dNameDataList[0] : null; const data = dNameDataList.length ? dNameDataList[0] : null;
if (!data) return setHistoryRender(false); if (!data) return setOptions(null);
dataMenthod(data); dataMenthod(data);
}; };
...@@ -134,6 +170,19 @@ const StatisticalHistoryView = (props) => { ...@@ -134,6 +170,19 @@ const StatisticalHistoryView = (props) => {
if (times === time2) data2.push({ ...item, pt: pt }); if (times === time2) data2.push({ ...item, pt: pt });
}); });
break; break;
case 'thisYear':
time0 = moment(time.endDate).subtract(0, 'year').format('YYYY');
time1 = moment(time.endDate).subtract(1, 'year').format('YYYY');
time2 = moment(time.endDate).subtract(2, 'year').format('YYYY');
timeName = [].concat(yearName);
nameDate.forEach((item) => {
const times = moment(item.time).format('YYYY');
const pt = moment(item.time).format('MM月');
if (times === time0) data0.push({ ...item, pt: pt });
if (times === time1) data1.push({ ...item, pt: pt });
if (times === time2) data2.push({ ...item, pt: pt });
});
break;
case 'customer': case 'customer':
const style = picker === 'day' ? 'HH时' : picker === 'month' ? 'DD日' : 'MM月'; const style = picker === 'day' ? 'HH时' : picker === 'month' ? 'DD日' : 'MM月';
const format = picker === 'day' ? 'YYYY-MM-DD' : picker === 'month' ? 'YYYY-MM' : 'YYYY'; const format = picker === 'day' ? 'YYYY-MM-DD' : picker === 'month' ? 'YYYY-MM' : 'YYYY';
...@@ -172,11 +221,11 @@ const StatisticalHistoryView = (props) => { ...@@ -172,11 +221,11 @@ const StatisticalHistoryView = (props) => {
const series = []; const series = [];
dataInfo.data.forEach((item, index) => { dataInfo.data.forEach((item, index) => {
const config = !index && dName.indexOf('流量') > -1 ? { areaStyle: {} } : {}; const config = !index && dName.indexOf('流量') > -1 ? { areaStyle: {} } : {};
const style = index ? {lineStyle:{normal:{type:'dashed'}}} : {} const style = index ? { lineStyle: { normal: { type: 'dashed' } } } : {};
const list = { const list = {
name: dataInfo.name[index], name: dataInfo.name[index],
type: 'line', type: 'line',
smooth: true, smooth: true,
...config, ...config,
...style, ...style,
data: item.map((arr) => { data: item.map((arr) => {
...@@ -202,7 +251,7 @@ const StatisticalHistoryView = (props) => { ...@@ -202,7 +251,7 @@ const StatisticalHistoryView = (props) => {
grid: { grid: {
containLabel: true, containLabel: true,
left: 20, left: 20,
right: 10, right: 20,
// top: 20, // top: 20,
bottom: 10, bottom: 10,
}, },
...@@ -218,6 +267,13 @@ const StatisticalHistoryView = (props) => { ...@@ -218,6 +267,13 @@ const StatisticalHistoryView = (props) => {
axisTick: { axisTick: {
alignWithLabel: true, alignWithLabel: true,
}, },
boundaryGap: false,
splitLine: {
show: true,
lineStyle: {
type: 'dashed',
},
},
}, },
], ],
yAxis: [ yAxis: [
...@@ -255,7 +311,6 @@ const StatisticalHistoryView = (props) => { ...@@ -255,7 +311,6 @@ const StatisticalHistoryView = (props) => {
title: item, title: item,
dataIndex: dataIndex[index], dataIndex: dataIndex[index],
align: 'center', align: 'center',
// width: 60,
}; };
}); });
const column = column1.concat(column2); const column = column1.concat(column2);
...@@ -290,6 +345,24 @@ const StatisticalHistoryView = (props) => { ...@@ -290,6 +345,24 @@ const StatisticalHistoryView = (props) => {
} }
}; };
const Summary = (currentData) => {
return (
<Table.Summary.Row>
{columns.map((item, index) => {
let sum = 0;
currentData.reduce((prev, next) => {
sum += next[item.dataIndex] === '-' ? 0 : next[item.dataIndex];
}, 0);
return (
<Table.Summary.Cell key={item.dataIndex} index={index} align={'center'}>
{index === 0 ? '总计' : sum.toFixed(0)}
</Table.Summary.Cell>
);
})}
</Table.Summary.Row>
);
};
useEffect(() => { useEffect(() => {
setHistoryParams(props.deviceParams || {}); setHistoryParams(props.deviceParams || {});
}, [props.deviceParams]); }, [props.deviceParams]);
...@@ -313,6 +386,11 @@ const StatisticalHistoryView = (props) => { ...@@ -313,6 +386,11 @@ const StatisticalHistoryView = (props) => {
end = moment().endOf('month').format('YYYY-MM-DD 23:59:59'); end = moment().endOf('month').format('YYYY-MM-DD 23:59:59');
setPicker('month'); setPicker('month');
break; break;
case 'thisYear':
start = moment().startOf('year').subtract(2, 'year').format('YYYY-MM-DD 00:00:00');
end = moment().endOf('year').format('YYYY-MM-DD 23:59:59');
setPicker('year');
break;
case 'customer': case 'customer':
start = moment().startOf(picker).subtract(2, picker).format('YYYY-MM-DD 00:00:00'); start = moment().startOf(picker).subtract(2, picker).format('YYYY-MM-DD 00:00:00');
end = moment().endOf(picker).format('YYYY-MM-DD 23:59:59'); end = moment().endOf(picker).format('YYYY-MM-DD 23:59:59');
...@@ -331,32 +409,54 @@ const StatisticalHistoryView = (props) => { ...@@ -331,32 +409,54 @@ const StatisticalHistoryView = (props) => {
<div className={classNames(prefixCls)}> <div className={classNames(prefixCls)}>
<div className={classNames(`${prefixCls}-box`)}> <div className={classNames(`${prefixCls}-box`)}>
<div className={classNames(`${prefixCls}-header`)}> <div className={classNames(`${prefixCls}-header`)}>
<span>时间选择:</span> <div className={classNames(`${prefixCls}-time`)}>
<Radio.Group value={dateValue} defaultValue={dateList[0].key} onChange={onTimeChange}> <span>时间选择:</span>
{dateList.map((item) => ( <Radio.Group value={dateValue} defaultValue={dateList[0].key} onChange={onTimeChange}>
<Radio.Button key={item.key} value={item.key}> {dateList.map((item) => (
{item.name} <Radio.Button key={item.key} value={item.key}>
</Radio.Button> {item.name}
))} </Radio.Button>
</Radio.Group> ))}
{dateValue === 'customer' && ( </Radio.Group>
<> {dateValue === 'customer' && (
<Select <>
defaultValue="day" <Select
value={picker} defaultValue="day"
options={timeList} value={picker}
onChange={onPickerChange} options={timeList}
className={classNames(`${prefixCls}-select`)} onChange={onPickerChange}
/> className={classNames(`${prefixCls}-select`)}
<DatePicker onChange={onDateChange} value={moment(dateTime)} picker={picker} /> />
</> <DatePicker onChange={onDateChange} value={moment(dateTime)} picker={picker} />
)} </>
)}
</div>
<Button
className={classNames(`${prefixCls}-down-load`)}
type="primary"
onClick={exportExcelBtn}
disabled={!dataSource.length}
>
<VerticalAlignBottomOutlined />
下载
</Button>
</div> </div>
<div className={classNames(`${prefixCls}-content`)}> <div className={classNames(`${prefixCls}-content`)}>
{ {
<> <>
<div className={classNames(`${prefixCls}-chart`)}> <div className={classNames(`${prefixCls}-chart`)}>
<BasicChart ref={chartRef} option={options} notMerge style={{ width: '100%', height: '100%' }} /> {options ? (
<BasicChart
ref={chartRef}
option={options}
notMerge
style={{ width: '100%', height: '100%' }}
/>
) : (
<div className={classNames(`${prefixCls}-empty`)}>
<Empty />
</div>
)}
</div> </div>
<div className={classNames(`${prefixCls}-table`)}> <div className={classNames(`${prefixCls}-table`)}>
<BasicTable <BasicTable
...@@ -364,7 +464,32 @@ const StatisticalHistoryView = (props) => { ...@@ -364,7 +464,32 @@ const StatisticalHistoryView = (props) => {
columns={columns} columns={columns}
pagination={false} pagination={false}
bordered={true} bordered={true}
onRow={(record, index) => {
return {
onMouseEnter: (event) => {
let seriesIndex = 0;
const dataIndex = ['value0', 'value1', 'value2'];
seriesIndex = dataIndex.findIndex((item) => {
return record[item] !== '-';
});
chartRef?.current?.getEchartsInstance() &&
chartRef?.current?.getEchartsInstance().dispatchAction({
type: 'showTip',
seriesIndex: seriesIndex,
dataIndex: index,
});
}, // 鼠标移入行
onMouseLeave: (event) => {
chartRef?.current?.getEchartsInstance() &&
chartRef?.current?.getEchartsInstance().dispatchAction({
type: 'hideTip',
dataIndex: index,
});
}, // 鼠标移出行
};
}}
scroll={{ x: '100%', y: 'calc(100% - 40px)' }} scroll={{ x: '100%', y: 'calc(100% - 40px)' }}
summary={Summary}
/> />
</div> </div>
</> </>
...@@ -387,14 +512,18 @@ const dateList = [ ...@@ -387,14 +512,18 @@ const dateList = [
key: 'today', key: 'today',
name: '今日', name: '今日',
}, },
{ // {
key: 'thisWeek', // key: 'thisWeek',
name: '本周', // name: '本周',
}, // },
{ {
key: 'thisMonth', key: 'thisMonth',
name: '本月', name: '本月',
}, },
{
key: 'thisYear',
name: '今年',
},
{ {
key: 'customer', key: 'customer',
name: '自定义', name: '自定义',
...@@ -421,3 +550,5 @@ const dayName = ['今日', '昨日', '前日']; ...@@ -421,3 +550,5 @@ const dayName = ['今日', '昨日', '前日'];
const weekName = ['本周', '上周', '上上周']; const weekName = ['本周', '上周', '上上周'];
const monthName = ['本月', '上月', '上上月']; const monthName = ['本月', '上月', '上上月'];
const yearName = ['今年', '去年', '前年'];
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
width: 100%;
height: 100%;
} }
&-box { &-box {
...@@ -37,6 +39,19 @@ ...@@ -37,6 +39,19 @@
&-header { &-header {
flex: none; flex: none;
margin-bottom: 10px; margin-bottom: 10px;
display: flex;
align-items: center;
justify-content: space-between;
}
&-time {
display: flex;
align-items: center;
}
&-down-load {
display: flex;
align-items: center;
} }
&-select { &-select {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment