import { PageContainer } from '@ant-design/pro-layout'; import SearchComponent from '@/components/SearchComponent'; import { useRef, useState } from 'react'; import { history } from 'umi'; import type { ActionType, ProColumns } from '@jetlinks/pro-table'; import { PermissionButton, ProTableCard } from '@/components'; import { DeleteOutlined, EditOutlined, InfoCircleOutlined, PlayCircleOutlined, PlusOutlined, StopOutlined, } from '@ant-design/icons'; import { useIntl } from '@@/plugin-locale/localeExports'; import { getMenuPathByParams, MENUS_CODE } from '@/utils/menu'; import AliyunCard from '@/components/ProTableCard/CardItems/aliyun'; import Service from './service'; import { Badge } from 'antd'; import { onlyMessage } from '@/utils/util'; export const service = new Service('device/aliyun/bridge'); const AliCloud = () => { const actionRef = useRef(); const intl = useIntl(); const [searchParams, setSearchParams] = useState({}); const { permission } = PermissionButton.usePermission('Northbound/AliCloud'); const Tools = (record: any, type: 'card' | 'table') => { return [ { const url = `${getMenuPathByParams(MENUS_CODE['Northbound/AliCloud/Detail'], record.id)}`; history.push(url); }} > {type !== 'table' && intl.formatMessage({ id: 'pages.data.option.edit', defaultMessage: '编辑', })} , { const resp = record?.state?.value !== 'disabled' ? await service._disable(record.id) : await service._enable(record.id); if (resp.status === 200) { onlyMessage('操作成功!'); actionRef.current?.reload?.(); } else { onlyMessage('操作失败!', 'error'); } }, }} tooltip={{ title: intl.formatMessage({ id: `pages.data.option.${record?.state?.value !== 'disabled' ? 'disabled' : 'enabled'}`, defaultMessage: '启用', }), }} > {record?.state?.value !== 'disabled' ? : } , { if (record?.state?.value === 'disabled') { await service.remove(record.id); onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } else { onlyMessage(intl.formatMessage({ id: 'pages.device.instance.deleteTip' }), 'error'); } }, }} tooltip={{ title: record.state.value === 'started' ? 请先禁用,再删除 : 删除, }} > , ]; }; const columns: ProColumns[] = [ { title: '名称', dataIndex: 'name', ellipsis: true, fixed: 'left', }, { title: '网桥产品', dataIndex: 'bridgeProductName', ellipsis: true, }, { title: '说明', dataIndex: 'description', ellipsis: true, }, { title: '状态', dataIndex: 'state', render: (text: any, record: any) => ( ), valueType: 'select', valueEnum: { disabled: { text: '停用', status: 'disabled', }, enabled: { text: '正常', status: 'enabled', }, }, }, { title: intl.formatMessage({ id: 'pages.data.option', defaultMessage: '操作', }), valueType: 'option', align: 'center', width: 200, fixed: 'right', render: (text, record) => Tools(record, 'table'), }, ]; return ( field={columns} target="aliyun" onSearch={(data) => { actionRef.current?.reload?.(); setSearchParams(data); }} />
将平台产品与设备数据通过API的方式同步到阿里云物联网平台
rowKey="id" search={false} scroll={{ x: 1366 }} columns={columns} actionRef={actionRef} params={searchParams} options={{ fullScreen: true }} request={(params) => service.query({ ...params, sorts: [ { name: 'createTime', order: 'desc', }, ], }) } pagination={{ pageSize: 10 }} headerTitle={[ { const url = `${getMenuPathByParams(MENUS_CODE['Northbound/AliCloud/Detail'])}`; history.push(url); }} style={{ marginRight: 12 }} isPermission={permission.add} key="button" icon={} type="primary" > {intl.formatMessage({ id: 'pages.data.option.add', defaultMessage: '新增', })} , ]} cardRender={(record) => ( { const url = `${getMenuPathByParams( MENUS_CODE['Northbound/AliCloud/Detail'], record.id, )}`; history.push(url); }} key={'edit'} isPermission={permission.update} > {intl.formatMessage({ id: 'pages.data.option.edit', defaultMessage: '编辑', })} , { const resp = record?.state?.value !== 'disabled' ? await service._disable(record.id) : await service._enable(record.id); if (resp.status === 200) { onlyMessage('操作成功!'); actionRef.current?.reload?.(); } else { onlyMessage('操作失败!', 'error'); } }, }} > {record?.state?.value !== 'disabled' ? : } {intl.formatMessage({ id: `pages.data.option.${ record?.state?.value !== 'disabled' ? 'disabled' : 'enabled' }`, defaultMessage: record?.state?.value !== 'disabled' ? '禁用' : '启用', })} , { if (record?.state?.value === 'disabled') { await service.remove(record.id); onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } else { onlyMessage( intl.formatMessage({ id: 'pages.device.instance.deleteTip' }), 'error', ); } }, }} > , ]} /> )} />
); }; export default AliCloud;