deviceHistory.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. import React, { useEffect, useState } from 'react';
  2. import { Modal, Table } from 'antd';
  3. import type { ColumnsType } from 'antd/es/table';
  4. import moment from 'moment/moment';
  5. import { queryDeviceRunState } from '@/services/afterSales/afterSales';
  6. interface editProps {
  7. visible: boolean;
  8. editCallback: () => void;
  9. params: any;
  10. }
  11. interface DataType {
  12. created_at: string;
  13. start_time: string;
  14. end_time: string;
  15. duration: number;
  16. record_id: string;
  17. }
  18. /**
  19. * 设备运行历史
  20. * @param props
  21. * @constructor
  22. */
  23. const DeviceHistory: React.FC<editProps> = (props) => {
  24. const { params, visible, editCallback } = props;
  25. const [pagination, setPagination] = useState({ total: 0, current: 1, pageSize: 10 });
  26. const [loading, setLoading] = useState(false);
  27. const [list, setList] = useState([]);
  28. // 设备运行历史
  29. const onHistory = () => {
  30. setLoading(true);
  31. const data = {
  32. q: 'page',
  33. current: pagination.current,
  34. pageSize: pagination.pageSize,
  35. device_id: params.device_code,
  36. };
  37. queryDeviceRunState(data).then((res) => {
  38. if (res && res.code === 0) {
  39. setList(res.data.list || []);
  40. setPagination(res.data.pagination);
  41. setLoading(false);
  42. }
  43. });
  44. };
  45. useEffect(() => {
  46. if (params) {
  47. onHistory();
  48. }
  49. }, []);
  50. const tableChange = (page: any) => {
  51. setLoading(true);
  52. const data = {
  53. q: 'page',
  54. current: page.current,
  55. pageSize: page.pageSize,
  56. device_id: params.device_code,
  57. };
  58. queryDeviceRunState(data).then((res) => {
  59. if (res && res.code === 0) {
  60. setList(res.data.list || []);
  61. setPagination(res.data.pagination);
  62. setLoading(false);
  63. }
  64. });
  65. };
  66. const columns: ColumnsType<DataType> = [
  67. {
  68. title: '序号',
  69. align: 'center',
  70. key: 'index',
  71. render: (_: any, _row: any, index: number) => index + 1,
  72. },
  73. {
  74. title: '创建时间',
  75. dataIndex: 'created_at',
  76. key: 'created_at',
  77. render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
  78. },
  79. {
  80. title: '开机时间',
  81. dataIndex: 'start_time',
  82. key: 'start_time',
  83. render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
  84. },
  85. {
  86. title: '关机时间',
  87. dataIndex: 'end_time',
  88. key: 'end_time',
  89. render: (v) => v && <span>{moment(v).format('YYYY-MM-DD HH:mm')}</span>,
  90. },
  91. {
  92. title: '运行时长(小时)',
  93. dataIndex: 'duration',
  94. key: 'duration',
  95. },
  96. ];
  97. return (
  98. <Modal
  99. title="设备运行历史"
  100. width={800}
  101. footer={null}
  102. open={visible}
  103. onCancel={() => {
  104. editCallback();
  105. }}
  106. >
  107. <Table
  108. columns={columns}
  109. dataSource={list}
  110. rowKey={(record) => record.record_id}
  111. pagination={pagination}
  112. loading={loading}
  113. onChange={tableChange}
  114. />
  115. </Modal>
  116. );
  117. };
  118. export default DeviceHistory;