Commit a08bd4fb authored by 崔佳豪's avatar 崔佳豪

fix(EC_RealTimeInfo): 组件服务优化

parent 4af880d5
...@@ -16,4 +16,14 @@ export default { ...@@ -16,4 +16,14 @@ export default {
'/PandaMonitor': '/PandaMonitor', '/PandaMonitor': '/PandaMonitor',
}, },
}, },
'/PandaCore': {
target: proxyURL,
changeOrigin: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
pathRewrite: {
'/PandaCore': '/PandaCore',
},
},
}; };
import { request } from '@wisdom-utils/utils';
const REQUEST_METHOD_GET = 'get';
const REQUEST_METHOD_POST = 'post';
// eslint-disable-next-line no-undef
const baseUrl = typeof DUMI_TYPE !== 'undefined' && DUMI_TYPE === 'dumi' ? '/api' : '';
// 获取监控展示配置
export function getMonitorConfig({ params, data } = {}) {
return request({
url: `/PandaMonitor/Monitor/MonitorConfig/GetMonitorConf`,
method: REQUEST_METHOD_GET,
params,
data,
});
}
// 获取传感器类型
export function getSensorType({ params, data } = {}) {
return request({
url: `/PandaCore/GCK/Sensor/GetSensorType`,
method: REQUEST_METHOD_GET,
params,
data,
});
}
// 获取设备实时数据
export function getDeviceRealInfo({ params, data } = {}) {
return request({
url: `/PandaMonitor/Monitor/Device/GetDeviceRealInfo`,
method: REQUEST_METHOD_POST,
params,
data,
});
}
// 获取点表地址
export function getPointAddressEntry({ params, data } = {}) {
return request({
url: `/PandaMonitor/Monitor/PointAddress/GetPointAddressEntry`,
method: REQUEST_METHOD_GET,
params,
data,
});
}
// 获取点表版本
export function getPointAddress({ params, data } = {}) {
return request({
url: `/PandaMonitor/Monitor/PointAddress/GetPointAddress`,
method: REQUEST_METHOD_GET,
params,
data,
});
}
...@@ -20,53 +20,55 @@ const GET_DEVICE_REAL_INFO = ...@@ -20,53 +20,55 @@ const GET_DEVICE_REAL_INFO =
// const GET_SENSOR_TYPE = '/api/Publish/GCK/Sensor/GetSensorType'; //获取传感器类型 // const GET_SENSOR_TYPE = '/api/Publish/GCK/Sensor/GetSensorType'; //获取传感器类型
// const GET_DEVICE_REAL_INFO = '/api/Publish/GCK/Device/DeviceRealInfo'; //获取设备实时数据 // const GET_DEVICE_REAL_INFO = '/api/Publish/GCK/Device/DeviceRealInfo'; //获取设备实时数据
const realTimeInfoService = { // const realTimeInfoService = {
getDeviceConf: { // getDeviceConf: {
url: GET_DEVICE_CONF, // url: GET_DEVICE_CONF,
method: REQUEST_METHOD_GET, // method: REQUEST_METHOD_GET,
type: REQUEST_HTTP, // type: REQUEST_HTTP,
}, // },
getPointAddressEntry: { // getPointAddressEntry: {
url: GET_POINT_ADDRESS_ENTRY, // url: GET_POINT_ADDRESS_ENTRY,
method: REQUEST_METHOD_GET, // method: REQUEST_METHOD_GET,
type: REQUEST_HTTP, // type: REQUEST_HTTP,
}, // },
getSensorType: { // getSensorType: {
url: GET_SENSOR_TYPE, // url: GET_SENSOR_TYPE,
method: REQUEST_METHOD_GET, // method: REQUEST_METHOD_GET,
type: REQUEST_HTTP, // type: REQUEST_HTTP,
}, // },
getDeviceRealInfo: { // getDeviceRealInfo: {
url: GET_DEVICE_REAL_INFO, // url: GET_DEVICE_REAL_INFO,
method: REQUEST_METHOD_POST, // method: REQUEST_METHOD_POST,
type: REQUEST_HTTP, // type: REQUEST_HTTP,
}, // },
}; // };
const rtService = service(realTimeInfoService); // const rtService = service(realTimeInfoService);
const getDeviceConf = rtService.getDeviceConf; // const getDeviceConf = rtService.getDeviceConf;
const getPointAddressEntry = rtService.getPointAddressEntry; // const getPointAddressEntry = rtService.getPointAddressEntry;
const getSensorType = rtService.getSensorType; // const getSensorType = rtService.getSensorType;
const getDeviceRealInfo = rtService.getDeviceRealInfo; // const getDeviceRealInfo = rtService.getDeviceRealInfo;
const Demo = () => { const Demo = () => {
return ( return (
<div style={{ width: '200px', height: '60px', background: 'black' }}> <div style={{ width: '200px', height: '60px', background: 'black' }}>
<RealTimeInfo <RealTimeInfo
deviceConfService={getDeviceConf} deviceParams={[
pointAddressEntryService={getPointAddressEntry} {
sensorTypeService={getSensorType} deviceType: '二供泵房',
deviceRealInfoService={getDeviceRealInfo} deviceCode: 'EGBF00000001',
deviceRealInfoParams={{ },
userID: '1', {
pageIndex: 1, deviceType: '二供机组',
pageSize: 20, deviceCode: 'EGJZ00000001',
isFocus: false, },
accountFieldParams: [{ AName: '二供泵房' }, { AName: '二供机组' }], {
equipmentCode: 'EGBF00000001', deviceType: '二供机组',
}} deviceCode: 'EGJZ00000002',
user={'1'} },
]}
user={1}
/> />
</div> </div>
); );
......
import React, { useState, useEffect, useContext } from 'react'; import React, { useState, useEffect, useContext, useMemo } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Empty from '@wisdom-components/empty'; import Empty from '@wisdom-components/empty';
import classNames from 'classnames'; import classNames from 'classnames';
import { Modal, Button, Tabs, Input, Radio, ConfigProvider } from 'antd'; import { Modal, Button, Tabs, Input, Radio, ConfigProvider, message } from 'antd';
import BasicTable from '@wisdom-components/basictable'; import BasicTable from '@wisdom-components/basictable';
import {
getMonitorConfig,
getSensorType,
getDeviceRealInfo,
getPointAddressEntry,
getPointAddress,
} from '../apis';
import './index.less'; import './index.less';
const { TabPane } = Tabs; const { TabPane } = Tabs;
const defaultColumns = [
{
title: '序号',
dataIndex: 'index',
width: 60,
},
{
title: '指标名称',
dataIndex: 'name',
width: 150,
},
{
title: '最新指标',
dataIndex: 'value',
render: (text) => <a>{text}</a>,
},
{
title: '单位',
dataIndex: 'unit',
},
{
title: '指标类型',
dataIndex: 'type',
},
{
title: '数据描述',
dataIndex: 'desc',
},
{
title: '更新时间',
dataIndex: 'time',
},
];
const RealTimeInfo = (props) => { const RealTimeInfo = (props) => {
const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); const { getPrefixCls } = useContext(ConfigProvider.ConfigContext);
const prefixCls = getPrefixCls('realtime-info'); const prefixCls = getPrefixCls('realtime-info');
const { const { deviceParams, user, placeholder, defaultTargetValue, modalTitle, buttonText } = props;
deviceConfService,
pointAddressEntryService,
sensorTypeService,
deviceRealInfoService,
deviceRealInfoParams,
user,
placeholder,
defaultTargetValue,
modalTitle,
buttonText,
} = props;
const [isModalVisible, setIsModalVisible] = useState(false); const [isModalVisible, setIsModalVisible] = useState(false);
const [targetValue, setTargetValue] = useState(defaultTargetValue); // 重点/全部 const [targetValue, setTargetValue] = useState(defaultTargetValue); // 重点/全部
const [searchValue, setSearchValue] = useState(''); // 搜索框内容 const [searchValue, setSearchValue] = useState(''); // 搜索框内容
const [columns, setColumns] = useState(defaultColumns); // 搜索框内容
const [tabData, setTabData] = useState([]);
const [tabKey, setTabKey] = useState(''); const [tabKey, setTabKey] = useState('');
const [guid, setGuid] = useState(''); const [guid, setGuid] = useState('');
const [deviceConf, setDeviceConf] = useState([]); // 设备配置 const [deviceConf, setDeviceConf] = useState([]); // 设备配置
const [deviceInfo, setDeviceInfo] = useState({}); // 设备实时数据 const [deviceInfo, setDeviceInfo] = useState({}); // 设备实时数据
const [sensorType, setSensorType] = useState({}); // sensorType const [sensorType, setSensorType] = useState([]); // sensorType
const [pointAddress, setPointAddress] = useState([]); // pointAddress const [pointAddress, setPointAddress] = useState([]); // pointAddress
const [tableData, setTableData] = useState([]); // 表格数据
const [searchData, setSearchData] = useState([]); // 表格搜索数据
const handleTabData = (data = {}) => { const tabData = useMemo(() => {
const data = deviceInfo;
let tData = []; let tData = [];
if (!data) return tData;
tData.push({ tData.push({
key: data.code, key: data.code,
title: data.name, title: data.name,
...@@ -59,43 +87,92 @@ const RealTimeInfo = (props) => { ...@@ -59,43 +87,92 @@ const RealTimeInfo = (props) => {
}); });
}); });
} }
setTabData(tData); return tData;
setTabKey(tData[0].key); }, [deviceInfo]);
};
// 过滤重点指标 // 过滤重点指标(带搜索)
const filterEmphasis = (dataSource) => { const filterEmphasis = (dataSource, searchValue) => {
const cur = tabData.filter((item) => item.key === tabKey); const cur = tabData.filter((item) => item.key === tabKey);
const conf = const conf =
cur.length > 0 ? deviceConf.filter((item) => item.deviceType === cur[0].deviceType) : []; cur.length > 0 ? deviceConf.filter((item) => item.deviceType === cur[0].deviceType) : [];
const dPoints = conf.length > 0 && conf[0].dPoints ? conf[0].dPoints.split(',') : []; const dPoints = conf.length > 0 && conf[0].dPoints ? conf[0].dPoints.split(',') : [];
const data = dataSource.filter((item) => dPoints.includes(item.name)); const data = dataSource.filter((item) =>
setSearchData(data); searchValue
? dPoints.indexOf(searchValue) > -1 && dPoints.includes(item.name)
: dPoints.includes(item.name),
);
return data;
};
// 过滤普通指标(带搜索)
const filterSearch = (dataSource, searchValue) => {
return !searchValue ? dataSource : dataSource.filter((item) => item.name.includes(searchValue));
}; };
const handleFilterColumns = (data = []) => { const getData = () => {
const keyArr = defaultColumns.map((item) => item.dataIndex); const deviceType =
const filter = []; deviceParams.length > 0
keyArr.forEach((key) => { ? Array.from(new Set(deviceParams.map((item) => item.deviceType))).join(',')
let length = 0; : '二供泵房,二供机组';
data.forEach((item) => { const configReq = getMonitorConfig({
if (item[key] === '--' || item[key] === '') { params: {
length++; user,
showAll: true,
deviceType,
},
});
const sensorReq = getSensorType();
const realDataReq = getDeviceRealInfo({
data: {
pageIndex: 1,
pageSize: 200,
param: deviceParams,
useID: user,
},
});
Promise.all([configReq, sensorReq, realDataReq])
.then((results) => {
if (results.some((item) => item.code !== 0)) message.error('获取数据失败');
const [configRes, sensorRes, realDataRes] = results;
setSensorType(sensorRes.data);
setDeviceConf(configRes.data);
setDeviceInfo(realDataRes.data.list[0]);
setTabKey(realDataRes?.data?.list?.[0]?.code);
})
.catch((err) => {
message.error('获取数据失败');
});
};
useEffect(() => {
if (!isModalVisible || !deviceParams || !deviceParams.length) return;
getData();
}, [deviceParams, user, isModalVisible]);
const GetPointAddressEntry = () => {
const cur = tabData.filter((item) => item.key === tabKey);
!!cur.length &&
getPointAddressEntry({
params: {
versionId: cur[0].versionID,
},
}).then((res) => {
if (res.code === 0 && res.data.length) {
setPointAddress(res.data);
} }
}); });
if (data.length === length) {
filter.push(key);
}
});
const column = defaultColumns.filter((item) => !filter.includes(item.dataIndex));
setColumns(column);
setTableData(data);
}; };
const handleData = (data1 = [], data2 = [], data3 = {}) => { useEffect(() => {
let time = data3.pt; if (!tabKey || !tabData || !tabData.length) return;
GetPointAddressEntry();
}, [tabKey]);
const formatData = (data = [], sensorType = [], deviceInfo = {}) => {
if (!deviceInfo) return [];
let time = deviceInfo.pt;
if (time) time = time.slice(5, 19).replace('-', '/'); if (time) time = time.slice(5, 19).replace('-', '/');
let newData = data1.map((item, index) => { let newData = data.map((item, index) => {
return { return {
id: item.id, id: item.id,
key: item.id, key: item.id,
...@@ -110,8 +187,8 @@ const RealTimeInfo = (props) => { ...@@ -110,8 +187,8 @@ const RealTimeInfo = (props) => {
}; };
}); });
newData.forEach((item) => { newData.forEach((item) => {
let curData1 = data2.filter((child) => child.id == item.sensorTypeID); let curData1 = sensorType.filter((child) => child.id == item.sensorTypeID);
let curData2 = data3.dataList.filter((child) => child.paid == item.id); let curData2 = deviceInfo.dataList.filter((child) => child.paid == item.id);
if (curData1.length) { if (curData1.length) {
item.unit = curData1[0].unit || '--'; item.unit = curData1[0].unit || '--';
item.type = curData1[0].name || '--'; item.type = curData1[0].name || '--';
...@@ -120,90 +197,29 @@ const RealTimeInfo = (props) => { ...@@ -120,90 +197,29 @@ const RealTimeInfo = (props) => {
item.value = curData2[0].pv || '--'; item.value = curData2[0].pv || '--';
} }
}); });
handleFilterColumns(newData); return newData;
const data = searchValue
? newData.filter((item) => item.name.indexOf(searchValue) !== -1)
: newData;
if (targetValue === 'emphasis') {
filterEmphasis(data);
} else {
setSearchData(data);
}
}; };
const GetDeviceConf = () => { const tableData = useMemo(() => {
const deviceType = // 过滤数据
deviceRealInfoParams.accountFieldParams.length > 0 let points = [];
? deviceRealInfoParams.accountFieldParams.map((item) => item.AName).join(',')
: '二供泵房,二供机组';
deviceConfService({
user,
showAll: true,
deviceType,
}).then((res) => {
if (res.code === 0 && res.data.length) {
setDeviceConf(res.data);
}
});
};
const GetDeviceRealInfo = () => {
deviceRealInfoService(deviceRealInfoParams).then((res) => {
if (res.code === 0 && res.data) {
setDeviceInfo(res.data.list[0]);
handleTabData(res.data.list[0]);
}
});
};
const GetSensorType = () => {
sensorTypeService({}).then((res) => {
if (res.code === 0 && res.data.length) {
setSensorType(res.data);
}
});
};
const GetPointAddressEntry = () => {
const cur = tabData.filter((item) => item.key === tabKey);
!!cur.length &&
pointAddressEntryService({ versionID: cur[0].versionID }).then((res) => {
if (res.code === 0 && res.data.length) {
setPointAddress(res.data);
}
});
};
useEffect(() => {
if (isModalVisible) {
GetDeviceConf();
GetDeviceRealInfo();
GetSensorType();
}
}, [isModalVisible]);
useEffect(() => {
GetPointAddressEntry();
}, [tabKey]);
useEffect(() => {
handleData(pointAddress, sensorType, deviceInfo);
}, [pointAddress]);
useEffect(() => {
if (targetValue === 'emphasis') { if (targetValue === 'emphasis') {
// 重点指标 points = filterEmphasis(pointAddress, searchValue);
filterEmphasis(searchData);
} else { } else {
// 全部 points = filterSearch(pointAddress, searchValue);
if (searchValue) {
const data = tableData.filter((item) => item.name.indexOf(searchValue) !== -1);
setSearchData(data);
} else {
setSearchData(tableData);
}
} }
}, [targetValue]);
const deviceData =
deviceInfo.code === tabKey
? deviceInfo
: deviceInfo?.child?.find((item) => item.code === tabKey);
const newData = formatData(points, sensorType, deviceData);
return newData;
}, [targetValue, searchValue, pointAddress, deviceInfo]);
const columns = useMemo(() => {
return defaultColumns;
}, []);
const showModal = () => { const showModal = () => {
setIsModalVisible(true); setIsModalVisible(true);
...@@ -217,33 +233,13 @@ const RealTimeInfo = (props) => { ...@@ -217,33 +233,13 @@ const RealTimeInfo = (props) => {
setIsModalVisible(false); setIsModalVisible(false);
}; };
const onSearch = (e) => { const changeSearch = (e) => {
e.target && e.target.value === '' && setSearchValue('');
};
const onSearch = (value) => {
// 前端搜索 // 前端搜索
if (e.target.value) { setSearchValue(value);
if (targetValue === 'emphasis') {
// 重点指标
const cur = tabData.filter((item) => item.key === tabKey);
const conf =
cur.length > 0 ? deviceConf.filter((item) => item.deviceType === cur[0].deviceType) : [];
const dPoints = conf.length > 0 && conf[0].dPoints ? conf[0].dPoints.split(',') : [];
const data = tableData.filter((item) => dPoints.includes(item.name));
const newDate = data.filter((item) => item.name.indexOf(e.target.value) !== -1);
setSearchData(newDate);
} else {
// 全部
const data = tableData.filter((item) => item.name.indexOf(e.target.value) !== -1);
setSearchData(data);
}
} else {
if (targetValue === 'emphasis') {
// 重点指标
filterEmphasis(tableData);
} else {
// 全部
setSearchData(tableData);
}
}
setSearchValue(e.target.value);
}; };
const onTabChange = (key) => { const onTabChange = (key) => {
...@@ -291,7 +287,7 @@ const RealTimeInfo = (props) => { ...@@ -291,7 +287,7 @@ const RealTimeInfo = (props) => {
<div className={classNames(`${prefixCls}-search-wrap`)}> <div className={classNames(`${prefixCls}-search-wrap`)}>
<div className={classNames(`${prefixCls}-search`)}> <div className={classNames(`${prefixCls}-search`)}>
<div className={classNames(`${prefixCls}-label`)}>搜索:</div> <div className={classNames(`${prefixCls}-label`)}>搜索:</div>
<Input placeholder={placeholder} onChange={onSearch} value={searchValue} /> <Input.Search placeholder={placeholder} onSearch={onSearch} onChange={changeSearch} />
</div> </div>
<div className={classNames(`${prefixCls}-target`)}> <div className={classNames(`${prefixCls}-target`)}>
<div className={classNames(`${prefixCls}-label`)}>指标:</div> <div className={classNames(`${prefixCls}-label`)}>指标:</div>
...@@ -311,7 +307,7 @@ const RealTimeInfo = (props) => { ...@@ -311,7 +307,7 @@ const RealTimeInfo = (props) => {
columns={columns} columns={columns}
locale={{ emptyText: <Empty /> }} locale={{ emptyText: <Empty /> }}
pagination={false} pagination={false}
dataSource={searchData} dataSource={tableData}
{...props} {...props}
/> />
</div> </div>
...@@ -327,6 +323,7 @@ RealTimeInfo.defaultProps = { ...@@ -327,6 +323,7 @@ RealTimeInfo.defaultProps = {
placeholder: '输入指标名称等', placeholder: '输入指标名称等',
defaultTargetValue: 'emphasis', defaultTargetValue: 'emphasis',
user: null, user: null,
deviceParams: [],
deviceRealInfoParams: {}, deviceRealInfoParams: {},
deviceConfService: () => {}, deviceConfService: () => {},
pointAddressEntryService: () => {}, pointAddressEntryService: () => {},
...@@ -339,7 +336,8 @@ RealTimeInfo.propTypes = { ...@@ -339,7 +336,8 @@ RealTimeInfo.propTypes = {
modalTitle: PropTypes.string, modalTitle: PropTypes.string,
placeholder: PropTypes.string, placeholder: PropTypes.string,
defaultTargetValue: PropTypes.string, defaultTargetValue: PropTypes.string,
user: PropTypes.string, user: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
deviceParams: PropTypes.array,
deviceRealInfoParams: PropTypes.object, deviceRealInfoParams: PropTypes.object,
deviceConfService: PropTypes.func, deviceConfService: PropTypes.func,
pointAddressEntryService: PropTypes.func, pointAddressEntryService: PropTypes.func,
...@@ -348,37 +346,3 @@ RealTimeInfo.propTypes = { ...@@ -348,37 +346,3 @@ RealTimeInfo.propTypes = {
}; };
export default RealTimeInfo; export default RealTimeInfo;
const defaultColumns = [
{
title: '序号',
dataIndex: 'index',
width: 60,
},
{
title: '指标名称',
dataIndex: 'name',
width: 150,
},
{
title: '最新指标',
dataIndex: 'value',
render: (text) => <a>{text}</a>,
},
{
title: '单位',
dataIndex: 'unit',
},
{
title: '指标类型',
dataIndex: 'type',
},
{
title: '数据描述',
dataIndex: 'desc',
},
{
title: '更新时间',
dataIndex: 'time',
},
];
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