DeviceAnalysis.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import TabsContent from '@/components/TabsContent';
  2. import { UnityAction } from '@/utils/utils';
  3. import { connect } from '@umijs/max';
  4. import { Spin, Table, Tabs } from 'antd';
  5. import { useEffect, useMemo, useState } from 'react';
  6. import styles from './DeviceAnalysis.less';
  7. import ThresholdBar from './ThresholdBar';
  8. const { TabPane } = Tabs;
  9. const DeviceAnalysis = (props) => {
  10. const Status = [
  11. { name: '异常', type: '1', data: [] },
  12. { name: '全部', type: '2', data: [] },
  13. ];
  14. const { list = [], processList, loading } = props;
  15. const [selectedRowKeys, setSelectedRowKeys] = useState([]);
  16. const [tab, setTab] = useState('1');
  17. const columns = [
  18. {
  19. title: '设备名称',
  20. width: '20%',
  21. render: (record) => (
  22. <div>
  23. {record.DeviceName}({record.DeviceCode})
  24. </div>
  25. ),
  26. },
  27. {
  28. title: '巡检项',
  29. width: '14%',
  30. dataIndex: 'ProcessSectionId',
  31. render: (id) => {
  32. return processList.find((item) => item.id == id)?.name;
  33. },
  34. },
  35. {
  36. title: '设定值范围',
  37. width: '14%',
  38. render: (record) => {
  39. let thresholds = record.fault_range.split(',');
  40. return (
  41. <div>
  42. {record.fault_range && (
  43. <ThresholdBar
  44. current={record.fault_result}
  45. thresholds={thresholds}
  46. />
  47. )}
  48. </div>
  49. );
  50. },
  51. },
  52. {
  53. title: '状态',
  54. width: '20%',
  55. dataIndex: 'Reason',
  56. },
  57. ];
  58. useEffect(() => {
  59. UnityAction.on('SynDev', selectedItem);
  60. return () => UnityAction.off('SynDev', selectedItem);
  61. }, [data, tab]);
  62. const selectedItem = (e) => {
  63. setSelectedRowKeys([e]);
  64. console.log(data);
  65. const itemIndex = data?.findIndex((item) => item.type == tab);
  66. const index = data[itemIndex]?.data?.findIndex(
  67. (item) => item.DeviceCode == e,
  68. );
  69. if (index !== 0 || index != -1) {
  70. const dom = document.querySelector(`tr[data-row-key="${index}"]`);
  71. if (dom) {
  72. let v = document.getElementsByClassName('ant-table-body')[itemIndex];
  73. v.scrollTop = dom.offsetTop;
  74. }
  75. }
  76. };
  77. const data = useMemo(() => {
  78. return Status.map((item, idx) => {
  79. const data = list?.filter((cur) => cur.grade_alarm == item.type);
  80. return { ...item, data };
  81. });
  82. }, [list]);
  83. const handleBtnClick = (plcs, title) => {
  84. if (!plcs) return;
  85. const msg = JSON.stringify(plcs); //[{ dataitemid: 'Raw_Water_Tank_Level', deviceid: '1436022785' }]
  86. UnityAction.sendMsg(
  87. 'ProcessAnalysisAbout',
  88. JSON.stringify({
  89. title,
  90. data: msg,
  91. }),
  92. );
  93. };
  94. const onTabChange = (tab) => {
  95. setTab(tab);
  96. UnityAction.sendMsg('ProcessAnalysisType', tab);
  97. };
  98. const rowSelection = {
  99. type: 'radio',
  100. selectedRowKeys,
  101. onChange: (selectedRowKeys, selectedRows) => {
  102. setSelectedRowKeys(selectedRowKeys);
  103. UnityAction.sendMsg('SynDev', selectedRows[0].DeviceCode);
  104. },
  105. };
  106. const onSelectRow = (record, index) => {
  107. const selectedList = [...selectedRowKeys];
  108. if (selectedList[0] === index) return;
  109. selectedList[0] = index;
  110. setSelectedRowKeys(selectedList);
  111. UnityAction.sendMsg('SynDev', record.DeviceCode);
  112. };
  113. const setRowClassName = (record, index) => {
  114. return index === selectedRowKeys[0] ||
  115. record.DeviceCode == selectedRowKeys[0]
  116. ? styles.tableSelect
  117. : '';
  118. };
  119. return (
  120. <Spin spinning={loading}>
  121. <div className="card-box">
  122. <TabsContent
  123. small={true}
  124. center={false}
  125. defaultActiveKey="1"
  126. items={data?.map((item) => {
  127. return {
  128. label: `${item.name}(${item.data?.length || 0})`,
  129. key: item.type,
  130. children: (
  131. <Table
  132. dataSource={item.data}
  133. columns={columns}
  134. // rowKey={'DeviceCode'}
  135. // rowSelection={rowSelection}
  136. rowClassName={setRowClassName}
  137. onRow={(record, index) => ({
  138. onClick: () => onSelectRow(record, index),
  139. })}
  140. pagination={false}
  141. scroll={{ y: document.body.clientHeight - 730 }}
  142. />
  143. ),
  144. };
  145. })}
  146. onChange={onTabChange}
  147. />
  148. </div>
  149. </Spin>
  150. );
  151. };
  152. export default connect(({ smartOps, loading }) => ({
  153. loading: loading.effects['smartOps/queryList'],
  154. list: smartOps.list.list,
  155. processList: smartOps.processList,
  156. }))(DeviceAnalysis);