Commit 5dcb0d73 authored by 李纪文's avatar 李纪文

fix: 发布

parent 06ee06ea
{ {
"name": "@wisdom-components/ec_configurationview", "name": "@wisdom-components/ec_configurationview",
"version": "1.4.40", "version": "1.4.41",
"description": "> TODO: description", "description": "> TODO: description",
"author": "tuqian <webtuqian@163.com>", "author": "tuqian <webtuqian@163.com>",
"homepage": "", "homepage": "",
......
...@@ -24,7 +24,7 @@ let twoID = ''; ...@@ -24,7 +24,7 @@ let twoID = '';
let myDiagram = null; let myDiagram = null;
let editionArr = []; let editionArr = [];
// const guidAggre = {}; const guidAggre = {};
let bindData = []; let bindData = [];
const stationList = []; const stationList = [];
......
import React, {useContext, useEffect, useMemo, useState} from 'react'; import React, { useContext, useEffect, useMemo, useState } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import classNames from 'classnames'; import classNames from 'classnames';
import { import {
Checkbox, Checkbox,
ConfigProvider, ConfigProvider,
DatePicker, DatePicker,
Radio, Radio,
Select, Select,
Spin, Spin,
Tabs, Tabs,
Tooltip, Tooltip,
Button, Button,
} from 'antd'; } from 'antd';
import { import {
CloseCircleFilled, CloseCircleFilled,
PlusCircleOutlined, PlusCircleOutlined,
QuestionCircleFilled, QuestionCircleFilled,
DownloadOutlined, DownloadOutlined,
} from '@ant-design/icons'; } from '@ant-design/icons';
import moment from 'moment'; import moment from 'moment';
import _ from 'lodash'; import _ from 'lodash';
import TimeRangePicker from '@wisdom-components/timerangepicker'; import TimeRangePicker from '@wisdom-components/timerangepicker';
import PandaEmpty from '@wisdom-components/empty'; import PandaEmpty from '@wisdom-components/empty';
import BasicTable from '@wisdom-components/basictable'; import BasicTable from '@wisdom-components/basictable';
import {getHistoryInfo, getDeviceAlarmScheme, getExportDeviceHistoryUrl} from './apis'; import { getHistoryInfo, getDeviceAlarmScheme, getExportDeviceHistoryUrl } from './apis';
import SimgleChart from './SingleChart'; import SimgleChart from './SingleChart';
import GridChart from './GridChart'; import GridChart from './GridChart';
import './index.less'; import './index.less';
import {globalConfig} from 'antd/lib/config-provider'; import { globalConfig } from 'antd/lib/config-provider';
const {RangePicker} = DatePicker; const { RangePicker } = DatePicker;
const {Option} = Select; const { Option } = Select;
const startFormat = 'YYYY-MM-DD 00:00:00'; const startFormat = 'YYYY-MM-DD 00:00:00';
const endFormat = 'YYYY-MM-DD 23:59:59'; const endFormat = 'YYYY-MM-DD 23:59:59';
const timeFormat = 'YYYY-MM-DD HH:mm:ss'; const timeFormat = 'YYYY-MM-DD HH:mm:ss';
const dateFormat = 'YYYYMMDD'; const dateFormat = 'YYYYMMDD';
// 时间列表
const timeList = [ const timeList = [
{ {
key: 'twelveHours', key: 'twelveHours',
name: '近12小时', name: '近12小时',
}, },
{ {
key: 'roundClock', key: 'roundClock',
name: '近24小时', name: '近24小时',
}, },
{ {
key: 'oneWeek', key: 'oneWeek',
name: '近1周', name: '近1周',
}, },
{ {
key: 'oneMonth', key: 'oneMonth',
name: '近1月', name: '近1月',
}, },
]; ];
const CheckboxData = [ const CheckboxData = [
{ {
key: 'curveCenter', key: 'curveCenter',
label: '曲线居中', label: '曲线居中',
checked: false, checked: false,
showInCurve: true, showInCurve: true,
showInTable: false, showInTable: false,
}, },
{ {
key: 'chartGrid', key: 'chartGrid',
label: '图表网格', label: '图表网格',
checked: true, checked: true,
showInCurve: true, showInCurve: true,
showInTable: false, showInTable: false,
}, },
{ {
key: 'ignoreOutliers', key: 'ignoreOutliers',
label: '数据滤波', label: '数据滤波',
type: 'updateIgnoreOutliers', type: 'updateIgnoreOutliers',
checked: false, checked: false,
showInCurve: true, showInCurve: true,
showInTable: true, showInTable: true,
tooltip: '数据滤波针对与样本平均值相差2个标准差以上的值进行过滤。', tooltip: '数据滤波针对与样本平均值相差2个标准差以上的值进行过滤。',
}, },
{ {
key: 'justLine', key: 'justLine',
label: '仅查看曲线', label: '仅查看曲线',
type: '', type: '',
checked: false, checked: false,
showInCurve: false, showInCurve: false,
showInTable: false, showInTable: false,
}, },
{ {
key: 'dataThin', key: 'dataThin',
label: '数据抽稀', label: '数据抽稀',
type: 'updateDataThin', type: 'updateDataThin',
checked: true, checked: true,
showInCurve: false, showInCurve: false,
showInTable: true, showInTable: true,
}, },
]; ];
const timeIntervalList = [ const timeIntervalList = [
{ {
key: '5', key: '5',
zoom: '5', zoom: '5',
unit: 'min', unit: 'min',
name: '5分钟', name: '5分钟',
}, },
{ {
key: '10', key: '10',
zoom: '10', zoom: '10',
unit: 'min', unit: 'min',
name: '10分钟', name: '10分钟',
}, },
{ {
key: '30', key: '30',
zoom: '30', zoom: '30',
unit: 'min', unit: 'min',
name: '30分钟', name: '30分钟',
}, },
{ {
key: '1', key: '1',
zoom: '1', zoom: '1',
unit: 'h', unit: 'h',
name: '1小时', name: '1小时',
}, },
{ {
key: '2', key: '2',
zoom: '2', zoom: '2',
unit: 'h', unit: 'h',
name: '2小时', name: '2小时',
}, },
{ {
key: '4', key: '4',
zoom: '4', zoom: '4',
unit: 'h', unit: 'h',
name: '4小时', name: '4小时',
}, },
{ {
key: '6', key: '6',
zoom: '6', zoom: '6',
unit: 'h', unit: 'h',
name: '6小时', name: '6小时',
}, },
{ {
key: '12', key: '12',
zoom: '12', zoom: '12',
unit: 'h', unit: 'h',
name: '12小时', name: '12小时',
}, },
]; ];
const updateTime = (key) => { const updateTime = (key) => {
let start = ''; let start = '';
let end = ''; let end = '';
if (Array.isArray(key)) { if (Array.isArray(key)) {
start = moment(key[0]).format(timeFormat); start = moment(key[0]).format(timeFormat);
end = moment(key[1]).format(timeFormat); end = moment(key[1]).format(timeFormat);
} else { } else {
switch (key) { switch (key) {
case 'twelveHours': case 'twelveHours':
start = moment().subtract(12, 'hour').format(timeFormat); start = moment().subtract(12, 'hour').format(timeFormat);
end = moment().format(timeFormat); end = moment().format(timeFormat);
break; break;
case 'roundClock': case 'roundClock':
start = moment().subtract(24, 'hour').format(timeFormat); start = moment().subtract(24, 'hour').format(timeFormat);
end = moment().format(timeFormat); end = moment().format(timeFormat);
break; break;
case 'oneWeek': case 'oneWeek':
start = moment().subtract(7, 'day').format(timeFormat); start = moment().subtract(7, 'day').format(timeFormat);
end = moment().format(timeFormat); end = moment().format(timeFormat);
break; break;
case 'oneMonth': case 'oneMonth':
start = moment().subtract(30, 'day').format(timeFormat); start = moment().subtract(30, 'day').format(timeFormat);
end = moment().format(timeFormat); end = moment().format(timeFormat);
break; break;
}
} }
return [ }
{ return [
dateFrom: start, {
dateTo: end, dateFrom: start,
}, dateTo: end,
]; },
];
}; };
const DefaultDatePicker = (value) => [ const DefaultDatePicker = (value) => [
{ {
key: 1, key: 1,
value: moment(), value: moment(),
}, },
{ {
key: 2, key: 2,
value: moment().subtract(1, value), value: moment().subtract(1, value),
}, },
]; ];
const handleBatchTime = (arr, cOption) => { const handleBatchTime = (arr, cOption) => {
let newArr = []; let newArr = [];
arr.forEach((child) => { arr.forEach((child) => {
if (child.value) { if (child.value) {
newArr.push({ newArr.push({
dateFrom: moment(child.value).startOf(cOption).format(startFormat), dateFrom: moment(child.value).startOf(cOption).format(startFormat),
dateTo: moment(child.value).endOf(cOption).format(endFormat), dateTo: moment(child.value).endOf(cOption).format(endFormat),
}); });
} }
}); });
newArr = _.uniqWith(newArr, _.isEqual); // 去掉重复日期时间 newArr = _.uniqWith(newArr, _.isEqual); // 去掉重复日期时间
return newArr; return newArr;
}; };
const timeColumn = { const timeColumn = {
title: '采集时间', title: '采集时间',
dataIndex: 'time', dataIndex: 'time',
key: 'time', key: 'time',
width: 170, width: 170,
fixed: 'left', fixed: 'left',
ellipsis: true, ellipsis: true,
align: 'center', align: 'center',
}; };
const HistoryView = (props) => { const HistoryView = (props) => {
const {getPrefixCls} = useContext(ConfigProvider.ConfigContext); const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('history-view'); const prefixCls = getPrefixCls('history-view');
const { const {
title, title,
grid, grid,
defaultChecked, defaultChecked,
tableProps, tableProps,
deviceParams, deviceParams,
defaultModel, defaultModel,
showModels, showModels,
needMarkLine, needMarkLine,
} = props; } = props;
const isBoxPlots = deviceParams?.length === 1 && deviceParams[0]?.sensors?.split(',').length === 1; const isBoxPlots =
const [loading, setLoading] = useState(false); deviceParams?.length === 1 && deviceParams[0]?.sensors?.split(',').length === 1;
const [activeTabKey, setActiveTabKey] = useState(defaultModel); const [loading, setLoading] = useState(false);
const [activeTabKey, setActiveTabKey] = useState(defaultModel);
// 时间模式: 自定义模式/同期对比模式
const [timeValue, setTimeValue] = useState('customer'); // 时间模式: 自定义模式/同期对比模式
const [timeValue, setTimeValue] = useState('customer');
// 自定义模式
const [customerChecked, setCustomerChecked] = useState(defaultChecked); // 时间快速选择类型值 // 自定义模式
const [customerTime, setCustomerTime] = useState(); // 自定义时间选择值 const [customerChecked, setCustomerChecked] = useState(defaultChecked); // 时间快速选择类型值
const [customerTime, setCustomerTime] = useState(); // 自定义时间选择值
// 同期对比模式
const [contrastOption, setContrastOption] = useState('day'); // 对比时间类型: 日/月 // 同期对比模式
const [datePickerArr, setDatePickerArr] = useState(DefaultDatePicker('day')); // 对比时间段配置值 const [contrastOption, setContrastOption] = useState('day'); // 对比时间类型: 日/月
const [datePickerArr, setDatePickerArr] = useState(DefaultDatePicker('day')); // 对比时间段配置值
const [checkboxData, setCheckboxData] = useState(() => [...CheckboxData]); // 曲线设置项
const [dataThinKey, setDataThinKey] = useState(timeIntervalList[0].key); // 曲线抽稀时间设置 const [checkboxData, setCheckboxData] = useState(() => [...CheckboxData]); // 曲线设置项
const [dataThinKey, setDataThinKey] = useState(timeIntervalList[0].key); // 曲线抽稀时间设置
const [columns, setColumns] = useState([]);
const [tableData, setTableData] = useState([]); const [columns, setColumns] = useState([]);
const [chartDataSource, setChartDataSource] = useState([]); const [tableData, setTableData] = useState([]);
const [chartDataSource, setChartDataSource] = useState([]);
const [chartType, setChartType] = useState('lineChart');
// 选择的时间范围值 const [chartType, setChartType] = useState('lineChart');
const dateRange = useMemo(() => { // 选择的时间范围值
if (timeValue === 'customer') { const dateRange = useMemo(() => {
return updateTime(customerChecked || customerTime); if (timeValue === 'customer') {
} else { return updateTime(customerChecked || customerTime);
return handleBatchTime(datePickerArr, contrastOption); } else {
} return handleBatchTime(datePickerArr, contrastOption);
}, [contrastOption, customerChecked, customerTime, datePickerArr, timeValue]); }
}, [contrastOption, customerChecked, customerTime, datePickerArr, timeValue]);
const configDependence = checkboxData
.filter((item) => ['curveCenter', 'chartGrid'].indexOf(item.key) === -1) const configDependence = checkboxData
.map((item) => item.checked) .filter((item) => ['curveCenter', 'chartGrid'].indexOf(item.key) === -1)
.join(','); .map((item) => item.checked)
// 数据配置 .join(',');
const dataConfig = useMemo(() => { // 数据配置
const initial = { const dataConfig = useMemo(() => {
ignoreOutliers: false, const initial = {
dataThin: false, ignoreOutliers: false,
zoom: '', // 数据抽稀时间 dataThin: false,
unit: '', // 数据抽稀时间单位 zoom: '', // 数据抽稀时间
}; unit: '', // 数据抽稀时间单位
// 曲线居中,过滤异常值,数据抽稀
const config = checkboxData.reduce(
(pre, item) => (item.key !== 'curveCenter' && (pre[item.key] = item.checked), pre),
initial,
);
// 数据抽稀时间单位
const dataThin = timeIntervalList.find((item) => item.key === dataThinKey);
config.zoom = activeTabKey === 'curve' ? '' : dataThin?.zoom ?? '';
config.unit = activeTabKey === 'curve' ? '' : dataThin?.unit ?? '';
config.dataThin = activeTabKey === 'curve' ? true : config.dataThin; // 曲线强制抽稀
return config;
}, [configDependence, dataThinKey, activeTabKey]);
// 图表居中
const [curveCenter, chartGrid] = useMemo(() => {
const curveCenter = checkboxData.find((item) => item.key === 'curveCenter')?.checked;
const chartGrid = checkboxData.find((item) => item.key === 'chartGrid')?.checked;
return [curveCenter, chartGrid];
}, [checkboxData]);
// 自定义模式: 快速选择
const onCustomerTimeChange = (key) => {
setCustomerChecked(key);
!!customerTime && setCustomerTime(null);
}; };
// 曲线居中,过滤异常值,数据抽稀
const config = checkboxData.reduce(
(pre, item) => (item.key !== 'curveCenter' && (pre[item.key] = item.checked), pre),
initial,
);
// 数据抽稀时间单位
const dataThin = timeIntervalList.find((item) => item.key === dataThinKey);
config.zoom = activeTabKey === 'curve' ? '' : dataThin?.zoom ?? '';
config.unit = activeTabKey === 'curve' ? '' : dataThin?.unit ?? '';
config.dataThin = activeTabKey === 'curve' ? true : config.dataThin; // 曲线强制抽稀
return config;
}, [configDependence, dataThinKey, activeTabKey]);
// 图表居中
const [curveCenter, chartGrid] = useMemo(() => {
const curveCenter = checkboxData.find((item) => item.key === 'curveCenter')?.checked;
const chartGrid = checkboxData.find((item) => item.key === 'chartGrid')?.checked;
return [curveCenter, chartGrid];
}, [checkboxData]);
// 自定义模式: 快速选择
const onCustomerTimeChange = (key) => {
setCustomerChecked(key);
!!customerTime && setCustomerTime(null);
};
// 自定义模式: 自定义时间选择
const onCustomerRangeChange = (value) => {
if (!value) {
// 时间清空,回到默认时间选择
setCustomerChecked(defaultChecked);
setCustomerTime(value);
} else {
setCustomerChecked(null);
setCustomerTime(value);
}
};
// 自定义模式: 自定义时间选择 // 同期对比模式: 选择(日/月)
const onCustomerRangeChange = (value) => { const onContrastChange = (value) => {
if (!value) { setContrastOption(value);
// 时间清空,回到默认时间选择 setDatePickerArr([...DefaultDatePicker(value)]);
setCustomerChecked(defaultChecked); };
setCustomerTime(value);
} else {
setCustomerChecked(null);
setCustomerTime(value);
}
};
// 同期对比模式: 选择(日/月) // 同期对比模式: 时间段选择
const onContrastChange = (value) => { const onContrastPickerChange = (date, dateString, item) => {
setContrastOption(value); const arr = [...datePickerArr];
setDatePickerArr([...DefaultDatePicker(value)]); arr.forEach((child) => {
}; if (child.key === item.key) {
child.value = date;
}
});
setDatePickerArr(arr);
};
// 同期对比模式: 新增日期选择组件
const handleAddDatePicker = () => {
setDatePickerArr([
...datePickerArr,
{
key: datePickerArr[datePickerArr.length - 1].key + 1,
value: '',
},
]);
};
// 同期对比模式: 删除日期选择组件
const handleDeleteDatePicker = (index) => {
const arr = [...datePickerArr];
arr.splice(index, 1);
setDatePickerArr(arr);
};
// 时间设置切换(自定义/同期对比)
const onTimeSetChange = (e) => {
setTimeValue(e.target.value);
if (e.target.value === 'contrast') {
// 同期对比
onContrastChange(contrastOption);
} else {
// 自定义
// 不需要处理
}
};
// 同期对比模式: 时间段选择 const renderTimeOption = () => {
const onContrastPickerChange = (date, dateString, item) => { return (
const arr = [...datePickerArr]; <div className={classNames(`${prefixCls}-date`)}>
arr.forEach((child) => { <div className={classNames(`${prefixCls}-label`)}>时间选择</div>
if (child.key === item.key) { <Radio.Group value={timeValue} onChange={onTimeSetChange}>
child.value = date; <Radio.Button value="customer">自定义</Radio.Button>
} <Radio.Button value="contrast">同期对比</Radio.Button>
}); </Radio.Group>
setDatePickerArr(arr); {timeValue === 'customer' && ( // 自定义
}; <>
<TimeRangePicker
onChange={onCustomerTimeChange}
value={customerChecked}
dataSource={timeList}
/>
<RangePicker
className={classNames(`${prefixCls}-custime-customer`)}
onChange={onCustomerRangeChange}
value={customerTime}
showTime
/>
</>
)}
{timeValue === 'contrast' && ( // 同期对比
<>
<Select value={contrastOption} style={{ width: 60 }} onChange={onContrastChange}>
<Option value="day"></Option>
<Option value="month"></Option>
</Select>
{datePickerArr.map((child, index) => (
<div key={child.key} className={classNames(`${prefixCls}-contrast-list`)}>
<div className={classNames(`${prefixCls}-contrast-wrap`)}>
<DatePicker
picker={contrastOption}
value={child.value}
onChange={(date, dateString) => onContrastPickerChange(date, dateString, child)}
/>
{datePickerArr.length > 2 && (
<div
className={classNames(`${prefixCls}-contrast-delete`)}
onClick={() => handleDeleteDatePicker(index)}
>
<CloseCircleFilled />
</div>
)}
</div>
{index < datePickerArr.length - 1 && (
<div className={classNames(`${prefixCls}-contrast-connect`)}></div>
)}
</div>
))}
{datePickerArr.length < 5 && <PlusCircleOutlined onClick={handleAddDatePicker} />}
</>
)}
</div>
);
};
// 曲线设置项选择/取消
const onCheckboxChange = (e, key) => {
let data = [...checkboxData];
let _index = data.findIndex((item) => item.key === 'justLine'); // 仅查看曲线会在勾选了数据滤波后展示
let _index1 = data.findIndex((item) => item.key === 'ignoreOutliers'); // 仅查看曲线会在勾选了数据滤波后展示
data.forEach((item) => {
if (item.key === key) {
item.checked = e.target.checked;
}
});
if (key === 'ignoreOutliers') {
data[_index].showInCurve = e.target.checked;
data[_index].checked = e.target.checked;
}
if (key === 'chartType') {
data[_index1].showInCurve = e.target.value;
data[_index1].checked = false;
data[_index].showInCurve = false;
data[_index].checked = false;
}
setCheckboxData(data);
};
// 同期对比模式: 新增日期选择组件 // 数据抽稀时间间隔
const handleAddDatePicker = () => { const onTimeIntervalChange = (value) => {
setDatePickerArr([ setDataThinKey(value);
...datePickerArr, };
{
key: datePickerArr[datePickerArr.length - 1].key + 1,
value: '',
},
]);
};
// 同期对比模式: 删除日期选择组件 const renderCheckbox = (child) => {
const handleDeleteDatePicker = (index) => { const curveAccess = activeTabKey === 'curve' && child.showInCurve;
const arr = [...datePickerArr]; const tableAccess = activeTabKey === 'table' && child.showInTable;
arr.splice(index, 1); const gridOptions = ['curveCenter'];
setDatePickerArr(arr);
};
// 时间设置切换(自定义/同期对比) if (grid && curveAccess && gridOptions.indexOf(child.key) === -1) return null;
const onTimeSetChange = (e) => { return (
setTimeValue(e.target.value); (curveAccess || tableAccess) && (
if (e.target.value === 'contrast') { <>
// 同期对比 <Checkbox checked={child.checked} onChange={(e) => onCheckboxChange(e, child.key)}>
onContrastChange(contrastOption); {child.label}
} else { </Checkbox>
// 自定义 {child.tooltip && (
// 不需要处理 <Tooltip title={child.tooltip}>
} <QuestionCircleFilled className={`${prefixCls}-question`} />
}; </Tooltip>
)}
</>
)
);
};
const renderTimeOption = () => { const renderCurveOption = (isChart, isSingle) => {
return ( return (
<div className={classNames(`${prefixCls}-date`)}> <div className={classNames(`${prefixCls}-cover`)}>
<div className={classNames(`${prefixCls}-label`)}>时间选择</div> {isChart && isSingle ? (
<Radio.Group value={timeValue} onChange={onTimeSetChange}> <>
<Radio.Button value="customer">自定义</Radio.Button> <div className={classNames(`${prefixCls}-label`)}>曲线形态</div>
<Radio.Button value="contrast">同期对比</Radio.Button> <Radio.Group
</Radio.Group> value={chartType}
{timeValue === 'customer' && ( // 自定义 style={{ marginRight: 16 }}
<> onChange={(e) => {
<TimeRangePicker let _value = e.target.value;
onChange={onCustomerTimeChange} setChartType(_value);
value={customerChecked} onCheckboxChange({ target: { value: _value !== 'boxChart' } }, 'chartType');
dataSource={timeList} }}
/> >
<RangePicker <Radio.Button value={'lineChart'}>线形图</Radio.Button>
className={classNames(`${prefixCls}-custime-customer`)} <Radio.Button value={'boxChart'}>箱线图</Radio.Button>
onChange={onCustomerRangeChange} </Radio.Group>
value={customerTime} </>
showTime ) : (
/> ''
</> )}
)} <div className={classNames(`${prefixCls}-label`)}>曲线设置</div>
{timeValue === 'contrast' && ( // 同期对比 {checkboxData.map((child) => {
<> const box = renderCheckbox(child);
<Select value={contrastOption} style={{width: 60}} onChange={onContrastChange}> if (!box) return null;
<Option value="day"></Option> return (
<Option value="month"></Option> <div key={child.key} className={`${prefixCls}-cover-item`}>
</Select> {box}
{datePickerArr.map((child, index) => (
<div key={child.key} className={classNames(`${prefixCls}-contrast-list`)}>
<div className={classNames(`${prefixCls}-contrast-wrap`)}>
<DatePicker
picker={contrastOption}
value={child.value}
onChange={(date, dateString) => onContrastPickerChange(date, dateString, child)}
/>
{datePickerArr.length > 2 && (
<div
className={classNames(`${prefixCls}-contrast-delete`)}
onClick={() => handleDeleteDatePicker(index)}
>
<CloseCircleFilled/>
</div>
)}
</div>
{index < datePickerArr.length - 1 && (
<div className={classNames(`${prefixCls}-contrast-connect`)}></div>
)}
</div>
))}
{datePickerArr.length < 5 && <PlusCircleOutlined onClick={handleAddDatePicker}/>}
</>
)}
</div> </div>
); );
}; })}
{activeTabKey === 'table' && (
<Select
value={dataThinKey}
style={{ width: 90 }}
onChange={onTimeIntervalChange}
disabled={!dataConfig.dataThin}
>
{timeIntervalList.map((child) => (
<Option key={child.key} unit={child.unit} value={child.key}>
{child.name}
</Option>
))}
</Select>
)}
</div>
);
};
const exportExcelBtn = () => {
deviceParams.forEach((i, r) => {
let timeFrom = dateRange[r]?.dateFrom || moment().format(startFormat);
let timeTo = dateRange[r]?.dateTo || moment().format(timeFormat);
let fileName = `数据报表-${i.deviceType}-${i.deviceCode}-${moment(timeFrom).format(
dateFormat,
)}${moment(timeTo).format(dateFormat)}`;
getExportDeviceHistoryUrl({
deviceType: i.deviceType,
deviceCode: i.deviceCode,
quotas: i.sensors,
startTime: timeFrom,
endTime: timeTo,
fileName: fileName,
})
.then((res) => {
if (res && res.code === -1) return message.error(res.msg);
const url = `${window.location.origin}/PandaCore/GCK/FileHandleContoller/Download/name?name=${res.data}&_site=${globalConfig?.userInfo?.site}`;
const aDom = document.createElement('a');
aDom.href = url;
aDom.click();
aDom.remove();
})
.catch((err) => {});
});
};
// 曲线设置项选择/取消 const handleTableData = (data) => {
const onCheckboxChange = (e, key) => { const ignoreOutliers = checkboxData.find((item) => item.key === 'ignoreOutliers').checked;
let data = [...checkboxData]; const dataIndexAccess = (dataItem, index) => {
let _index = data.findIndex(item => item.key === 'justLine'); // 仅查看曲线会在勾选了数据滤波后展示 const { stationCode, sensorName } = dataItem;
let _index1 = data.findIndex(item => item.key === 'ignoreOutliers'); // 仅查看曲线会在勾选了数据滤波后展示 return `${stationCode}-${sensorName}-${index}`;
data.forEach((item) => {
if (item.key === key) {
item.checked = e.target.checked;
}
});
if (key === 'ignoreOutliers') {
data[_index].showInCurve = e.target.checked;
data[_index].checked = e.target.checked;
}
if (key === 'chartType') {
data[_index1].showInCurve = e.target.value;
data[_index1].checked = false;
data[_index].showInCurve = false;
data[_index].checked = false;
}
setCheckboxData(data);
}; };
// 数据抽稀时间间隔 let format = timeFormat;
const onTimeIntervalChange = (value) => { if (timeValue === 'contrast') {
setDataThinKey(value); format = contrastOption === 'day' ? '2020-01-01 HH:mm:00' : '2020-01-DD HH:mm:00';
}; }
const renderCheckbox = (child) => { // 处理表头数据
const curveAccess = activeTabKey === 'curve' && child.showInCurve; const columnsData = data.map((item, index) => {
const tableAccess = activeTabKey === 'table' && child.showInTable; const { stationCode, equipmentName, sensorName, unit, dataModel } = item;
const gridOptions = ['curveCenter']; const dataIndex = dataIndexAccess(item, index);
let col = {
if (grid && curveAccess && gridOptions.indexOf(child.key) === -1) return null; title: `${equipmentName}-${sensorName}${unit ? `(${unit})` : ''}`,
return ( dataIndex: dataIndex,
(curveAccess || tableAccess) && ( key: dataIndex,
<> ellipsis: true,
<Checkbox checked={child.checked} onChange={(e) => onCheckboxChange(e, child.key)}> align: 'center',
{child.label} };
</Checkbox> // 同期对比
{child.tooltip && ( if (timeValue === 'contrast' && dataModel[0]) {
<Tooltip title={child.tooltip}> const time = item.dataModel[0].pt
<QuestionCircleFilled className={`${prefixCls}-question`}/> .slice(0, contrastOption === 'day' ? 10 : 7)
</Tooltip> .replace(/-/g, '');
)} col.title = `${equipmentName}-${sensorName}-${time}`;
</> }
) return col;
); });
};
const renderCurveOption = (isChart, isSingle) => { // 格式化时间对齐数据, 生成行数
return ( const timeData = {};
<div className={classNames(`${prefixCls}-cover`)}>
{
isChart && isSingle ? <>
<div className={classNames(`${prefixCls}-label`)}>曲线形态</div>
<Radio.Group value={chartType} style={{marginRight: 16}} onChange={(e) => {
let _value = e.target.value;
setChartType(_value);
onCheckboxChange({target: {value: _value !== 'boxChart'}}, 'chartType')
}}>
<Radio.Button value={'lineChart'}>线形图</Radio.Button>
<Radio.Button value={'boxChart'}>箱线图</Radio.Button>
</Radio.Group></> : ''
}
<div className={classNames(`${prefixCls}-label`)}>曲线设置</div>
{checkboxData.map((child) => {
const box = renderCheckbox(child);
if (!box) return null;
return (
<div key={child.key} className={`${prefixCls}-cover-item`}>
{box}
</div>
);
})}
{activeTabKey === 'table' && (
<Select
value={dataThinKey}
style={{width: 90}}
onChange={onTimeIntervalChange}
disabled={!dataConfig.dataThin}
>
{timeIntervalList.map((child) => (
<Option key={child.key} unit={child.unit} value={child.key}>
{child.name}
</Option>
))}
</Select>
)}
</div>
);
};
const exportExcelBtn = () => { const buildDefaultData = (time) => {
deviceParams.forEach((i, r) => { const obj = { key: time, time: time };
let timeFrom = dateRange[r]?.dateFrom || moment().format(startFormat); data.forEach((item, index) => {
let timeTo = dateRange[r]?.dateTo || moment().format(timeFormat); const dataIndex = dataIndexAccess(item, index);
let fileName = `数据报表-${i.deviceType}-${i.deviceCode}-${moment(timeFrom).format( obj[dataIndex] = '';
dateFormat, });
)}${moment(timeTo).format(dateFormat)}`; return obj;
getExportDeviceHistoryUrl({
deviceType: i.deviceType,
deviceCode: i.deviceCode,
quotas: i.sensors,
startTime: timeFrom,
endTime: timeTo,
fileName: fileName,
})
.then((res) => {
if (res && res.code === -1) return message.error(res.msg);
const url = `${window.location.origin}/PandaCore/GCK/FileHandleContoller/Download/name?name=${res.data}&_site=${globalConfig?.userInfo?.site}`;
const aDom = document.createElement('a');
aDom.href = url;
aDom.click();
aDom.remove();
})
.catch((err) => {
});
});
}; };
data.forEach((item, index) => {
const { stationCode, sensorName, dataModel } = item;
dataModel.forEach((data) => {
const formatTime = moment(data.pt).format(format);
const handleTableData = (data) => { let time = formatTime;
const ignoreOutliers = checkboxData.find((item) => item.key === 'ignoreOutliers').checked;
const dataIndexAccess = (dataItem, index) => {
const {stationCode, sensorName} = dataItem;
return `${stationCode}-${sensorName}-${index}`;
};
let format = timeFormat;
if (timeValue === 'contrast') { if (timeValue === 'contrast') {
format = contrastOption === 'day' ? '2020-01-01 HH:mm:00' : '2020-01-DD HH:mm:00'; time = time.slice(contrastOption === 'day' ? 11 : 8, 16);
} }
// 处理表头数据 timeData[formatTime] = timeData[formatTime] || buildDefaultData(time);
const columnsData = data.map((item, index) => { });
const {stationCode, equipmentName, sensorName, unit, dataModel} = item; });
const dataIndex = dataIndexAccess(item, index);
let col = {
title: `${equipmentName}-${sensorName}${unit ? `(${unit})` : ''}`,
dataIndex: dataIndex,
key: dataIndex,
ellipsis: true,
align: 'center',
};
// 同期对比
if (timeValue === 'contrast' && dataModel[0]) {
const time = item.dataModel[0].pt
.slice(0, contrastOption === 'day' ? 10 : 7)
.replace(/-/g, '');
col.title = `${equipmentName}-${sensorName}-${time}`;
}
return col;
});
// 格式化时间对齐数据, 生成行数
const timeData = {};
const buildDefaultData = (time) => {
const obj = {key: time, time: time};
data.forEach((item, index) => {
const dataIndex = dataIndexAccess(item, index);
obj[dataIndex] = '';
});
return obj;
};
data.forEach((item, index) => {
const {stationCode, sensorName, dataModel} = item;
dataModel.forEach((data) => {
const formatTime = moment(data.pt).format(format);
let time = formatTime;
if (timeValue === 'contrast') {
time = time.slice(contrastOption === 'day' ? 11 : 8, 16);
}
timeData[formatTime] = timeData[formatTime] || buildDefaultData(time);
});
});
// 处理表格数据
data.forEach((child, index) => {
const {dataModel} = child;
const dataIndex = dataIndexAccess(child, index);
dataModel.forEach((value, j) => {
const formatTime = moment(value.pt).format(format);
const dataRow = timeData[formatTime];
if (dataRow) {
dataRow[dataIndex] = value.pv === null || value.pv === undefined ? '' : value.pv;
}
});
});
const timeSort = (a, b) => {
let aa = a,
bb = b;
if (timeValue === 'contrast') {
aa = a.slice(contrastOption === 'day' ? 11 : 8, 16);
bb = b.slice(contrastOption === 'day' ? 11 : 8, 16);
}
return aa.localeCompare(bb);
};
const times = Object.keys(timeData).sort(timeSort);
const tableData = times.map((time) => timeData[time]);
setColumns([timeColumn, ...columnsData]);
setTableData(tableData);
};
const [deviceAlarmSchemes, setDeviceAlarmSchemes] = useState([]);
const beforChangeParams = (value = {}) => {
if (!needMarkLine) return Promise.resolve();
return getDeviceAlarmScheme({
data: deviceParams.map((item) => ({
deviceType: item.deviceType,
deviceCode: item.deviceCode,
pointAddressID: item.pointAddressID,
sensorName: item.sensors,
})),
})
.then((res) => {
if (res.code === 0) setDeviceAlarmSchemes(res.data || []);
else setDeviceAlarmSchemes([]);
return Promise.resolve();
})
.catch((err) => {
setDeviceAlarmSchemes([]);
return Promise.resolve();
});
};
const handleDataThinKey = (diffDays) => {
// edit by zy 根据选择的时长控制抽稀频度
if (diffDays >= 7 && diffDays < 15) {
return {unit: 'h', zoom: '2'};
} else if (diffDays >= 15 && diffDays < 30) {
return {unit: 'h', zoom: '4'};
} else if (diffDays >= 30) {
return {unit: 'h', zoom: '6'};
} else if (diffDays < 7 && diffDays >= 2) {
return {unit: 'min', zoom: '40'};
} else if (diffDays < 2 && diffDays >= 1) {
return {unit: 'min', zoom: '30'};
} else {
return {unit: 'min', zoom: '10'};
}
};
// 处理接口服务参数的变化 // 处理表格数据
const onChangeParams = (value = {}) => { data.forEach((child, index) => {
const {dateRange, isDilute, ignoreOutliers, zoom, unit} = value; const { dataModel } = child;
const requestArr = []; const dataIndex = dataIndexAccess(child, index);
const acrossTables = []; dataModel.forEach((value, j) => {
deviceParams.forEach((i) => { const formatTime = moment(value.pt).format(format);
if (i.sensors && i.deviceCode && i.deviceCode) const dataRow = timeData[formatTime];
acrossTables.push(_.omit(i, ['pointAddressID'])); if (dataRow) {
}); dataRow[dataIndex] = value.pv === null || value.pv === undefined ? '' : value.pv;
if (!acrossTables?.length) {
handleTableData([]);
setChartDataSource([]);
return;
} }
dateRange.forEach((item) => { });
let _showLine = checkboxData.find(item => item.key === 'justLine'); });
const param = { const timeSort = (a, b) => {
isDilute, let aa = a,
zoom, bb = b;
unit, if (timeValue === 'contrast') {
ignoreOutliers, aa = a.slice(contrastOption === 'day' ? 11 : 8, 16);
// isVertical: false, // 是否查询竖表 bb = b.slice(contrastOption === 'day' ? 11 : 8, 16);
dateFrom: item.dateFrom, }
dateTo: item.dateTo, return aa.localeCompare(bb);
acrossTables,
isBoxPlots: isBoxPlots
};
let diffDays = moment(item.dateTo).diff(moment(item.dateFrom), 'days');
let zoomParam = activeTabKey === 'curve' ? handleDataThinKey(diffDays) : {};
requestArr.push(getHistoryInfo({...param, ...zoomParam}));
});
setLoading(true);
Promise.all(requestArr).then((results) => {
if (results.length) {
let data = [];
results.forEach((res, index) => {
const {dateFrom, dateTo} = dateRange?.[index] ?? {};
if (res.code === 0 && res.data.length) {
debugger
res.data.forEach((d) => {
d.dateFrom = dateFrom;
d.dateTo = dateTo;
});
deviceParams.forEach((p) => {
// 返回数据按查询指标顺序排序
const sensors = p.sensors?.split(',') ?? [];
const list = sensors.map((s) => {
const dataItem = res.data.find(
(d) => d.stationCode === p.deviceCode && d.sensorName === s,
);
dataItem.dateFrom = dateFrom;
dataItem.dateTo = dateTo;
return dataItem;
});
data = data.concat(list);
});
}
});
setLoading(false);
handleTableData(data);
setChartDataSource(data);
}
});
}; };
const times = Object.keys(timeData).sort(timeSort);
useEffect(() => { const tableData = times.map((time) => timeData[time]);
const {dataThin, ignoreOutliers, zoom, unit} = dataConfig; setColumns([timeColumn, ...columnsData]);
beforChangeParams().finally(() => { setTableData(tableData);
onChangeParams({ };
isDilute: dataThin,
ignoreOutliers, const [deviceAlarmSchemes, setDeviceAlarmSchemes] = useState([]);
zoom, const beforChangeParams = (value = {}) => {
unit, if (!needMarkLine) return Promise.resolve();
dateRange, return getDeviceAlarmScheme({
isBoxPlots: isBoxPlots data: deviceParams.map((item) => ({
deviceType: item.deviceType,
deviceCode: item.deviceCode,
pointAddressID: item.pointAddressID,
sensorName: item.sensors,
})),
})
.then((res) => {
if (res.code === 0) setDeviceAlarmSchemes(res.data || []);
else setDeviceAlarmSchemes([]);
return Promise.resolve();
})
.catch((err) => {
setDeviceAlarmSchemes([]);
return Promise.resolve();
});
};
const handleDataThinKey = (diffDays) => {
// edit by zy 根据选择的时长控制抽稀频度
if (diffDays >= 7 && diffDays < 15) {
return { unit: 'h', zoom: '2' };
} else if (diffDays >= 15 && diffDays < 30) {
return { unit: 'h', zoom: '4' };
} else if (diffDays >= 30) {
return { unit: 'h', zoom: '6' };
} else if (diffDays < 7 && diffDays >= 2) {
return { unit: 'min', zoom: '40' };
} else if (diffDays < 2 && diffDays >= 1) {
return { unit: 'min', zoom: '30' };
} else {
return { unit: 'min', zoom: '10' };
}
};
// 处理接口服务参数的变化
const onChangeParams = (value = {}) => {
const { dateRange, isDilute, ignoreOutliers, zoom, unit } = value;
const requestArr = [];
const acrossTables = [];
deviceParams.forEach((i) => {
if (i.sensors && i.deviceCode && i.deviceCode)
acrossTables.push(_.omit(i, ['pointAddressID']));
});
if (!acrossTables?.length) {
handleTableData([]);
setChartDataSource([]);
return;
}
dateRange.forEach((item) => {
let _showLine = checkboxData.find((item) => item.key === 'justLine');
const param = {
isDilute,
zoom,
unit,
ignoreOutliers,
// isVertical: false, // 是否查询竖表
dateFrom: item.dateFrom,
dateTo: item.dateTo,
acrossTables,
isBoxPlots: isBoxPlots,
};
let diffDays = moment(item.dateTo).diff(moment(item.dateFrom), 'days');
let zoomParam = activeTabKey === 'curve' ? handleDataThinKey(diffDays) : {};
requestArr.push(getHistoryInfo({ ...param, ...zoomParam }));
});
setLoading(true);
Promise.all(requestArr).then((results) => {
if (results.length) {
let data = [];
results.forEach((res, index) => {
const { dateFrom, dateTo } = dateRange?.[index] ?? {};
if (res.code === 0 && res.data.length) {
debugger;
res.data.forEach((d) => {
d.dateFrom = dateFrom;
d.dateTo = dateTo;
});
deviceParams.forEach((p) => {
// 返回数据按查询指标顺序排序
const sensors = p.sensors?.split(',') ?? [];
const list = sensors.map((s) => {
const dataItem = res.data.find(
(d) => d.stationCode === p.deviceCode && d.sensorName === s,
);
dataItem.dateFrom = dateFrom;
dataItem.dateTo = dateTo;
return dataItem;
});
data = data.concat(list);
}); });
}
}); });
}, [dateRange, dataConfig, deviceParams, chartType]); setLoading(false);
handleTableData(data);
const renderPanel = (model) => { setChartDataSource(data);
if (model === 'curve') { }
return ( });
<> };
<div className={`${prefixCls}-options`}>
{renderTimeOption()} useEffect(() => {
{renderCurveOption(true, (deviceParams?.length === 1 && deviceParams[0]?.sensors?.split(',').length === 1))} const { dataThin, ignoreOutliers, zoom, unit } = dataConfig;
</div> beforChangeParams().finally(() => {
<div className={`${prefixCls}-content`}> onChangeParams({
{!chartDataSource.length ? ( isDilute: dataThin,
<PandaEmpty/> ignoreOutliers,
) : grid === true ? ( zoom,
<GridChart unit,
curveCenter={curveCenter} dateRange,
prefixCls={prefixCls} isBoxPlots: isBoxPlots,
dataSource={chartDataSource} });
contrast={timeValue === 'contrast'} });
contrastOption={contrastOption} }, [dateRange, dataConfig, deviceParams, chartType]);
deviceAlarmSchemes={deviceAlarmSchemes}
/> const renderPanel = (model) => {
) : ( if (model === 'curve') {
<SimgleChart return (
curveCenter={curveCenter} <>
showGridLine={chartGrid} <div className={`${prefixCls}-options`}>
prefixCls={prefixCls} {renderTimeOption()}
dataSource={chartDataSource} {renderCurveOption(
justLine={!!checkboxData.find(item => item.key === 'justLine' && item.checked)} true,
chartType={isBoxPlots ? chartType : null} deviceParams?.length === 1 && deviceParams[0]?.sensors?.split(',').length === 1,
contrast={timeValue === 'contrast'} )}
contrastOption={contrastOption} </div>
deviceAlarmSchemes={deviceAlarmSchemes} <div className={`${prefixCls}-content`}>
/> {!chartDataSource.length ? (
)} <PandaEmpty />
</div> ) : grid === true ? (
</> <GridChart
); curveCenter={curveCenter}
} prefixCls={prefixCls}
if (model === 'table') { dataSource={chartDataSource}
return ( contrast={timeValue === 'contrast'}
<> contrastOption={contrastOption}
<div className={`${prefixCls}-options`}> deviceAlarmSchemes={deviceAlarmSchemes}
{renderTimeOption()} />
{renderCurveOption()} ) : (
</div> <SimgleChart
<div className={`${prefixCls}-content`}> curveCenter={curveCenter}
{chartDataSource.length > 0 ? ( showGridLine={chartGrid}
<BasicTable prefixCls={prefixCls}
dataSource={tableData} dataSource={chartDataSource}
columns={columns} justLine={!!checkboxData.find((item) => item.key === 'justLine' && item.checked)}
{...tableProps} chartType={isBoxPlots ? chartType : null}
pagination={false} contrast={timeValue === 'contrast'}
onChange={() => { contrastOption={contrastOption}
}} deviceAlarmSchemes={deviceAlarmSchemes}
/> />
) : ( )}
<PandaEmpty/> </div>
)} </>
</div> );
</> }
); if (model === 'table') {
} return (
}; <>
<div className={`${prefixCls}-options`}>
return ( {renderTimeOption()}
<div className={classNames(prefixCls)}> {renderCurveOption()}
<Spin spinning={loading} wrapperClassName={classNames(`${prefixCls}-spin`)}> </div>
{showModels.length === 1 && ( <div className={`${prefixCls}-content`}>
<div className={`${prefixCls}-single-panel`}>{renderPanel(showModels[0])}</div> {chartDataSource.length > 0 ? (
)} <BasicTable
{showModels.length > 1 && ( dataSource={tableData}
<Tabs columns={columns}
activeKey={activeTabKey} {...tableProps}
onChange={(key) => setActiveTabKey(key)} pagination={false}
centered onChange={() => {}}
tabBarExtraContent={{ />
left: <h3>{title}</h3>, ) : (
right: ( <PandaEmpty />
<div className={`${prefixCls}-extra-right`}> )}
{activeTabKey === 'table' && ( </div>
<Button type="link" onClick={exportExcelBtn}> </>
<DownloadOutlined/> );
下载 }
</Button> };
)}
</div> return (
), <div className={classNames(prefixCls)}>
}} <Spin spinning={loading} wrapperClassName={classNames(`${prefixCls}-spin`)}>
> {showModels.length === 1 && (
<Tabs.TabPane key="curve" tab="曲线"> <div className={`${prefixCls}-single-panel`}>{renderPanel(showModels[0])}</div>
{renderPanel('curve')} )}
</Tabs.TabPane> {showModels.length > 1 && (
<Tabs.TabPane key="table" tab="表格"> <Tabs
{renderPanel('table')} activeKey={activeTabKey}
</Tabs.TabPane> onChange={(key) => setActiveTabKey(key)}
</Tabs> centered
)} tabBarExtraContent={{
</Spin> left: <h3>{title}</h3>,
</div> right: (
); <div className={`${prefixCls}-extra-right`}>
{activeTabKey === 'table' && (
<Button type="link" onClick={exportExcelBtn}>
<DownloadOutlined />
下载
</Button>
)}
</div>
),
}}
>
<Tabs.TabPane key="curve" tab="曲线">
{renderPanel('curve')}
</Tabs.TabPane>
<Tabs.TabPane key="table" tab="表格">
{renderPanel('table')}
</Tabs.TabPane>
</Tabs>
)}
</Spin>
</div>
);
}; };
HistoryView.propTypes = { HistoryView.propTypes = {
grid: PropTypes.bool, grid: PropTypes.bool,
title: PropTypes.string, title: PropTypes.string,
defaultChecked: PropTypes.oneOf(['twelveHours', 'roundClock', 'oneWeek', 'oneMonth']), defaultChecked: PropTypes.oneOf(['twelveHours', 'roundClock', 'oneWeek', 'oneMonth']),
tableProps: PropTypes.object, tableProps: PropTypes.object,
deviceParams: PropTypes.arrayOf( deviceParams: PropTypes.arrayOf(
PropTypes.objectOf({ PropTypes.objectOf({
deviceCode: PropTypes.string, deviceCode: PropTypes.string,
sensors: PropTypes.string, sensors: PropTypes.string,
deviceType: PropTypes.string, deviceType: PropTypes.string,
pointAddressID: PropTypes.number, // 可选,配置了将会查询相关报警方案配置 pointAddressID: PropTypes.number, // 可选,配置了将会查询相关报警方案配置
}), }),
), ),
defaultModel: PropTypes.oneOf(['curve', 'table']), defaultModel: PropTypes.oneOf(['curve', 'table']),
showModels: PropTypes.arrayOf(PropTypes.oneOf(['curve', 'table'])), showModels: PropTypes.arrayOf(PropTypes.oneOf(['curve', 'table'])),
}; };
HistoryView.defaultProps = { HistoryView.defaultProps = {
grid: false, grid: false,
title: '指标曲线', title: '指标曲线',
defaultChecked: 'roundClock', defaultChecked: 'roundClock',
tableProps: {}, tableProps: {},
defaultModel: 'curve', defaultModel: 'curve',
showModels: ['curve', 'table'], showModels: ['curve', 'table'],
needMarkLine: true, needMarkLine: true,
}; };
export default HistoryView; export default HistoryView;
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