List.jsx 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import React from 'react';
  2. import { Link } from 'umi';
  3. import moment from 'moment';
  4. import { Button, Popconfirm, Dropdown, Menu, message } from 'antd';
  5. import PageTable from '@/components/PageTable';
  6. import { getDeviceList } from '@/services/device';
  7. const formatterTime = (val) => {
  8. return val && val !== '-' ? moment(val).format('YYYY-MM-DD') : '-';
  9. };
  10. const List = (props, ref) => {
  11. const { onOperate, toolBar } = props;
  12. const columns = [
  13. {
  14. title: '设备类型',
  15. dataIndex: 'deviceType',
  16. key: 'deviceType',
  17. valueEnum: {
  18. shensong: {
  19. text: '深松',
  20. },
  21. feifang: {
  22. text: '飞防',
  23. },
  24. },
  25. },
  26. {
  27. title: '设备编号',
  28. dataIndex: 'deviceNo',
  29. key: 'deviceNo',
  30. search: false,
  31. },
  32. {
  33. title: '绑定农机',
  34. dataIndex: 'machineryName',
  35. key: 'machineryName',
  36. search: false,
  37. },
  38. {
  39. title: '注册时间',
  40. dataIndex: 'createDate',
  41. key: 'createDate',
  42. render: formatterTime,
  43. search: false,
  44. width: 240,
  45. },
  46. {
  47. title: '在线状态',
  48. dataIndex: 'onlineStatus',
  49. key: 'onlineStatus',
  50. valueEnum: {
  51. 1: {
  52. text: '在线',
  53. },
  54. 0: {
  55. text: '离线',
  56. },
  57. },
  58. },
  59. {
  60. title: '操作',
  61. valueType: 'option',
  62. width: 280,
  63. render: (_, record) => [
  64. <Link
  65. to={`/Machinery/OperationStatistics?deviceType=${record.deviceType}&deviceNo=${record.deviceNo}`}
  66. key={1}
  67. >
  68. 作业
  69. </Link>,
  70. record.machineryId === null ? (
  71. <Button key={2} type="link" onClick={() => onOperate(record, 'bind')}>
  72. 绑定
  73. </Button>
  74. ) : (
  75. <Popconfirm
  76. key={3}
  77. title={`是否进行解绑操作?`}
  78. onConfirm={() => onOperate(record, 'unbind')}
  79. >
  80. <Button type="link">解绑</Button>
  81. </Popconfirm>
  82. ),
  83. <Popconfirm
  84. key={4}
  85. title={`确认进行删除操作?`}
  86. onConfirm={() => onOperate(record, 'delete')}
  87. >
  88. <a href="#">删除</a>
  89. </Popconfirm>,
  90. <Button key={5} type="link" onClick={() => onOperate(record, 'syncLoc')}>
  91. 同步位置
  92. </Button>,
  93. ],
  94. },
  95. ];
  96. const actionRef = React.useRef();
  97. React.useImperativeHandle(ref, () => {
  98. return {
  99. reload: () => actionRef.current.reload(),
  100. };
  101. });
  102. return (
  103. <PageTable
  104. request={getDeviceList}
  105. actionRef={actionRef}
  106. columns={columns}
  107. rowKey={(row) => `${row.deviceType}-${row.deviceNo}`}
  108. options={false}
  109. toolBarRender={() => toolBar}
  110. scroll={{ x: 1000 }}
  111. />
  112. );
  113. };
  114. export default React.forwardRef(List);