| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- import { PageContainer } from '@ant-design/pro-layout';
- import { useRef } from 'react';
- import type { ActionType, ProColumns } from '@jetlinks/pro-table';
- import ProTable from '@jetlinks/pro-table';
- import type { CommandItem } from '@/pages/device/Command/typings';
- import { Button, Tooltip } from 'antd';
- import moment from 'moment';
- import { EyeOutlined, PlusOutlined, SyncOutlined } from '@ant-design/icons';
- import { useIntl } from '@@/plugin-locale/localeExports';
- import Service from '@/pages/device/Command/service';
- import Create from '@/pages/device/Command/create';
- import encodeQuery from '@/utils/encodeQuery';
- import { model } from '@formily/reactive';
- import { observer } from '@formily/react';
- import Cat from '@/pages/device/Command/cat';
- import { onlyMessage } from '@/utils/util';
- export const service = new Service('device/message/task');
- export const state = model<{
- visible: boolean;
- cat: boolean;
- data?: CommandItem;
- }>({
- visible: false,
- cat: false,
- });
- const Command = observer(() => {
- const actionRef = useRef<ActionType>();
- const intl = useIntl();
- const columns: ProColumns<CommandItem>[] = [
- {
- dataIndex: 'index',
- valueType: 'indexBorder',
- width: 48,
- },
- {
- title: intl.formatMessage({
- id: 'pages.table.deviceId',
- defaultMessage: '设备ID',
- }),
- dataIndex: 'deviceId',
- },
- {
- title: intl.formatMessage({
- id: 'pages.table.deviceName',
- defaultMessage: '设备名称',
- }),
- dataIndex: 'deviceName',
- },
- {
- title: intl.formatMessage({
- id: 'pages.device.command.type',
- defaultMessage: '指令类型',
- }),
- dataIndex: 'messageType',
- filters: [
- {
- text: intl.formatMessage({
- id: 'pages.device.command.type.readProperty',
- defaultMessage: '读取属性',
- }),
- value: 'READ_PROPERTY',
- },
- {
- text: intl.formatMessage({
- id: 'pages.device.command.type.writeProperty',
- defaultMessage: '设置属性',
- }),
- value: 'WRITE_PROPERTY',
- },
- {
- text: intl.formatMessage({
- id: 'pages.device.command.type.invokeFunction',
- defaultMessage: '调用属性',
- }),
- value: 'INVOKE_FUNCTION',
- },
- ],
- },
- {
- title: intl.formatMessage({
- id: 'pages.searchTable.titleStatus',
- defaultMessage: '状态',
- }),
- dataIndex: 'state',
- filters: [
- {
- text: intl.formatMessage({
- id: 'pages.device.command.status.wait',
- defaultMessage: '等待中',
- }),
- value: 'wait',
- },
- {
- text: intl.formatMessage({
- id: 'pages.device.command.status.sendError',
- defaultMessage: '发送失败',
- }),
- value: 'sendError',
- },
- {
- text: intl.formatMessage({
- id: 'pages.device.command.status.success',
- defaultMessage: '发送成功',
- }),
- value: 'success',
- },
- ],
- render: (value: any) => value.text,
- },
- {
- title: intl.formatMessage({
- id: 'pages.device.command.lastError',
- defaultMessage: '错误信息',
- }),
- dataIndex: 'lastError',
- },
- {
- title: intl.formatMessage({
- id: 'pages.device.command.sendTime',
- defaultMessage: '发送时间',
- }),
- dataIndex: 'sendTimestamp',
- render: (text: any) => moment(text).format('YYYY-MM-DD HH:mm:ss'),
- sorter: true,
- defaultSortOrder: 'descend',
- },
- {
- title: intl.formatMessage({
- id: 'pages.data.option',
- defaultMessage: '操作',
- }),
- valueType: 'option',
- align: 'center',
- width: 200,
- render: (text, record) => [
- <a
- key="cat"
- onClick={() => {
- state.cat = true;
- state.data = record;
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.data.option.detail',
- defaultMessage: '查看',
- })}
- key="detail"
- >
- <EyeOutlined />
- </Tooltip>
- </a>,
- record.state.value !== 'wait' && (
- <a
- key="action"
- onClick={async () => {
- const resp = await service.resend(encodeQuery({ terms: { id: record.id } }));
- if (resp.status === 200) {
- onlyMessage('操作成功!');
- } else {
- onlyMessage('操作失败!', 'error');
- }
- }}
- >
- <Tooltip
- title={intl.formatMessage({
- id: 'pages.device.command.option.send',
- defaultMessage: '重新发送',
- })}
- >
- <SyncOutlined />
- </Tooltip>
- </a>
- ),
- ],
- },
- ];
- return (
- <PageContainer>
- <ProTable<CommandItem>
- toolBarRender={() => [
- <Button
- onClick={() => {
- state.visible = true;
- }}
- key="button"
- icon={<PlusOutlined />}
- type="primary"
- >
- 下发指令
- </Button>,
- ]}
- request={async (params) => service.query(params)}
- columns={columns}
- actionRef={actionRef}
- rowKey="id"
- columnEmptyText={''}
- />
- <Create
- visible={state.visible}
- close={() => {
- state.visible = false;
- }}
- />
- <Cat
- close={() => {
- state.cat = false;
- }}
- data={state.data}
- visible={state.cat}
- />
- </PageContainer>
- );
- });
- export default Command;
|