1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React, { useEffect, useState } from 'react';
import Empty from '@wisdom-components/empty';
import RealTimeInfo from '../index';
import request from 'umi-request';
const Demo = () => {
const [data, setData] = useState([]);
const [targetValue, setTargetValue] = useState('emphasis');
const [guid, setGuid] = useState('');
const [updateTime, setUpdateTime] = useState('');
const GetPointAddressEntry = (params = {}) => {
return request(baseUrl + '/Publish/GCK/PointAddress/GetPointAddressEntry', {
method: 'get',
params: {
versionID: 4,
},
});
};
const GetSensorType = (params = {}) => {
return request(baseUrl + '/Publish/GCK/Sensor/GetSensorType', {
method: 'get',
params: {},
});
};
const GetDeviceRealInfo = (params = {}) => {
return request(baseUrl + '/Publish/GCK/Device/DeviceRealInfo', {
method: 'post',
data: {
userID: '1',
pageIndex: 1,
pageSize: 20,
isFocus: false,
accountFieldParams: [{ AName: '二供泵房' }, { AName: '二供机组' }],
equipmentCode: 'EGBF00000001',
},
});
};
const fetchData = async () => {
let data1 = await GetPointAddressEntry();
let data2 = await GetSensorType();
let data3 = await GetDeviceRealInfo();
setUpdateTime(data3.data.list[0].PT);
setGuid(data3.data.list[0].child[0].guid);
handleData(data1.data, data2.data, data3.data);
};
const handleData = (data1 = [], data2 = [], data3 = []) => {
let newData = data1.map((item, index) => {
return {
id: item.id,
key: item.id,
index: index + 1,
name: item.Name,
value: 0,
unit: '--',
type: '--',
time: data3.list[0].pt,
...item,
};
});
newData.forEach((item) => {
let curData1 = data2.filter((child) => child.id == item.sensorTypeID);
let curData2 = data3.list[0].dataList.filter((child) => child.paid == item.id);
if (curData1.length) {
item.unit = curData1[0].unit || '--';
item.type = curData1[0].name || '--';
}
if (curData2.length) {
item.value = curData2[0].pv || '--';
}
});
setData(newData);
};
useEffect(() => {
fetchData();
}, []);
const onSearch = (e) => {
console.log(e.type, e.target.value);
};
const onRadioChange = (e) => {
setTargetValue(e.target.value);
console.log('value', e.target.value);
};
return (
<RealTimeInfo
onSearch={onSearch}
onRadioChange={onRadioChange}
targetValue={targetValue}
guid={guid}
updateTime={updateTime}
bordered
columns={columns}
dataSource={data}
pagination={{ pageSize: 50 }}
scroll={{ y: 500 }}
locale={{ emptyText: <Empty /> }}
/>
);
};
export default Demo;
const baseUrl = 'https://www.fastmock.site/mock/162c15dca15c4dba9ba51e0a0b76929b/api';
const columns = [
{
title: '序号',
dataIndex: 'index',
},
{
title: '指标名称',
dataIndex: 'name',
width: 150,
},
{
title: '最新指标',
dataIndex: 'value',
render: (text) => <a>{text}</a>,
},
{
title: '单位',
dataIndex: 'unit',
},
{
title: '指标类型',
dataIndex: 'type',
},
{
title: '更新时间',
dataIndex: 'time',
},
];