Commit 98e4d154 authored by 涂茜's avatar 涂茜

fix: 历史曲线新增数据字典配置颜色

parent e6c0f9b1
Pipeline #27629 failed with stages
in 17 seconds
...@@ -60,6 +60,7 @@ const DeviceTree = (props) => { ...@@ -60,6 +60,7 @@ const DeviceTree = (props) => {
setTreeData(newData); setTreeData(newData);
setTotal(response.data.totalPages); setTotal(response.data.totalPages);
onTreeCheck([newData[0]]); onTreeCheck([newData[0]]);
onTreeSelect([newData[0]]);
} else { } else {
message.error(response.msg); message.error(response.msg);
} }
......
...@@ -4,11 +4,17 @@ import HistoryInfo from '../index'; ...@@ -4,11 +4,17 @@ import HistoryInfo from '../index';
const REQUEST_HTTP = 'http'; const REQUEST_HTTP = 'http';
const REQUEST_METHOD_POST = 'post'; const REQUEST_METHOD_POST = 'post';
const REQUEST_METHOD_GET = 'get';
const GET_HISTORY_INFO = const GET_HISTORY_INFO =
'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/Publish/Monitor/Device/SensorsDataForStation'; //获取历史信息 'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/PandaCore/Monitor/Device/SensorsDataForStation'; //获取历史信息
// const GET_HISTORY_INFO = '/api/Publish/GCK/Device/SensorsDataForStation'; //获取历史信息 const GET_DICTIONARY_LIST =
'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api/PandaCore/OMS/Data/GetDataDictionaryList'; //获取数据字典信息
// const GET_HISTORY_INFO = '/api/PandaCore/GCK/Device/SensorsDataForStation'; //获取历史信息
// const GET_DICTIONARY_LIST = '/api/PandaCore/OMS/Data/GetDataDictionaryList'; //获取数据字典信息
const historyInfoService = { const historyInfoService = {
getHistoryInfo: { getHistoryInfo: {
...@@ -16,11 +22,17 @@ const historyInfoService = { ...@@ -16,11 +22,17 @@ const historyInfoService = {
method: REQUEST_METHOD_POST, method: REQUEST_METHOD_POST,
type: REQUEST_HTTP, type: REQUEST_HTTP,
}, },
getDictionaryList: {
url: GET_DICTIONARY_LIST,
method: REQUEST_METHOD_GET,
type: REQUEST_HTTP,
},
}; };
const hsService = service(historyInfoService); const hsService = service(historyInfoService);
const getHistoryInfo = hsService.getHistoryInfo; const getHistoryInfo = hsService.getHistoryInfo;
const getDictionaryList = hsService.getDictionaryList;
const Demo = () => { const Demo = () => {
return ( return (
...@@ -30,6 +42,8 @@ const Demo = () => { ...@@ -30,6 +42,8 @@ const Demo = () => {
tableProps={{ bordered: true, pagination: { pageSize: 20 } }} tableProps={{ bordered: true, pagination: { pageSize: 20 } }}
historyInfoService={getHistoryInfo} historyInfoService={getHistoryInfo}
historyInfoParams={initialParams} historyInfoParams={initialParams}
dictionaryService={getDictionaryList}
dictionaryParams={{ nodeID: 149 }}
/> />
</div> </div>
); );
......
...@@ -110,6 +110,81 @@ const DefaultDatePicker = (value) => [ ...@@ -110,6 +110,81 @@ const DefaultDatePicker = (value) => [
}, },
]; ];
const DefaultOptions = (color, contrastOption) => ({
chart: {
zoomType: 'x',
backgroundColor: 'rgba(255, 255, 255, 0.5)',
},
colors: color,
title: null,
credits: false,
rangeSelector: {
enabled: false,
},
xAxis: [
{
lineWidth: 0,
crosshair: true,
type: 'datetime',
gridLineDashStyle: 'dash',
gridLineWidth: 1,
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%d',
week: '%d',
month: '%d',
year: '%Y',
},
},
],
yAxis: [],
tooltip: {
shared: true,
split: false,
valueDecimals: 3,
formatter: function () {
let html = `<b>${Highcharts.dateFormat(
contrastOption === 'day' ? '%H:%M' : '%d %H:%M',
this.x,
)}</b><br/>`;
this.points.forEach((item) => {
html += `<span style={{color: ${item.series.color}}}>${item.series.name}</span>:
<b>${
item.point.y.toFixed(
item.series.userOptions.decimalPoint ? item.series.userOptions.decimalPoint : 2,
) * 1
}${item.series.userOptions.tooltip.valueSuffix}</b>
<br/>`;
});
return html;
},
},
plotOptions: {
series: {
showInNavigator: true,
connectNulls: false,
zoneAxis: 'x',
},
},
legend: {
enabled: true,
verticalAlign: 'top',
},
series: [],
responsive: {
rules: [
{
condition: {
maxWidth: 800,
minHeight: 500,
},
},
],
},
});
let chartWidth = 0; // chart width let chartWidth = 0; // chart width
let chartHeight = 0; // chart height let chartHeight = 0; // chart height
...@@ -117,7 +192,15 @@ const HistoryInfo = (props) => { ...@@ -117,7 +192,15 @@ const HistoryInfo = (props) => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('history-info'); const prefixCls = getPrefixCls('history-info');
const { title, tableProps, historyInfoService, historyInfoParams, defaultChecked } = props; const {
title,
tableProps,
historyInfoService,
historyInfoParams,
dictionaryService,
dictionaryParams,
defaultChecked,
} = props;
const [activeTabKey, setActiveTabKey] = useState('curve'); const [activeTabKey, setActiveTabKey] = useState('curve');
const [timeValue, setTimeValue] = useState('customer'); const [timeValue, setTimeValue] = useState('customer');
...@@ -128,6 +211,7 @@ const HistoryInfo = (props) => { ...@@ -128,6 +211,7 @@ const HistoryInfo = (props) => {
const [checkboxData, setCheckboxData] = useState(CheckboxData); const [checkboxData, setCheckboxData] = useState(CheckboxData);
const [dataThinKey, setDataThinKey] = useState(timeIntervalList[0].key); const [dataThinKey, setDataThinKey] = useState(timeIntervalList[0].key);
const [options, setOptions] = useState({}); const [options, setOptions] = useState({});
const [colors, setColors] = useState(defaultColors);
const [params, setParams] = useState(historyInfoParams); const [params, setParams] = useState(historyInfoParams);
const [tableData, setTableData] = useState([]); const [tableData, setTableData] = useState([]);
const [pageSize, setPageSize] = useState(20); const [pageSize, setPageSize] = useState(20);
...@@ -257,6 +341,22 @@ const HistoryInfo = (props) => { ...@@ -257,6 +341,22 @@ const HistoryInfo = (props) => {
}); });
}; };
// 获取数据字典配置的曲线颜色
const getDictionaryList = () => {
dictionaryService(dictionaryParams).then((res) => {
if (res.code === 0 && res.data.length) {
const colorsData = res.data;
colorsData.sort((a, b) => a.nodeName.localeCompare(b.nodeName));
const color = colorsData.map((item) => item.nodeValue);
setColors(color);
}
});
};
useEffect(() => {
dictionaryService && getDictionaryList();
}, []);
useEffect(() => { useEffect(() => {
onChangeParams(state); onChangeParams(state);
}, [state]); }, [state]);
...@@ -472,10 +572,9 @@ const HistoryInfo = (props) => { ...@@ -472,10 +572,9 @@ const HistoryInfo = (props) => {
// 处理图表options // 处理图表options
const handleChartOptions = () => { const handleChartOptions = () => {
// const { series } = chartOptions; const _series = [];
let _series = [];
let _yAxis = []; let _yAxis = [];
let uniqueUnit = []; const uniqueUnit = [];
series.forEach((item, index) => { series.forEach((item, index) => {
// 处理series // 处理series
let _s = { let _s = {
...@@ -551,7 +650,7 @@ const HistoryInfo = (props) => { ...@@ -551,7 +650,7 @@ const HistoryInfo = (props) => {
global: { timezoneOffset: -8 * 60 }, global: { timezoneOffset: -8 * 60 },
}); });
let options = { ...defaultOptions }; let options = { ...DefaultOptions(colors, contrastOption) };
if (CheckboxData[0].checked) { if (CheckboxData[0].checked) {
_yAxis = setYaxisMin(_yAxis, _series); _yAxis = setYaxisMin(_yAxis, _series);
...@@ -561,30 +660,12 @@ const HistoryInfo = (props) => { ...@@ -561,30 +660,12 @@ const HistoryInfo = (props) => {
if (_yAxis.length > 0) { if (_yAxis.length > 0) {
options = { options = {
...defaultOptions, ...DefaultOptions(colors, contrastOption),
// ...chartOptions,
yAxis: _yAxis, yAxis: _yAxis,
series: _series, series: _series,
}; };
} }
options.tooltip.formatter = function formatter() {
let _html = `<b>${Highcharts.dateFormat(
contrastOption === 'day' ? '%H:%M' : '%d %H:%M',
this.x,
)}</b><br/>`;
this.points.forEach((item) => {
_html += `<span style={{color: ${item.series.color}}}>${item.series.name}</span>:
<b>${
item.point.y.toFixed(
item.series.userOptions.decimalPoint ? item.series.userOptions.decimalPoint : 2,
) * 1
}${item.series.userOptions.tooltip.valueSuffix}</b>
<br/>`;
});
return _html;
};
if (container.current) { if (container.current) {
if (container.current.offsetWidth !== 0) { if (container.current.offsetWidth !== 0) {
chartWidth = container.current.offsetWidth; chartWidth = container.current.offsetWidth;
...@@ -731,7 +812,7 @@ const endFormat = 'YYYY-MM-DD 23:59:59'; ...@@ -731,7 +812,7 @@ 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 colors = [ const defaultColors = [
'#1884EC', '#1884EC',
'#90CE53', '#90CE53',
'#86E0C7', '#86E0C7',
...@@ -750,65 +831,6 @@ const colors = [ ...@@ -750,65 +831,6 @@ const colors = [
'#cbcc75', '#cbcc75',
]; ];
const defaultOptions = {
chart: {
zoomType: 'x',
backgroundColor: 'rgba(255, 255, 255, 0.5)',
},
colors: colors,
title: null,
credits: false,
rangeSelector: {
enabled: false,
},
xAxis: [
{
lineWidth: 0,
crosshair: true,
type: 'datetime',
gridLineDashStyle: 'dash',
gridLineWidth: 1,
dateTimeLabelFormats: {
second: '%H:%M:%S',
minute: '%H:%M',
hour: '%H:%M',
day: '%d',
week: '%d',
month: '%d',
year: '%Y',
},
},
],
yAxis: [],
tooltip: {
shared: true,
split: false,
valueDecimals: 3,
},
plotOptions: {
series: {
showInNavigator: true,
connectNulls: false,
zoneAxis: 'x',
},
},
legend: {
enabled: true,
verticalAlign: 'top',
},
series: [],
responsive: {
rules: [
{
condition: {
maxWidth: 800,
minHeight: 500,
},
},
],
},
};
const initialState = { const initialState = {
dateRange: [], dateRange: [],
ignoreOutliers: false, ignoreOutliers: false,
......
...@@ -52,6 +52,7 @@ const QuotaSelect = ({ ...@@ -52,6 +52,7 @@ const QuotaSelect = ({
const [targetValue, setTargetValue] = useState('emphasis'); const [targetValue, setTargetValue] = useState('emphasis');
const [allQuotaList, setAllQuotaList] = useState([]); const [allQuotaList, setAllQuotaList] = useState([]);
const [quotaList, setQuotaList] = useState([]); const [quotaList, setQuotaList] = useState([]);
const [groupQuotaList, setGroupQuotaList] = useState([]);
const [selectDevice, setSelectDevice] = useState({}); // 选中的设备 const [selectDevice, setSelectDevice] = useState({}); // 选中的设备
const [selectData, setSelectData] = useState([]); // 选中的指标数据 const [selectData, setSelectData] = useState([]); // 选中的指标数据
const [confParams, setConfParams] = useState({}); const [confParams, setConfParams] = useState({});
...@@ -99,6 +100,34 @@ const QuotaSelect = ({ ...@@ -99,6 +100,34 @@ const QuotaSelect = ({
}); });
}; };
// 处理指标分组
const handleGroupData = (data) => {
const groupData = [];
const groupQuotaData = [];
data.forEach((item) => {
if (!groupData.includes(item.groupName)) {
groupData.push(item.groupName);
}
});
groupData.forEach((group) => {
const list = [];
data.forEach((child) => {
if (child.groupName === group) {
list.push(child);
}
});
groupQuotaData.push({
groupName: group || '未分组指标',
quotaList: list,
});
});
setGroupQuotaList(groupQuotaData);
};
useEffect(() => {
handleGroupData(quotaList);
}, [quotaList]);
useEffect(() => { useEffect(() => {
if (targetValue === 'emphasis') { if (targetValue === 'emphasis') {
filterEmphasisQuota(); filterEmphasisQuota();
...@@ -360,24 +389,31 @@ const QuotaSelect = ({ ...@@ -360,24 +389,31 @@ const QuotaSelect = ({
</div> </div>
<div className={classNames(`${prefixCls}-modal-option-wrap`)}> <div className={classNames(`${prefixCls}-modal-option-wrap`)}>
{!quotaList.length && <Empty />} {!quotaList.length && <Empty />}
<Row gutter={[0, 6]}> {!!quotaList.length &&
{!!quotaList.length && groupQuotaList.map((group, index) => (
quotaList.map((item) => ( <div key={index}>
<Col span={8} key={item.key}> <div className={classNames(`${prefixCls}-modal-class-title`)}>
<Checkbox {group.groupName}
value={item.title} </div>
checked={item.checked} <Row gutter={[0, 6]}>
disabled={ {group.quotaList.map((item) => (
(selectData.length > maximum || selectData.length === maximum) && <Col span={8} key={item.key}>
!item.checked <Checkbox
} value={item.title}
onChange={(e) => handleCheckboxChange(e, item)} checked={item.checked}
> disabled={
{item.title} (selectData.length > maximum || selectData.length === maximum) &&
</Checkbox> !item.checked
</Col> }
))} onChange={(e) => handleCheckboxChange(e, item)}
</Row> >
{item.title}
</Checkbox>
</Col>
))}
</Row>
</div>
))}
</div> </div>
</div> </div>
<div className={classNames(`${prefixCls}-modal-right`)}> <div className={classNames(`${prefixCls}-modal-right`)}>
......
...@@ -81,10 +81,26 @@ ...@@ -81,10 +81,26 @@
&-option-wrap { &-option-wrap {
height: calc(100% - 52px); height: calc(100% - 52px);
margin-top: 20px;
overflow-y: auto; overflow-y: auto;
} }
&-class-title {
position: relative;
margin: 24px 20px 16px 0;
padding: 0 0 16px 12px;
border-bottom: 1px solid rgba(0, 0, 0, 0.1);
&:after {
position: absolute;
top: 3px;
left: 0;
width: 3px;
height: 16px;
background: #1890ff;
content: '';
}
}
&-number { &-number {
margin-bottom: 10px; margin-bottom: 10px;
padding: 4px 0 10px 20px; padding: 4px 0 10px 20px;
......
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