import { PageContainer } from '@ant-design/pro-layout'; import Service from '@/pages/rule-engine/Instance/serivce'; import type { InstanceItem } from '@/pages/rule-engine/Instance/typings'; import { useEffect, useRef, useState } from 'react'; import type { ActionType, ProColumns } from '@jetlinks/pro-table'; import { DeleteOutlined, EditOutlined, EyeOutlined, PlayCircleOutlined, PlusOutlined, StopOutlined, } from '@ant-design/icons'; import { Button, Tooltip } from 'antd'; import { useIntl } from '@@/plugin-locale/localeExports'; import SearchComponent from '@/components/SearchComponent'; import { BadgeStatus, PermissionButton, ProTableCard } from '@/components'; import RuleInstanceCard from '@/components/ProTableCard/CardItems/ruleInstance'; import Save from '@/pages/rule-engine/Instance/Save'; import SystemConst from '@/utils/const'; import { StatusColorEnum } from '@/components/BadgeStatus'; import useLocation from '@/hooks/route/useLocation'; import { onlyMessage } from '@/utils/util'; export const service = new Service('rule-engine/instance'); const Instance = () => { const intl = useIntl(); const actionRef = useRef(); const [visible, setVisible] = useState(false); const [current, setCurrent] = useState>({}); const [searchParams, setSearchParams] = useState({}); const { permission } = PermissionButton.usePermission('rule-engine/Instance'); const location = useLocation(); useEffect(() => { const { state } = location; if (state && state.save) { setCurrent({}); setVisible(true); } }, [location]); const tools = (record: InstanceItem) => [ { setCurrent(record); setVisible(true); }} type={'link'} style={{ padding: 0 }} > 编辑 , { if (record.state.value !== 'disable') { await service.stopRule(record.id); } else { await service.startRule(record.id); } onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); }, }} isPermission={permission.action} > {record.state.value !== 'disable' ? : } {record.state.value !== 'disable' ? '禁用' : '启用'} , { if (record.state.value === 'disable') { await service.remove(record.id); onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } else { onlyMessage('未停止不能删除', 'error'); } }, }} key="delete" type="link" > , ]; const columns: ProColumns[] = [ { dataIndex: 'name', title: intl.formatMessage({ id: 'pages.table.name', defaultMessage: '名称', }), ellipsis: true, fixed: 'left', }, { dataIndex: 'state', title: '状态', render: (text: any, record: any) => ( ), valueType: 'select', valueEnum: { started: { text: '正常', status: 'started', }, disable: { text: '禁用', status: 'disable', }, }, }, { dataIndex: 'description', title: '说明', ellipsis: true, }, { title: intl.formatMessage({ id: 'pages.data.option', defaultMessage: '操作', }), valueType: 'option', align: 'center', width: 200, fixed: 'right', render: (text, record) => [ { setCurrent(record); setVisible(true); }} type={'link'} style={{ padding: 0 }} tooltip={{ title: intl.formatMessage({ id: 'pages.data.option.edit', defaultMessage: '编辑', }), }} > , , { if (record.state.value !== 'disable') { await service.stopRule(record.id); } else { await service.startRule(record.id); } onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); }, }} isPermission={permission.action} tooltip={{ title: record.state.value !== 'disable' ? '禁用' : '启用', }} > {record.state.value !== 'disable' ? : } , { if (record.state.value === 'disable') { const resp: any = await service.remove(record.id); if (resp.status === 200) { onlyMessage( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } } else { onlyMessage('未停止不能删除', 'error'); } }, }} key="button" type="link" > , ], }, ]; return ( field={columns} target="device-instance" onSearch={(data) => { // 重置分页数据 actionRef.current?.reset?.(); setSearchParams(data); }} /> columns={columns} actionRef={actionRef} params={searchParams} scroll={{ x: 1366 }} columnEmptyText={''} options={{ fullScreen: true }} request={(params) => service.query({ ...params, sorts: [ { name: 'createTime', order: 'desc', }, ], }) } rowKey="id" search={false} pagination={{ pageSize: 10 }} headerTitle={[ { setVisible(true); setCurrent({}); }} icon={} type="primary" tooltip={{ title: intl.formatMessage({ id: 'pages.data.option.add', defaultMessage: '新增', }), }} > 新增 , ]} cardRender={(record) => ( { window.open(`/${SystemConst.API_BASE}/rule-editor/index.html#flow/${record.id}`); }} > } /> )} /> {visible && ( { setVisible(false); actionRef.current?.reload(); }} /> )} ); }; export default Instance;