import { PageContainer } from '@ant-design/pro-layout'; import type { ActionType, ProColumns } from '@jetlinks/pro-table'; import type { ProtocolItem } from '@/pages/link/Protocol/typings'; import { Badge, message } from 'antd'; import { useEffect, useRef, useState } from 'react'; import { DeleteOutlined, EditOutlined, PlayCircleOutlined, PlusOutlined, StopOutlined, } from '@ant-design/icons'; import Service from '@/pages/link/Protocol/service'; import { useIntl, useLocation } from 'umi'; import SearchComponent from '@/components/SearchComponent'; import { PermissionButton, ProTableCard } from '@/components'; import ProcotolCard from '@/components/ProTableCard/CardItems/protocol'; import Save from './save'; export const service = new Service('protocol'); const Protocol = () => { const actionRef = useRef(); const [visible, setVisible] = useState(false); const [current, setCurrent] = useState(); const [searchParams, setSearchParams] = useState({}); const { permission } = PermissionButton.usePermission('link/Protocol'); const intl = useIntl(); const modifyState = async (id: string, type: 'deploy' | 'un-deploy') => { const resp = await service.modifyState(id, type); if (resp.status === 200) { message.success('操作成功!'); } else { message.error(resp?.message || '操作失败'); } actionRef.current?.reload(); }; const columns: ProColumns[] = [ { dataIndex: 'id', title: 'ID', sorter: true, ellipsis: true, defaultSortOrder: 'ascend', }, { dataIndex: 'name', ellipsis: true, title: intl.formatMessage({ id: 'pages.table.name', defaultMessage: '名称', }), }, { dataIndex: 'type', title: '类型', ellipsis: true, valueType: 'select', valueEnum: { jar: { text: 'jar', status: 'jar', }, local: { text: 'local', status: 'local', }, }, }, { dataIndex: 'state', title: '状态', renderText: (text) => ( ), }, { dataIndex: 'description', ellipsis: true, title: '说明', }, { title: intl.formatMessage({ id: 'pages.data.option', defaultMessage: '操作', }), valueType: 'option', 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 === 1) { modifyState(record.id, 'un-deploy'); } else { modifyState(record.id, 'deploy'); } }, }} > {record.state === 1 ? : } , { const resp: any = await service.remove(record.id); if (resp.status === 200) { message.success( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } else { message.error(resp?.message || '操作失败'); } }, }} key="delete" type="link" > , ], }, ]; const location = useLocation(); useEffect(() => { if ((location as any).query?.save === 'true') { setCurrent(undefined); setVisible(true); } }, []); return ( field={columns} target="Protocol" onSearch={(data) => { actionRef.current?.reset?.(); setSearchParams(data); }} /> columns={columns} actionRef={actionRef} params={searchParams} options={{ fullScreen: true }} request={(params) => service.query({ ...params, sorts: [ { name: 'createTime', order: 'desc', }, ], }) } rowKey="id" search={false} pagination={{ pageSize: 10 }} headerTitle={[ { setVisible(true); setCurrent(undefined); }} style={{ marginRight: 12 }} isPermission={permission.add} key="button" icon={} type="primary" > {intl.formatMessage({ id: 'pages.data.option.add', defaultMessage: '新增', })} , ]} cardRender={(record) => ( { setCurrent(record); setVisible(true); }} type={'link'} style={{ padding: 0 }} tooltip={{ title: intl.formatMessage({ id: 'pages.data.option.edit', defaultMessage: '编辑', }), }} > 编辑 , { if (record.state === 1) { modifyState(record.id, 'un-deploy'); } else { modifyState(record.id, 'deploy'); } }, }} > {record.state === 1 ? : } {record.state === 1 ? '撤销' : '发布'} , { const resp: any = await service.remove(record.id); if (resp.status === 200) { message.success( intl.formatMessage({ id: 'pages.data.option.success', defaultMessage: '操作成功!', }), ); actionRef.current?.reload(); } else { message.error(resp?.message || '操作失败'); } }, }} key="delete" type="link" > , ]} /> )} /> {visible && ( { setVisible(false); }} reload={() => { actionRef.current?.reload(); setVisible(false); }} /> )} ); }; export default Protocol;