index.tsx 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import { PageContainer } from '@ant-design/pro-layout';
  2. import BaseService from '@/utils/BaseService';
  3. import { useRef } from 'react';
  4. import type { ProColumns, ActionType } from '@jetlinks/pro-table';
  5. import type { CommandItem } from '@/pages/device/Command/typings';
  6. import { Tooltip } from 'antd';
  7. import moment from 'moment';
  8. import BaseCrud from '@/components/BaseCrud';
  9. import { EyeOutlined, SyncOutlined } from '@ant-design/icons';
  10. import { useIntl } from '@@/plugin-locale/localeExports';
  11. const service = new BaseService('device/message/task');
  12. const Command = () => {
  13. const actionRef = useRef<ActionType>();
  14. const intl = useIntl();
  15. const columns: ProColumns<CommandItem>[] = [
  16. {
  17. title: intl.formatMessage({
  18. id: 'pages.device.command.deviceID',
  19. defaultMessage: '设备ID',
  20. }),
  21. dataIndex: 'deviceId',
  22. },
  23. {
  24. title: intl.formatMessage({
  25. id: 'pages.device.command.equipmentName',
  26. defaultMessage: '设备名称',
  27. }),
  28. dataIndex: 'deviceName',
  29. },
  30. {
  31. title: intl.formatMessage({
  32. id: 'pages.device.command.instructionType',
  33. defaultMessage: '指令类型',
  34. }),
  35. dataIndex: 'messageType',
  36. filters: [
  37. {
  38. text: intl.formatMessage({
  39. id: 'pages.device.command.instructionType.readAttributes',
  40. defaultMessage: '读取属性',
  41. }),
  42. value: 'READ_PROPERTY'
  43. },
  44. {
  45. text: intl.formatMessage({
  46. id: 'pages.device.command.instructionType.setProperties',
  47. defaultMessage: '设置属性',
  48. }),
  49. value: 'WRITE_PROPERTY'
  50. },
  51. {
  52. text: intl.formatMessage({
  53. id: 'pages.device.command.instructionType.callAttribute',
  54. defaultMessage: '调用属性',
  55. }),
  56. value: 'INVOKE_FUNCTION'
  57. },
  58. ],
  59. },
  60. {
  61. title: intl.formatMessage({
  62. id: 'pages.device.command.status',
  63. defaultMessage: '状态',
  64. }),
  65. dataIndex: 'state',
  66. filters: [
  67. {
  68. text: intl.formatMessage({
  69. id: 'pages.device.command.status.waiting',
  70. defaultMessage: '等待中',
  71. }),
  72. value: 'wait'
  73. },
  74. {
  75. text: intl.formatMessage({
  76. id: 'pages.device.command.status.failed ',
  77. defaultMessage: '发送失败',
  78. }),
  79. value: 'sendError'
  80. },
  81. {
  82. text: intl.formatMessage({
  83. id: 'pages.device.command.status.succeed',
  84. defaultMessage: '发送成功',
  85. }),
  86. value: 'success'
  87. },
  88. ],
  89. render: (value: any) => value.text,
  90. },
  91. {
  92. title: intl.formatMessage({
  93. id: 'pages.device.command.errorMessage',
  94. defaultMessage: '错误信息',
  95. }),
  96. dataIndex: 'lastError',
  97. },
  98. {
  99. title: intl.formatMessage({
  100. id: 'pages.device.command.sendTime',
  101. defaultMessage: '发送时间',
  102. }),
  103. dataIndex: 'sendTimestamp',
  104. render: (text: any) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
  105. sorter: true,
  106. defaultSortOrder: 'descend',
  107. },
  108. {
  109. title: intl.formatMessage({
  110. id: 'pages.data.option',
  111. defaultMessage: '操作',
  112. }),
  113. valueType: 'option',
  114. align: 'center',
  115. width: 200,
  116. render: (text, record) => [
  117. <a
  118. onClick={() => {
  119. // setVisible(true);
  120. // setCurrent(record);
  121. }}
  122. >
  123. <Tooltip
  124. title={intl.formatMessage({
  125. id: 'pages.data.option.detail',
  126. defaultMessage: '查看',
  127. })}
  128. key={'detail'}
  129. >
  130. <EyeOutlined />
  131. </Tooltip>
  132. </a>,
  133. <a>
  134. {record.state.value !== 'wait' && (
  135. <a
  136. onClick={() => {
  137. // service.resend(encodeQueryParam({ terms: { id: record.id } })).subscribe(
  138. // data => {
  139. // message.success('操作成功');
  140. // },
  141. // () => {},
  142. // () => handleSearch(searchParam),
  143. // );
  144. }}
  145. >
  146. <Tooltip title="重新发送">
  147. <SyncOutlined />
  148. </Tooltip>
  149. </a>
  150. )}
  151. </a>,
  152. ],
  153. },
  154. ];
  155. const schema = {};
  156. return (
  157. <PageContainer>
  158. <BaseCrud<CommandItem>
  159. columns={columns}
  160. service={service}
  161. title={'指令下发'}
  162. schema={schema}
  163. actionRef={actionRef}
  164. />
  165. </PageContainer>
  166. );
  167. };
  168. export default Command;